31#include <initializer_list>
62 constexpr Vec3() =
default;
72 constexpr Vec3(
double inX,
double inY,
double inZ) noexcept :
85 Vec3(
const std::initializer_list<double>& inList)
87 if (inList.size() != 3)
93 y = *(inList.begin() + 1);
94 z = *(inList.begin() + 2);
117 if (ndArray.
size() != 3)
134 [[nodiscard]]
double angle(
const Vec3& otherVec)
const noexcept
136 double dotProduct =
dot(otherVec);
137 dotProduct /=
norm();
138 dotProduct /= otherVec.norm();
143 return std::acos(dotProduct);
154 return Vec3(0., 0., -1.);
167 const double magnitude =
norm();
168 if (magnitude <= maxLength)
173 Vec3 returnVec =
Vec3(*this).normalize();
174 returnVec *= maxLength;
187 const double crossX =
y * otherVec.z -
z * otherVec.y;
188 const double crossY = -(
x * otherVec.z -
z * otherVec.x);
189 const double crossZ =
x * otherVec.y -
y * otherVec.x;
191 return Vec3(crossX, crossY, crossZ);
203 return (
Vec3(*
this) -= otherVec).norm();
213 [[nodiscard]]
double dot(
const Vec3& otherVec)
const noexcept
215 return x * otherVec.x +
y * otherVec.y +
z * otherVec.z;
226 return Vec3(0., -1., 0.);
237 return Vec3(0., 0., 1.);
248 return Vec3(-1., 0., 0.);
263 Vec3 trajectory = otherVec;
269 return Vec3(*
this) +=
Vec3(xInterp, yInterp, zInterp);
278 [[nodiscard]]
double norm() const noexcept
304 return otherVec.normalize() *= projectedMagnitude;
315 return Vec3(1., 0., 0.);
326 std::stringstream stream;
327 stream <<
"Vec3[" <<
x <<
", " <<
y <<
", " <<
z <<
"]";
351 return Vec3(0., 1., 0.);
376 return !(*
this == rhs);
480 return Vec3(lhs) += rhs;
493 return Vec3(rhs) += lhs;
506 return Vec3(lhs) += rhs;
517 return Vec3(-vec.x, -vec.y, -vec.z);
530 return Vec3(lhs) -= rhs;
543 return -
Vec3(rhs) += lhs;
556 return Vec3(lhs) -= rhs;
569 return Vec3(lhs) *= rhs;
582 return Vec3(rhs) *= lhs;
609 return Vec3(lhs) /= rhs;
622 stream << vec.
toString() << std::endl;
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
size_type size() const noexcept
Definition: NdArrayCore.hpp:4524
self_type transpose() const
Definition: NdArrayCore.hpp:4882
Holds a 2D vector.
Definition: Vec2.hpp:49
Holds a 3D vector.
Definition: Vec3.hpp:51
double z
Definition: Vec3.hpp:56
std::string toString() const
Definition: Vec3.hpp:324
bool operator==(const Vec3 &rhs) const noexcept
Definition: Vec3.hpp:361
double distance(const Vec3 &otherVec) const noexcept
Definition: Vec3.hpp:201
constexpr Vec3(const Vec2 &vec2) noexcept
Definition: Vec3.hpp:103
Vec3(const std::initializer_list< double > &inList)
Definition: Vec3.hpp:85
static constexpr Vec3 back() noexcept
Definition: Vec3.hpp:152
Vec3(const NdArray< double > &ndArray)
Definition: Vec3.hpp:115
static constexpr Vec3 down() noexcept
Definition: Vec3.hpp:224
Vec3 clampMagnitude(double maxLength) const noexcept
Definition: Vec3.hpp:165
double angle(const Vec3 &otherVec) const noexcept
Definition: Vec3.hpp:134
Vec3 normalize() const noexcept
Definition: Vec3.hpp:289
constexpr Vec3(double inX, double inY, double inZ) noexcept
Definition: Vec3.hpp:72
double norm() const noexcept
Definition: Vec3.hpp:278
Vec3 & operator-=(const Vec3 &rhs) noexcept
Definition: Vec3.hpp:431
static constexpr Vec3 left() noexcept
Definition: Vec3.hpp:246
double x
Definition: Vec3.hpp:54
Vec3 & operator/=(double scalar) noexcept
Definition: Vec3.hpp:461
Vec3 & operator-=(double scalar) noexcept
Definition: Vec3.hpp:416
double y
Definition: Vec3.hpp:55
Vec3 & operator*=(double scalar) noexcept
Definition: Vec3.hpp:446
Vec3 project(const Vec3 &otherVec) const noexcept
Definition: Vec3.hpp:301
bool operator!=(const Vec3 &rhs) const noexcept
Definition: Vec3.hpp:374
static constexpr Vec3 up() noexcept
Definition: Vec3.hpp:349
Vec3 lerp(const Vec3 &otherVec, double t) const noexcept
Definition: Vec3.hpp:259
static constexpr Vec3 forward() noexcept
Definition: Vec3.hpp:235
double dot(const Vec3 &otherVec) const noexcept
Definition: Vec3.hpp:213
Vec3 & operator+=(const Vec3 &rhs) noexcept
Definition: Vec3.hpp:401
NdArray< double > toNdArray() const
Definition: Vec3.hpp:337
Vec3 & operator+=(double scalar) noexcept
Definition: Vec3.hpp:386
Vec3 cross(const Vec3 &otherVec) const noexcept
Definition: Vec3.hpp:185
static constexpr Vec3 right() noexcept
Definition: Vec3.hpp:313
constexpr double interp(double inValue1, double inValue2, double inPercent) noexcept
Definition: Utils/interp.hpp:41
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition: essentiallyEqual.hpp:49
Definition: Cartesian.hpp:40
NdArray< dtype > min(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: min.hpp:44
Duration operator-(const DateTime &lhs, const DateTime &rhs) noexcept
Subtraction operator.
Definition: DateTime/DateTime.hpp:551
NdArray< dtype > operator/(const NdArray< dtype > &lhs, const NdArray< dtype > &rhs)
Definition: NdArrayOperators.hpp:819
double hypot(dtype inValue1, dtype inValue2) noexcept
Definition: hypot.hpp:56
auto cos(dtype inValue) noexcept
Definition: cos.hpp:49
std::ostream & operator<<(std::ostream &os, Duration duration)
Output stream operator for the Duration type.
Definition: Clock.hpp:30
NdArrayConstIterator< dtype, PointerType, DifferenceType > operator+(typename NdArrayConstIterator< dtype, PointerType, DifferenceType >::difference_type offset, NdArrayConstIterator< dtype, PointerType, DifferenceType > next) noexcept
Definition: NdArrayIterators.hpp:302
NdArray< dtype > operator*(const NdArray< dtype > &lhs, const NdArray< dtype > &rhs)
Definition: NdArrayOperators.hpp:604
NdArray< dtype > max(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: max.hpp:44