31 #include <initializer_list>
61 constexpr
Vec3() =
default;
71 constexpr
Vec3(
double inX,
double inY,
double inZ) noexcept :
84 Vec3(
const std::initializer_list<double>& inList)
86 if (inList.size() != 3)
92 y = *(inList.begin() + 1);
93 z = *(inList.begin() + 2);
104 if (ndArray.
size() != 3)
123 double dotProduct =
dot(otherVec);
124 dotProduct /=
norm();
125 dotProduct /= otherVec.norm();
130 return std::acos(dotProduct);
141 return Vec3(0.0, 0.0, -1.0);
154 const double magnitude =
norm();
155 if (magnitude <= maxLength)
160 Vec3 returnVec =
Vec3(*this).normalize();
161 returnVec *= maxLength;
174 const double crossX =
y * otherVec.z -
z * otherVec.y;
175 const double crossY = -(
x * otherVec.z -
z * otherVec.x);
176 const double crossZ =
x * otherVec.y -
y * otherVec.x;
178 return { crossX, crossY, crossZ };
190 return (
Vec3(*
this) -= otherVec).norm();
200 double dot(
const Vec3& otherVec)
const noexcept
202 return x * otherVec.x +
y * otherVec.y +
z * otherVec.z;
213 return Vec3(0.0, -1.0, 0.0);
224 return Vec3(0.0, 0.0, 1.0);
235 return Vec3(-1.0, 0.0, 0.0);
250 Vec3 trajectory = otherVec;
256 return Vec3(*
this) +=
Vec3(xInterp, yInterp, zInterp);
291 return otherVec.normalize() *= projectedMagnitude;
302 return Vec3(1.0, 0.0, 0.0);
313 std::stringstream stream;
314 stream <<
"Vec3[" <<
x <<
", " <<
y <<
", " <<
z <<
"]";
338 return Vec3(0.0, 1.0, 0.0);
363 return !(*
this == rhs);
467 return Vec3(lhs) += rhs;
480 return Vec3(rhs) += lhs;
493 return Vec3(lhs) += rhs;
504 return { -vec.x, -vec.y, -vec.z };
517 return Vec3(lhs) -= rhs;
530 return -
Vec3(rhs) += lhs;
543 return Vec3(lhs) -= rhs;
556 return Vec3(lhs) *= rhs;
569 return Vec3(rhs) *= lhs;
596 return Vec3(lhs) /= rhs;
609 stream << vec.
toString() << std::endl;
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
size_type size() const noexcept
Definition: NdArrayCore.hpp:4289
NdArray< dtype > transpose() const
Definition: NdArrayCore.hpp:4650
Holds a 3D vector.
Definition: Vec3.hpp:50
Vec3 & operator*=(double scaler) noexcept
Definition: Vec3.hpp:433
double z
Definition: Vec3.hpp:55
Vec3 & operator-=(const Vec3 &rhs) noexcept
Definition: Vec3.hpp:418
std::string toString() const
Definition: Vec3.hpp:311
Vec3 & operator+=(const Vec3 &rhs) noexcept
Definition: Vec3.hpp:388
bool operator==(const Vec3 &rhs) const noexcept
Definition: Vec3.hpp:348
double distance(const Vec3 &otherVec) const noexcept
Definition: Vec3.hpp:188
Vec3(const std::initializer_list< double > &inList)
Definition: Vec3.hpp:84
Vec3 & operator/=(double scaler) noexcept
Definition: Vec3.hpp:448
static constexpr Vec3 back() noexcept
Definition: Vec3.hpp:139
NdArray< double > toNdArray() const
Definition: Vec3.hpp:324
Vec3(const NdArray< double > &ndArray)
Definition: Vec3.hpp:102
static constexpr Vec3 down() noexcept
Definition: Vec3.hpp:211
Vec3 clampMagnitude(double maxLength) const noexcept
Definition: Vec3.hpp:152
double angle(const Vec3 &otherVec) const noexcept
Definition: Vec3.hpp:121
Vec3 normalize() const noexcept
Definition: Vec3.hpp:276
constexpr Vec3(double inX, double inY, double inZ) noexcept
Definition: Vec3.hpp:71
double norm() const noexcept
Definition: Vec3.hpp:265
Vec3 & operator-=(double scaler) noexcept
Definition: Vec3.hpp:403
static constexpr Vec3 left() noexcept
Definition: Vec3.hpp:233
double x
Definition: Vec3.hpp:53
double y
Definition: Vec3.hpp:54
Vec3 project(const Vec3 &otherVec) const noexcept
Definition: Vec3.hpp:288
bool operator!=(const Vec3 &rhs) const noexcept
Definition: Vec3.hpp:361
static constexpr Vec3 up() noexcept
Definition: Vec3.hpp:336
Vec3 lerp(const Vec3 &otherVec, double t) const noexcept
Definition: Vec3.hpp:246
static constexpr Vec3 forward() noexcept
Definition: Vec3.hpp:222
double dot(const Vec3 &otherVec) const noexcept
Definition: Vec3.hpp:200
Vec3 cross(const Vec3 &otherVec) const noexcept
Definition: Vec3.hpp:172
static constexpr Vec3 right() noexcept
Definition: Vec3.hpp:300
Vec3 & operator+=(double scaler) noexcept
Definition: Vec3.hpp:373
constexpr double interp(double inValue1, double inValue2, double inPercent) noexcept
Definition: Utils/interp.hpp:43
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition: essentiallyEqual.hpp:51
Definition: Coordinate.hpp:45
NdArray< dtype > operator<<(const NdArray< dtype > &lhs, uint8 inNumBits)
Definition: NdArrayOperators.hpp:2233
double hypot(dtype inValue1, dtype inValue2) noexcept
Definition: hypot.hpp:56
NdArray< dtype > max(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: max.hpp:44
NdArrayConstIterator< dtype, PointerType, DifferenceType > operator+(typename NdArrayConstIterator< dtype, PointerType, DifferenceType >::difference_type offset, NdArrayConstIterator< dtype, PointerType, DifferenceType > next) noexcept
Definition: NdArrayIterators.hpp:307
auto cos(dtype inValue) noexcept
Definition: cos.hpp:49
NdArray< dtype > min(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: min.hpp:44
NdArray< dtype > operator*(const NdArray< dtype > &lhs, const NdArray< dtype > &rhs)
Definition: NdArrayOperators.hpp:723
NdArray< dtype > operator-(const NdArray< dtype > &lhs, const NdArray< dtype > &rhs)
Definition: NdArrayOperators.hpp:406
NdArray< dtype > operator/(const NdArray< dtype > &lhs, const NdArray< dtype > &rhs)
Definition: NdArrayOperators.hpp:990