 |
NumCpp
1.0
A C++ implementation of the Python Numpy library
|
Go to the documentation of this file.
38 #include <initializer_list>
62 constexpr
Vec3() =
default;
72 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)
161 Vec3 returnVec =
Vec3(*this).normalize();
162 returnVec *= maxLength;
176 const double crossX =
y * otherVec.z -
z * otherVec.y;
177 const double crossY = -(
x * otherVec.z -
z * otherVec.x);
178 const double crossZ =
x * otherVec.y -
y * otherVec.x;
180 return Vec3(crossX, crossY, crossZ);
192 return (
Vec3(*
this) -= otherVec).norm();
202 double dot(
const Vec3& otherVec)
const noexcept
204 return x * otherVec.x +
y * otherVec.y +
z * otherVec.z;
215 return Vec3(0.0, -1.0, 0.0);
226 return Vec3(0.0, 0.0, 1.0);
237 return Vec3(-1.0, 0.0, 0.0);
252 Vec3 trajectory = otherVec;
258 return Vec3(*
this) +=
Vec3(xInterp, yInterp, zInterp);
293 return otherVec.normalize() *= projectedMagnitude;
304 return Vec3(1.0, 0.0, 0.0);
315 std::stringstream stream;
316 stream <<
"Vec3[" <<
x <<
", " <<
y <<
", " <<
z <<
"]";
340 return Vec3(0.0, 1.0, 0.0);
366 return !(*
this == rhs);
470 return Vec3(lhs) += rhs;
483 return Vec3(rhs) += lhs;
496 return Vec3(lhs) += rhs;
507 return Vec3(-vec.x, -vec.y, -vec.z);
520 return Vec3(lhs) -= rhs;
533 return -
Vec3(rhs) += lhs;
546 return Vec3(lhs) -= rhs;
559 return Vec3(lhs) *= rhs;
572 return Vec3(rhs) *= lhs;
599 return Vec3(lhs) /= rhs;
612 stream << vec.
toString() << std::endl;
static constexpr Vec3 back() noexcept
Definition: Vec3.hpp:139
Vec3 project(const Vec3 &otherVec) const noexcept
Definition: Vec3.hpp:290
Vec3(const NdArray< double > &ndArray)
Definition: Vec3.hpp:102
double y
Definition: Vec3.hpp:55
static constexpr Vec3 down() noexcept
Definition: Vec3.hpp:213
NdArrayConstIterator< dtype, PointerType, DifferenceType > operator+(typename NdArrayConstIterator< dtype, PointerType, DifferenceType >::difference_type offset, NdArrayConstIterator< dtype, PointerType, DifferenceType > next) noexcept
Definition: NdArrayIterators.hpp:305
NdArray< dtype > dot(const NdArray< dtype > &inOtherArray) const
Definition: NdArrayCore.hpp:2635
Vec3 & operator-=(double scaler) noexcept
Definition: Vec3.hpp:406
constexpr double interp(double inValue1, double inValue2, double inPercent) noexcept
Definition: Utils/interp.hpp:44
std::string toString() const
Definition: Vec3.hpp:313
static constexpr Vec3 forward() noexcept
Definition: Vec3.hpp:224
NdArray< dtype > operator/(const NdArray< dtype > &lhs, const NdArray< dtype > &rhs)
Definition: NdArrayOperators.hpp:1091
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition: essentiallyEqual.hpp:53
Vec3 lerp(const Vec3 &otherVec, double t) const noexcept
Definition: Vec3.hpp:248
double z
Definition: Vec3.hpp:56
static constexpr Vec3 right() noexcept
Definition: Vec3.hpp:302
NdArray< dtype > transpose() const
Definition: NdArrayCore.hpp:4591
auto cos(dtype inValue) noexcept
Definition: cos.hpp:52
size_type size() const noexcept
Definition: NdArrayCore.hpp:4310
double norm() const noexcept
Definition: Vec3.hpp:267
Vec3 & operator-=(const Vec3 &rhs) noexcept
Definition: Vec3.hpp:421
double hypot(dtype inValue1, dtype inValue2) noexcept
Definition: hypot.hpp:58
static constexpr Vec3 left() noexcept
Definition: Vec3.hpp:235
NdArray< dtype > operator-(const NdArray< dtype > &lhs, const NdArray< dtype > &rhs)
Definition: NdArrayOperators.hpp:444
Definition: Coordinate.hpp:45
Vec3 & operator*=(double scaler) noexcept
Definition: Vec3.hpp:436
Vec3 & operator/=(double scaler) noexcept
Definition: Vec3.hpp:451
double angle(const Vec3 &otherVec) const noexcept
Definition: Vec3.hpp:121
double distance(const Vec3 &otherVec) const noexcept
Definition: Vec3.hpp:190
NdArray< double > toNdArray() const
Definition: Vec3.hpp:326
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
double x
Definition: Vec3.hpp:54
NdArray< dtype > operator<<(const NdArray< dtype > &lhs, uint8 inNumBits)
Definition: NdArrayOperators.hpp:2414
NdArray< dtype > max(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: max.hpp:46
Vec3(const std::initializer_list< double > &inList)
Definition: Vec3.hpp:84
bool operator==(const Vec3 &rhs) const noexcept
Definition: Vec3.hpp:350
Vec3 & operator+=(const Vec3 &rhs) noexcept
Definition: Vec3.hpp:391
Vec3 cross(const Vec3 &otherVec) const noexcept
Definition: Vec3.hpp:174
NdArray< dtype > operator*(const NdArray< dtype > &lhs, const NdArray< dtype > &rhs)
Definition: NdArrayOperators.hpp:802
constexpr Vec3(double inX, double inY, double inZ) noexcept
Definition: Vec3.hpp:72
Holds a 3D vector.
Definition: Vec3.hpp:50
Vec3 normalize() const noexcept
Definition: Vec3.hpp:278
bool operator!=(const Vec3 &rhs) const noexcept
Definition: Vec3.hpp:364
static constexpr Vec3 up() noexcept
Definition: Vec3.hpp:338
Vec3 clampMagnitude(double maxLength) const noexcept
Definition: Vec3.hpp:152
NdArray< dtype > min(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: min.hpp:46
double dot(const Vec3 &otherVec) const noexcept
Definition: Vec3.hpp:202
Vec3 & operator+=(double scaler) noexcept
Definition: Vec3.hpp:376