Jet
v1.3.3
|
3-D vector class. More...
#include <jet/vector3.h>
Public Member Functions | |
constexpr | Vector () |
Constructs default vector (0, 0, 0). More... | |
constexpr | Vector (T x_, T y_, T z_) |
Constructs vector with given parameters x_ , y_ , and z_ . More... | |
constexpr | Vector (const Vector2< T > &v, T z_) |
Constructs vector with a 2-D vector and a scalar. More... | |
template<typename U > | |
Vector (const std::initializer_list< U > &lst) | |
Constructs vector with initializer list. More... | |
constexpr | Vector (const Vector &v) |
Copy constructor. More... | |
void | set (T s) |
Set all x, y, and z components to s . More... | |
void | set (T x, T y, T z) |
Set x, y, and z components with given parameters. More... | |
void | set (const Vector2< T > &pt, T z) |
Set x, y, and z components with given pt.x , pt.y , and z . More... | |
template<typename U > | |
void | set (const std::initializer_list< U > &lst) |
Set x, y, and z components with given initializer list. More... | |
void | set (const Vector &v) |
Set x, y, and z with other vector v . More... | |
void | setZero () |
Set all x, y, and z to zero. More... | |
void | normalize () |
Normalizes this vector. More... | |
Vector | add (T v) const |
Computes this + (v, v, v). More... | |
Vector | add (const Vector &v) const |
Computes this + (v.x, v.y, v.z). More... | |
Vector | sub (T v) const |
Computes this - (v, v, v). More... | |
Vector | sub (const Vector &v) const |
Computes this - (v.x, v.y, v.z). More... | |
Vector | mul (T v) const |
Computes this * (v, v, v). More... | |
Vector | mul (const Vector &v) const |
Computes this * (v.x, v.y, v.z). More... | |
Vector | div (T v) const |
Computes this / (v, v, v). More... | |
Vector | div (const Vector &v) const |
Computes this / (v.x, v.y, v.z). More... | |
T | dot (const Vector &v) const |
Computes dot product. More... | |
Vector | cross (const Vector &v) const |
Comptues cross product. More... | |
Vector | rsub (T v) const |
Computes (v, v, v) - this. More... | |
Vector | rsub (const Vector &v) const |
Computes (v.x, v.y, v.z) - this. More... | |
Vector | rdiv (T v) const |
Computes (v, v, v) / this. More... | |
Vector | rdiv (const Vector &v) const |
Computes (v.x, v.y, v.z) / this. More... | |
Vector | rcross (const Vector &v) const |
Computes v cross this. More... | |
void | iadd (T v) |
Computes this += (v, v, v). More... | |
void | iadd (const Vector &v) |
Computes this += (v.x, v.y, v.z). More... | |
void | isub (T v) |
Computes this -= (v, v, v). More... | |
void | isub (const Vector &v) |
Computes this -= (v.x, v.y, v.z). More... | |
void | imul (T v) |
Computes this *= (v, v, v). More... | |
void | imul (const Vector &v) |
Computes this *= (v.x, v.y, v.z). More... | |
void | idiv (T v) |
Computes this /= (v, v, v). More... | |
void | idiv (const Vector &v) |
Computes this /= (v.x, v.y, v.z). More... | |
const T & | at (size_t i) const |
Returns const reference to the i -th element of the vector. More... | |
T & | at (size_t i) |
Returns reference to the i -th element of the vector. More... | |
T | sum () const |
Returns the sum of all the components (i.e. x + y + z). More... | |
T | avg () const |
Returns the average of all the components. More... | |
T | min () const |
Returns the minimum value among x, y, and z. More... | |
T | max () const |
Returns the maximum value among x, y, and z. More... | |
T | absmin () const |
Returns the absolute minimum value among x, y, and z. More... | |
T | absmax () const |
Returns the absolute maximum value among x, y, and z. More... | |
size_t | dominantAxis () const |
Returns the index of the dominant axis. More... | |
size_t | subminantAxis () const |
Returns the index of the subminant axis. More... | |
Vector | normalized () const |
Returns normalized vector. More... | |
T | length () const |
Returns the length of the vector. More... | |
T | lengthSquared () const |
Returns the squared length of the vector. More... | |
T | distanceTo (const Vector &other) const |
Returns the distance to the other vector. More... | |
T | distanceSquaredTo (const Vector &other) const |
Returns the squared distance to the other vector. More... | |
Vector | reflected (const Vector &normal) const |
Returns the reflection vector to the surface with given surface normal. More... | |
Vector | projected (const Vector &normal) const |
Returns the projected vector to the surface with given surface normal. More... | |
std::tuple< Vector, Vector > | tangential () const |
Returns the tangential vector for this vector. More... | |
template<typename U > | |
Vector< U, 3 > | castTo () const |
Returns a vector with different value type. More... | |
bool | isEqual (const Vector &other) const |
Returns true if other is the same as this vector. More... | |
bool | isSimilar (const Vector &other, T epsilon=std::numeric_limits< T >::epsilon()) const |
Returns true if other is similar to this vector. More... | |
T & | operator[] (size_t i) |
Returns reference to the i -th element of the vector. More... | |
const T & | operator[] (size_t i) const |
Returns const reference to the i -th element of the vector. More... | |
template<typename U > | |
Vector & | operator= (const std::initializer_list< U > &lst) |
Set x and y components with given initializer list. More... | |
Vector & | operator= (const Vector &v) |
Set x and y with other vector pt . More... | |
Vector & | operator+= (T v) |
Computes this += (v, v, v) More... | |
Vector & | operator+= (const Vector &v) |
Computes this += (v.x, v.y, v.z) More... | |
Vector & | operator-= (T v) |
Computes this -= (v, v, v) More... | |
Vector & | operator-= (const Vector &v) |
Computes this -= (v.x, v.y, v.z) More... | |
Vector & | operator*= (T v) |
Computes this *= (v, v, v) More... | |
Vector & | operator*= (const Vector &v) |
Computes this *= (v.x, v.y, v.z) More... | |
Vector & | operator/= (T v) |
Computes this /= (v, v, v) More... | |
Vector & | operator/= (const Vector &v) |
Computes this /= (v.x, v.y, v.z) More... | |
bool | operator== (const Vector &v) const |
Returns true if other is the same as this vector. More... | |
bool | operator!= (const Vector &v) const |
Returns true if other is the not same as this vector. More... | |
Public Attributes | |
T | x |
X (or the first) component of the vector. More... | |
T | y |
Y (or the second) component of the vector. More... | |
T | z |
Z (or the third) component of the vector. More... | |
3-D vector class.
This class defines simple 3-D vector data.
T | - Type of the element |
|
inlineconstexpr |
Constructs default vector (0, 0, 0).
|
inlineconstexpr |
Constructs vector with given parameters x_
, y_
, and z_
.
|
inlineconstexpr |
Constructs vector with a 2-D vector and a scalar.
jet::Vector< T, 3 >::Vector | ( | const std::initializer_list< U > & | lst | ) |
Constructs vector with initializer list.
|
inlineconstexpr |
Copy constructor.
T jet::Vector< T, 3 >::absmax | ( | ) | const |
Returns the absolute maximum value among x, y, and z.
T jet::Vector< T, 3 >::absmin | ( | ) | const |
Returns the absolute minimum value among x, y, and z.
Vector jet::Vector< T, 3 >::add | ( | const Vector< T, 3 > & | v | ) | const |
Computes this + (v.x, v.y, v.z).
Vector jet::Vector< T, 3 >::add | ( | T | v | ) | const |
Computes this + (v, v, v).
T& jet::Vector< T, 3 >::at | ( | size_t | i | ) |
Returns reference to the i
-th element of the vector.
const T& jet::Vector< T, 3 >::at | ( | size_t | i | ) | const |
Returns const reference to the i
-th element of the vector.
T jet::Vector< T, 3 >::avg | ( | ) | const |
Returns the average of all the components.
Returns a vector with different value type.
Vector jet::Vector< T, 3 >::cross | ( | const Vector< T, 3 > & | v | ) | const |
Comptues cross product.
T jet::Vector< T, 3 >::distanceSquaredTo | ( | const Vector< T, 3 > & | other | ) | const |
Returns the squared distance to the other vector.
T jet::Vector< T, 3 >::distanceTo | ( | const Vector< T, 3 > & | other | ) | const |
Returns the distance to the other vector.
Vector jet::Vector< T, 3 >::div | ( | const Vector< T, 3 > & | v | ) | const |
Computes this / (v.x, v.y, v.z).
Vector jet::Vector< T, 3 >::div | ( | T | v | ) | const |
Computes this / (v, v, v).
size_t jet::Vector< T, 3 >::dominantAxis | ( | ) | const |
Returns the index of the dominant axis.
T jet::Vector< T, 3 >::dot | ( | const Vector< T, 3 > & | v | ) | const |
Computes dot product.
void jet::Vector< T, 3 >::iadd | ( | const Vector< T, 3 > & | v | ) |
Computes this += (v.x, v.y, v.z).
void jet::Vector< T, 3 >::iadd | ( | T | v | ) |
Computes this += (v, v, v).
void jet::Vector< T, 3 >::idiv | ( | const Vector< T, 3 > & | v | ) |
Computes this /= (v.x, v.y, v.z).
void jet::Vector< T, 3 >::idiv | ( | T | v | ) |
Computes this /= (v, v, v).
void jet::Vector< T, 3 >::imul | ( | const Vector< T, 3 > & | v | ) |
Computes this *= (v.x, v.y, v.z).
void jet::Vector< T, 3 >::imul | ( | T | v | ) |
Computes this *= (v, v, v).
bool jet::Vector< T, 3 >::isEqual | ( | const Vector< T, 3 > & | other | ) | const |
Returns true if other
is the same as this vector.
bool jet::Vector< T, 3 >::isSimilar | ( | const Vector< T, 3 > & | other, |
T | epsilon = std::numeric_limits< T >::epsilon() |
||
) | const |
Returns true if other
is similar to this vector.
void jet::Vector< T, 3 >::isub | ( | const Vector< T, 3 > & | v | ) |
Computes this -= (v.x, v.y, v.z).
void jet::Vector< T, 3 >::isub | ( | T | v | ) |
Computes this -= (v, v, v).
T jet::Vector< T, 3 >::length | ( | ) | const |
Returns the length of the vector.
T jet::Vector< T, 3 >::lengthSquared | ( | ) | const |
Returns the squared length of the vector.
T jet::Vector< T, 3 >::max | ( | ) | const |
Returns the maximum value among x, y, and z.
T jet::Vector< T, 3 >::min | ( | ) | const |
Returns the minimum value among x, y, and z.
Vector jet::Vector< T, 3 >::mul | ( | const Vector< T, 3 > & | v | ) | const |
Computes this * (v.x, v.y, v.z).
Vector jet::Vector< T, 3 >::mul | ( | T | v | ) | const |
Computes this * (v, v, v).
void jet::Vector< T, 3 >::normalize | ( | ) |
Normalizes this vector.
Vector jet::Vector< T, 3 >::normalized | ( | ) | const |
Returns normalized vector.
bool jet::Vector< T, 3 >::operator!= | ( | const Vector< T, 3 > & | v | ) | const |
Returns true if other
is the not same as this vector.
Vector& jet::Vector< T, 3 >::operator*= | ( | const Vector< T, 3 > & | v | ) |
Computes this *= (v.x, v.y, v.z)
Vector& jet::Vector< T, 3 >::operator*= | ( | T | v | ) |
Computes this *= (v, v, v)
Vector& jet::Vector< T, 3 >::operator+= | ( | const Vector< T, 3 > & | v | ) |
Computes this += (v.x, v.y, v.z)
Vector& jet::Vector< T, 3 >::operator+= | ( | T | v | ) |
Computes this += (v, v, v)
Vector& jet::Vector< T, 3 >::operator-= | ( | const Vector< T, 3 > & | v | ) |
Computes this -= (v.x, v.y, v.z)
Vector& jet::Vector< T, 3 >::operator-= | ( | T | v | ) |
Computes this -= (v, v, v)
Vector& jet::Vector< T, 3 >::operator/= | ( | const Vector< T, 3 > & | v | ) |
Computes this /= (v.x, v.y, v.z)
Vector& jet::Vector< T, 3 >::operator/= | ( | T | v | ) |
Computes this /= (v, v, v)
Vector& jet::Vector< T, 3 >::operator= | ( | const std::initializer_list< U > & | lst | ) |
Set x and y components with given initializer list.
Vector& jet::Vector< T, 3 >::operator= | ( | const Vector< T, 3 > & | v | ) |
Set x and y with other vector pt
.
bool jet::Vector< T, 3 >::operator== | ( | const Vector< T, 3 > & | v | ) | const |
Returns true if other
is the same as this vector.
T& jet::Vector< T, 3 >::operator[] | ( | size_t | i | ) |
Returns reference to the i
-th element of the vector.
const T& jet::Vector< T, 3 >::operator[] | ( | size_t | i | ) | const |
Returns const reference to the i
-th element of the vector.
Vector jet::Vector< T, 3 >::projected | ( | const Vector< T, 3 > & | normal | ) | const |
Returns the projected vector to the surface with given surface normal.
Vector jet::Vector< T, 3 >::rcross | ( | const Vector< T, 3 > & | v | ) | const |
Computes v
cross this.
Vector jet::Vector< T, 3 >::rdiv | ( | const Vector< T, 3 > & | v | ) | const |
Computes (v.x, v.y, v.z) / this.
Vector jet::Vector< T, 3 >::rdiv | ( | T | v | ) | const |
Computes (v, v, v) / this.
Vector jet::Vector< T, 3 >::reflected | ( | const Vector< T, 3 > & | normal | ) | const |
Returns the reflection vector to the surface with given surface normal.
Vector jet::Vector< T, 3 >::rsub | ( | const Vector< T, 3 > & | v | ) | const |
Computes (v.x, v.y, v.z) - this.
Vector jet::Vector< T, 3 >::rsub | ( | T | v | ) | const |
Computes (v, v, v) - this.
void jet::Vector< T, 3 >::set | ( | const std::initializer_list< U > & | lst | ) |
Set x, y, and z components with given initializer list.
void jet::Vector< T, 3 >::set | ( | const Vector< T, 3 > & | v | ) |
Set x, y, and z with other vector v
.
void jet::Vector< T, 3 >::set | ( | const Vector2< T > & | pt, |
T | z | ||
) |
Set x, y, and z components with given pt.x
, pt.y
, and z
.
void jet::Vector< T, 3 >::set | ( | T | s | ) |
Set all x, y, and z components to s
.
void jet::Vector< T, 3 >::set | ( | T | x, |
T | y, | ||
T | z | ||
) |
Set x, y, and z components with given parameters.
void jet::Vector< T, 3 >::setZero | ( | ) |
Set all x, y, and z to zero.
Vector jet::Vector< T, 3 >::sub | ( | const Vector< T, 3 > & | v | ) | const |
Computes this - (v.x, v.y, v.z).
Vector jet::Vector< T, 3 >::sub | ( | T | v | ) | const |
Computes this - (v, v, v).
size_t jet::Vector< T, 3 >::subminantAxis | ( | ) | const |
Returns the index of the subminant axis.
T jet::Vector< T, 3 >::sum | ( | ) | const |
Returns the sum of all the components (i.e. x + y + z).
std::tuple<Vector, Vector> jet::Vector< T, 3 >::tangential | ( | ) | const |
Returns the tangential vector for this vector.
T jet::Vector< T, 3 >::x |
X (or the first) component of the vector.
T jet::Vector< T, 3 >::y |
Y (or the second) component of the vector.
T jet::Vector< T, 3 >::z |
Z (or the third) component of the vector.