 |
NumCpp
2.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)
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);
364 return !(*
this == rhs);
468 return Vec3(lhs) += rhs;
481 return Vec3(rhs) += lhs;
494 return Vec3(lhs) += rhs;
505 return {-vec.x, -vec.y, -vec.z};
518 return Vec3(lhs) -= rhs;
531 return -
Vec3(rhs) += lhs;
544 return Vec3(lhs) -= rhs;
557 return Vec3(lhs) *= rhs;
570 return Vec3(rhs) *= lhs;
597 return Vec3(lhs) /= rhs;
610 stream << vec.
toString() << std::endl;
static constexpr Vec3 back() noexcept
Definition: Vec3.hpp:139
Vec3 project(const Vec3 &otherVec) const noexcept
Definition: Vec3.hpp:288
Vec3(const NdArray< double > &ndArray)
Definition: Vec3.hpp:102
double y
Definition: Vec3.hpp:55
static constexpr Vec3 down() noexcept
Definition: Vec3.hpp:211
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:2644
Vec3 & operator-=(double scaler) noexcept
Definition: Vec3.hpp:404
constexpr double interp(double inValue1, double inValue2, double inPercent) noexcept
Definition: Utils/interp.hpp:44
std::string toString() const
Definition: Vec3.hpp:311
static constexpr Vec3 forward() noexcept
Definition: Vec3.hpp:222
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:246
double z
Definition: Vec3.hpp:56
static constexpr Vec3 right() noexcept
Definition: Vec3.hpp:300
NdArray< dtype > transpose() const
Definition: NdArrayCore.hpp:4608
auto cos(dtype inValue) noexcept
Definition: cos.hpp:52
size_type size() const noexcept
Definition: NdArrayCore.hpp:4326
double norm() const noexcept
Definition: Vec3.hpp:265
Vec3 & operator-=(const Vec3 &rhs) noexcept
Definition: Vec3.hpp:419
double hypot(dtype inValue1, dtype inValue2) noexcept
Definition: hypot.hpp:58
static constexpr Vec3 left() noexcept
Definition: Vec3.hpp:233
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:434
Vec3 & operator/=(double scaler) noexcept
Definition: Vec3.hpp:449
double angle(const Vec3 &otherVec) const noexcept
Definition: Vec3.hpp:121
double distance(const Vec3 &otherVec) const noexcept
Definition: Vec3.hpp:188
NdArray< double > toNdArray() const
Definition: Vec3.hpp:324
#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:348
Vec3 & operator+=(const Vec3 &rhs) noexcept
Definition: Vec3.hpp:389
Vec3 cross(const Vec3 &otherVec) const noexcept
Definition: Vec3.hpp:172
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:276
bool operator!=(const Vec3 &rhs) const noexcept
Definition: Vec3.hpp:362
static constexpr Vec3 up() noexcept
Definition: Vec3.hpp:336
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:200
Vec3 & operator+=(double scaler) noexcept
Definition: Vec3.hpp:374