37 #include <initializer_list>
61 constexpr
Vec3() =
default;
71 constexpr
Vec3(
double inX,
double inY,
double inZ) noexcept :
83 Vec3(
const std::initializer_list<double>& inList)
85 if (inList.size() != 3)
91 y = *(inList.begin() + 1);
92 z = *(inList.begin() + 2);
103 if (ndArray.
size() != 3)
122 double dotProduct =
dot(otherVec);
123 dotProduct /=
norm();
124 dotProduct /= otherVec.norm();
129 return std::acos(dotProduct);
140 return Vec3(0.0, 0.0, -1.0);
153 const double magnitude =
norm();
154 if (magnitude <= maxLength)
159 Vec3 returnVec =
Vec3(*this).normalize();
160 returnVec *= maxLength;
173 const double crossX =
y * otherVec.z -
z * otherVec.y;
174 const double crossY = -(
x * otherVec.z -
z * otherVec.x);
175 const double crossZ =
x * otherVec.y -
y * otherVec.x;
177 return {crossX, crossY, crossZ};
189 return (
Vec3(*
this) -= otherVec).norm();
199 double dot(
const Vec3& otherVec)
const noexcept
201 return x * otherVec.x +
y * otherVec.y +
z * otherVec.z;
212 return Vec3(0.0, -1.0, 0.0);
223 return Vec3(0.0, 0.0, 1.0);
234 return Vec3(-1.0, 0.0, 0.0);
249 Vec3 trajectory = otherVec;
255 return Vec3(*
this) +=
Vec3(xInterp, yInterp, zInterp);
290 return otherVec.normalize() *= projectedMagnitude;
301 return Vec3(1.0, 0.0, 0.0);
312 std::stringstream stream;
313 stream <<
"Vec3[" <<
x <<
", " <<
y <<
", " <<
z <<
"]";
337 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:4497
NdArray< dtype > transpose() const
Definition: NdArrayCore.hpp:4830
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:310
Vec3 & operator+=(const Vec3 &rhs) noexcept
Definition: Vec3.hpp:388
bool operator==(const Vec3 &rhs) const noexcept
Definition: Vec3.hpp:347
double distance(const Vec3 &otherVec) const noexcept
Definition: Vec3.hpp:187
Vec3(const std::initializer_list< double > &inList)
Definition: Vec3.hpp:83
Vec3 & operator/=(double scaler) noexcept
Definition: Vec3.hpp:448
static constexpr Vec3 back() noexcept
Definition: Vec3.hpp:138
NdArray< double > toNdArray() const
Definition: Vec3.hpp:323
Vec3(const NdArray< double > &ndArray)
Definition: Vec3.hpp:101
static constexpr Vec3 down() noexcept
Definition: Vec3.hpp:210
Vec3 clampMagnitude(double maxLength) const noexcept
Definition: Vec3.hpp:151
double angle(const Vec3 &otherVec) const noexcept
Definition: Vec3.hpp:120
Vec3 normalize() const noexcept
Definition: Vec3.hpp:275
constexpr Vec3(double inX, double inY, double inZ) noexcept
Definition: Vec3.hpp:71
double norm() const noexcept
Definition: Vec3.hpp:264
Vec3 & operator-=(double scaler) noexcept
Definition: Vec3.hpp:403
static constexpr Vec3 left() noexcept
Definition: Vec3.hpp:232
double x
Definition: Vec3.hpp:53
double y
Definition: Vec3.hpp:54
Vec3 project(const Vec3 &otherVec) const noexcept
Definition: Vec3.hpp:287
bool operator!=(const Vec3 &rhs) const noexcept
Definition: Vec3.hpp:361
static constexpr Vec3 up() noexcept
Definition: Vec3.hpp:335
Vec3 lerp(const Vec3 &otherVec, double t) const noexcept
Definition: Vec3.hpp:245
static constexpr Vec3 forward() noexcept
Definition: Vec3.hpp:221
double dot(const Vec3 &otherVec) const noexcept
Definition: Vec3.hpp:199
Vec3 cross(const Vec3 &otherVec) const noexcept
Definition: Vec3.hpp:171
static constexpr Vec3 right() noexcept
Definition: Vec3.hpp:299
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:52
Definition: Coordinate.hpp:45
NdArray< dtype > operator<<(const NdArray< dtype > &lhs, uint8 inNumBits)
Definition: NdArrayOperators.hpp:2413
double hypot(dtype inValue1, dtype inValue2) noexcept
Definition: hypot.hpp:57
NdArray< dtype > max(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: max.hpp:45
NdArrayConstIterator< dtype, PointerType, DifferenceType > operator+(typename NdArrayConstIterator< dtype, PointerType, DifferenceType >::difference_type offset, NdArrayConstIterator< dtype, PointerType, DifferenceType > next) noexcept
Definition: NdArrayIterators.hpp:310
auto cos(dtype inValue) noexcept
Definition: cos.hpp:51
NdArray< dtype > min(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: min.hpp:45
NdArray< dtype > operator*(const NdArray< dtype > &lhs, const NdArray< dtype > &rhs)
Definition: NdArrayOperators.hpp:801
NdArray< dtype > operator-(const NdArray< dtype > &lhs, const NdArray< dtype > &rhs)
Definition: NdArrayOperators.hpp:443
NdArray< dtype > operator/(const NdArray< dtype > &lhs, const NdArray< dtype > &rhs)
Definition: NdArrayOperators.hpp:1090