NumCpp  2.12.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
nc::Vec3 Class Reference

Holds a 3D vector. More...

#include <Vec3.hpp>

Public Member Functions

constexpr Vec3 ()=default
 
 Vec3 (const NdArray< double > &ndArray)
 
 Vec3 (const std::initializer_list< double > &inList)
 
constexpr Vec3 (const Vec2 &vec2) noexcept
 
constexpr Vec3 (double inX, double inY, double inZ) noexcept
 
double angle (const Vec3 &otherVec) const noexcept
 
Vec3 clampMagnitude (double maxLength) const noexcept
 
Vec3 cross (const Vec3 &otherVec) const noexcept
 
double distance (const Vec3 &otherVec) const noexcept
 
double dot (const Vec3 &otherVec) const noexcept
 
Vec3 lerp (const Vec3 &otherVec, double t) const noexcept
 
double norm () const noexcept
 
Vec3 normalize () const noexcept
 
bool operator!= (const Vec3 &rhs) const noexcept
 
Vec3operator*= (double scalar) noexcept
 
Vec3operator+= (const Vec3 &rhs) noexcept
 
Vec3operator+= (double scalar) noexcept
 
Vec3operator-= (const Vec3 &rhs) noexcept
 
Vec3operator-= (double scalar) noexcept
 
Vec3operator/= (double scalar) noexcept
 
bool operator== (const Vec3 &rhs) const noexcept
 
Vec3 project (const Vec3 &otherVec) const noexcept
 
NdArray< double > toNdArray () const
 
std::string toString () const
 

Static Public Member Functions

static constexpr Vec3 back () noexcept
 
static constexpr Vec3 down () noexcept
 
static constexpr Vec3 forward () noexcept
 
static constexpr Vec3 left () noexcept
 
static constexpr Vec3 right () noexcept
 
static constexpr Vec3 up () noexcept
 

Data Fields

double x { 0. }
 
double y { 0. }
 
double z { 0. }
 

Detailed Description

Holds a 3D vector.

Constructor & Destructor Documentation

◆ Vec3() [1/5]

constexpr nc::Vec3::Vec3 ( )
constexprdefault

Default Constructor

◆ Vec3() [2/5]

constexpr nc::Vec3::Vec3 ( double  inX,
double  inY,
double  inZ 
)
inlineconstexprnoexcept

Constructor

Parameters
inXthe x component
inYthe y component
inZthe y component

◆ Vec3() [3/5]

nc::Vec3::Vec3 ( const std::initializer_list< double > &  inList)
inline

Constructor

Parameters
inList

◆ Vec3() [4/5]

constexpr nc::Vec3::Vec3 ( const Vec2 vec2)
inlineconstexprnoexcept

Constructor

Parameters
vec22d vector

◆ Vec3() [5/5]

nc::Vec3::Vec3 ( const NdArray< double > &  ndArray)
inline

Constructor

Parameters
ndArray

Member Function Documentation

◆ angle()

double nc::Vec3::angle ( const Vec3 otherVec) const
inlinenoexcept

Returns the angle between the two vectors

Parameters
otherVec
Returns
the angle in radians

◆ back()

static constexpr Vec3 nc::Vec3::back ( )
inlinestaticconstexprnoexcept

Returns the unit vector [0, 0, -1]

Returns
Vec3

◆ clampMagnitude()

Vec3 nc::Vec3::clampMagnitude ( double  maxLength) const
inlinenoexcept

Returns a copy of the vector with its magnitude clamped to maxLength

Parameters
maxLength
Returns
Vec3

◆ cross()

Vec3 nc::Vec3::cross ( const Vec3 otherVec) const
inlinenoexcept

Returns the cross product of the two vectors

Parameters
otherVec
Returns
the dot product

◆ distance()

double nc::Vec3::distance ( const Vec3 otherVec) const
inlinenoexcept

Returns the distance between the two vectors

Parameters
otherVec
Returns
the distance (equivalent to (a - b).norm()

◆ dot()

double nc::Vec3::dot ( const Vec3 otherVec) const
inlinenoexcept

Returns the dot product of the two vectors

Parameters
otherVec
Returns
the dot product

◆ down()

static constexpr Vec3 nc::Vec3::down ( )
inlinestaticconstexprnoexcept

Returns the unit vector [0, -1, 0]

Returns
Vec3

◆ forward()

static constexpr Vec3 nc::Vec3::forward ( )
inlinestaticconstexprnoexcept

Returns the unit vector [0, 0, 1]

Returns
Vec3

◆ left()

static constexpr Vec3 nc::Vec3::left ( )
inlinestaticconstexprnoexcept

Returns the unit vector [-1, 0, 0]

Returns
Vec3

◆ lerp()

Vec3 nc::Vec3::lerp ( const Vec3 otherVec,
double  t 
) const
inlinenoexcept

Linearly interpolates between two vectors

Parameters
otherVec
tthe amount to interpolate by (clamped from [0, 1]);
Returns
Vec3

◆ norm()

double nc::Vec3::norm ( ) const
inlinenoexcept

Returns the magnitude of the vector

Returns
magnitude of the vector

◆ normalize()

Vec3 nc::Vec3::normalize ( ) const
inlinenoexcept

Returns a new normalized Vec3

Returns
Vec3

◆ operator!=()

bool nc::Vec3::operator!= ( const Vec3 rhs) const
inlinenoexcept

Not Equality operator

Parameters
rhs
Returns
bool

◆ operator*=()

Vec3 & nc::Vec3::operator*= ( double  scalar)
inlinenoexcept

Scalar mulitplication

Parameters
scalar
Returns
Vec3

◆ operator+=() [1/2]

Vec3 & nc::Vec3::operator+= ( const Vec3 rhs)
inlinenoexcept

Adds the two vectors

Parameters
rhs
Returns
Vec3

◆ operator+=() [2/2]

Vec3 & nc::Vec3::operator+= ( double  scalar)
inlinenoexcept

Adds the scalar to the vector

Parameters
scalar
Returns
Vec3

◆ operator-=() [1/2]

Vec3 & nc::Vec3::operator-= ( const Vec3 rhs)
inlinenoexcept

Subtracts the two vectors

Parameters
rhs
Returns
Vec3

◆ operator-=() [2/2]

Vec3 & nc::Vec3::operator-= ( double  scalar)
inlinenoexcept

Subtracts the scalar from the vector

Parameters
scalar
Returns
Vec3

◆ operator/=()

Vec3 & nc::Vec3::operator/= ( double  scalar)
inlinenoexcept

Scalar division

Parameters
scalar
Returns
Vec3

◆ operator==()

bool nc::Vec3::operator== ( const Vec3 rhs) const
inlinenoexcept

Equality operator

Parameters
rhs
Returns
bool

◆ project()

Vec3 nc::Vec3::project ( const Vec3 otherVec) const
inlinenoexcept

Projects the vector onto the input vector

Parameters
otherVec
Returns
Vec3

◆ right()

static constexpr Vec3 nc::Vec3::right ( )
inlinestaticconstexprnoexcept

Returns the unit vector [1, 0, 0]

Returns
Vec3

◆ toNdArray()

NdArray< double > nc::Vec3::toNdArray ( ) const
inline

Returns the Vec2 as an NdArray

Returns
NdArray

◆ toString()

std::string nc::Vec3::toString ( ) const
inline

Returns the Vec3 as a string

Returns
std::string

◆ up()

static constexpr Vec3 nc::Vec3::up ( )
inlinestaticconstexprnoexcept

Returns the unit vector [0, 1, 0]

Returns
Vec3

Field Documentation

◆ x

double nc::Vec3::x { 0. }

◆ y

double nc::Vec3::y { 0. }

◆ z

double nc::Vec3::z { 0. }

The documentation for this class was generated from the following file: