scsl  1.1.1
Shimmering Clarity Standard Library
Public Member Functions | Friends | List of all members
scmp::geom::Vector< T, N > Class Template Reference

Vectors represent a direction and Magnitude. More...

#include <Vector.h>

Public Member Functions

 Vector ()
 Construct a unit vector of a given type and size. More...
 
 Vector (std::initializer_list< T > ilst)
 Construct a Vector with initial values. More...
 
At (size_t index) const
 Return the element At index i. More...
 
void Set (size_t index, T value)
 Set a new value for the vector. More...
 
Magnitude () const
 Compute the length of the vector. More...
 
void SetEpsilon (T eps)
 Set equivalence tolerance. More...
 
bool IsZero () const
 Determine whether this is a zero vector. More...
 
Vector UnitVector () const
 Obtain the unit vector for this vector. More...
 
bool IsUnitVector () const
 Determine if this is a unit vector. More...
 
Angle (const Vector< T, N > &other) const
 Compute the Angle between two vectors. More...
 
bool IsParallel (const Vector< T, N > &other) const
 Determine whether two vectors are parallel. More...
 
bool IsOrthogonal (const Vector< T, N > &other) const
 Determine if two vectors are orthogonal or perpendicular to each other. More...
 
Vector ProjectParallel (const Vector< T, N > &basis) const
 Project this vector onto some basis vector. More...
 
Vector ProjectOrthogonal (const Vector< T, N > &basis)
 Project this vector perpendicularly onto some basis vector. More...
 
Vector Cross (const Vector< T, N > &other) const
 Compute the cross product of two vectors. More...
 
Vector operator+ (const Vector< T, N > &other) const
 Vector addition. More...
 
Vector operator- (const Vector< T, N > &other) const
 Vector subtraction. More...
 
Vector operator* (const T k) const
 Scalar multiplication. More...
 
Vector operator/ (const T k) const
 Scalar division. More...
 
operator* (const Vector< T, N > &other) const
 Compute the Dot product between two vectors. More...
 
bool operator== (const Vector< T, N > &other) const
 Vector equivalence. More...
 
bool operator!= (const Vector< T, N > &other) const
 Vector non-equivalence. More...
 
const T & operator[] (size_t i) const
 Array indexing into vector. More...
 

Friends

std::ostream & operator<< (std::ostream &outs, const Vector< T, N > &vec)
 Write a vector a stream in the form "<i, j, ...>". More...
 

Detailed Description

template<typename T, size_t N>
class scmp::geom::Vector< T, N >

Vectors represent a direction and Magnitude.

Vector provides a standard interface for dimensionless fixed-size vectors. Once instantiated, they cannot be modified.

Note that while the class is templated, it's intended to be used with floating-point types.

Vectors can be indexed like arrays, and they contain an epsilon value that defines a tolerance for equality.

Constructor & Destructor Documentation

◆ Vector() [1/2]

template<typename T , size_t N>
scmp::geom::Vector< T, N >::Vector ( )
inline

Construct a unit vector of a given type and size.

◆ Vector() [2/2]

template<typename T , size_t N>
scmp::geom::Vector< T, N >::Vector ( std::initializer_list< T >  ilst)
inline

Construct a Vector with initial values.

If given an initializer_list, the vector is created with those values. There must be exactly N elements in the list.

Parameters
ilstAn intializer list with N elements of type T.

Member Function Documentation

◆ Angle()

template<typename T , size_t N>
T scmp::geom::Vector< T, N >::Angle ( const Vector< T, N > &  other) const
inline

Compute the Angle between two vectors.

Parameters
otherAnother vector.
Returns
The Angle in radians between the two vectors.

◆ At()

template<typename T , size_t N>
T scmp::geom::Vector< T, N >::At ( size_t  index) const
inline

Return the element At index i.

Exceptions
std::out_of_rangeif the index is out of bounds.
Parameters
indexThe index of the item to retrieve.
Returns
The value At the index.

◆ Cross()

template<typename T , size_t N>
Vector scmp::geom::Vector< T, N >::Cross ( const Vector< T, N > &  other) const
inline

Compute the cross product of two vectors.

This is only defined over three-dimensional vectors.

Exceptions
std::out_of_rangeif this is not a three-dimensional vector.
Parameters
otherAnother 3D vector.
Returns
The Cross product vector.

◆ IsOrthogonal()

template<typename T , size_t N>
bool scmp::geom::Vector< T, N >::IsOrthogonal ( const Vector< T, N > &  other) const
inline

Determine if two vectors are orthogonal or perpendicular to each other.

Parameters
otherAnother vector
Returns
True if the two vectors are orthogonal.

◆ IsParallel()

template<typename T , size_t N>
bool scmp::geom::Vector< T, N >::IsParallel ( const Vector< T, N > &  other) const
inline

Determine whether two vectors are parallel.

Parameters
otherAnother vector
Returns
True if the Angle between the vectors is zero.

◆ IsUnitVector()

template<typename T , size_t N>
bool scmp::geom::Vector< T, N >::IsUnitVector ( ) const
inline

Determine if this is a unit vector.

Returns
true if the vector is a unit vector.

◆ IsZero()

template<typename T , size_t N>
bool scmp::geom::Vector< T, N >::IsZero ( ) const
inline

Determine whether this is a zero vector.

Returns
true if the vector is zero.

◆ Magnitude()

template<typename T , size_t N>
T scmp::geom::Vector< T, N >::Magnitude ( ) const
inline

Compute the length of the vector.

Returns
The length of the vector.

◆ operator!=()

template<typename T , size_t N>
bool scmp::geom::Vector< T, N >::operator!= ( const Vector< T, N > &  other) const
inline

Vector non-equivalence.

Parameters
otherThe other vector.
Returns
Return true if any of the components of both vectors are not within the tolerance value.

◆ operator*() [1/2]

template<typename T , size_t N>
Vector scmp::geom::Vector< T, N >::operator* ( const T  k) const
inline

Scalar multiplication.

Parameters
kThe scaling value.
Returns
A new vector that is this vector scaled by k.

◆ operator*() [2/2]

template<typename T , size_t N>
T scmp::geom::Vector< T, N >::operator* ( const Vector< T, N > &  other) const
inline

Compute the Dot product between two vectors.

Parameters
otherThe other vector.
Returns
A scalar value that is the Dot product of the two vectors.

◆ operator+()

template<typename T , size_t N>
Vector scmp::geom::Vector< T, N >::operator+ ( const Vector< T, N > &  other) const
inline

Vector addition.

Parameters
otherThe vector to be added.
Returns
A new vector that is the result of adding this and the other vector.

◆ operator-()

template<typename T , size_t N>
Vector scmp::geom::Vector< T, N >::operator- ( const Vector< T, N > &  other) const
inline

Vector subtraction.

Parameters
otherThe vector to be subtracted from this vector.
Returns
A new vector that is the result of subtracting the other vector from this one.

◆ operator/()

template<typename T , size_t N>
Vector scmp::geom::Vector< T, N >::operator/ ( const T  k) const
inline

Scalar division.

Parameters
kThe scaling value
Returns
A new vector that is this vector scaled by 1/k.

◆ operator==()

template<typename T , size_t N>
bool scmp::geom::Vector< T, N >::operator== ( const Vector< T, N > &  other) const
inline

Vector equivalence.

Parameters
otherThe other vector.
Returns
Return true if all the components of both vectors are within the tolerance value.

◆ operator[]()

template<typename T , size_t N>
const T& scmp::geom::Vector< T, N >::operator[] ( size_t  i) const
inline

Array indexing into vector.

Note that the values of the vector cannot be modified. Instead, something like the following must be done:

Vector3D a {1.0, 2.0, 3.0};
Vector3D b {a[0], a[1]*2.0, a[2]};
Vector< double, 3 > Vector3D
Type alias for a three-dimensional double vector.
Definition: Vector.h:494
Parameters
iThe component index.
Returns
The value of the vector component At i.

◆ ProjectOrthogonal()

template<typename T , size_t N>
Vector scmp::geom::Vector< T, N >::ProjectOrthogonal ( const Vector< T, N > &  basis)
inline

Project this vector perpendicularly onto some basis vector.

This is also called the rejection of the vector.

Parameters
basisThe basis vector to be projected onto.
Returns
A vector that is the orthogonal projection of this onto the basis vector.

◆ ProjectParallel()

template<typename T , size_t N>
Vector scmp::geom::Vector< T, N >::ProjectParallel ( const Vector< T, N > &  basis) const
inline

Project this vector onto some basis vector.

Parameters
basisThe basis vector to be projected onto.
Returns
A vector that is the projection of this onto the basis vector.

◆ Set()

template<typename T , size_t N>
void scmp::geom::Vector< T, N >::Set ( size_t  index,
value 
)
inline

Set a new value for the vector.

This is used to modify the vector in place.

Exceptions
std::out_of_rangeif the index is out of bounds.
Parameters
indexThe index to insert the value At.
value

◆ SetEpsilon()

template<typename T , size_t N>
void scmp::geom::Vector< T, N >::SetEpsilon ( eps)
inline

Set equivalence tolerance.

Set the tolerance for equality checks. At a minimum, this accounts for systemic errors in floating math arithmetic.

Parameters
epsis the maximum difference between this vector and another.

◆ UnitVector()

template<typename T , size_t N>
Vector scmp::geom::Vector< T, N >::UnitVector ( ) const
inline

Obtain the unit vector for this vector.

Returns
The unit vector

Friends And Related Function Documentation

◆ operator<<

template<typename T , size_t N>
std::ostream& operator<< ( std::ostream &  outs,
const Vector< T, N > &  vec 
)
friend

Write a vector a stream in the form "<i, j, ...>".

Parameters
outsAn output stream.
vecThe vector to be formatted.
Returns
The output stream.

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