Represents a vector, \( v \in \mathcal{R}^d \). It provides access methods for setting and querying the vector components as well as vector math operators, e.g., adding, subtracting, dot_product and cross_product.
More...
#include </home/docs/checkouts/readthedocs.org/user_builds/axom/checkouts/v0.3.3/src/axom/primal/geometry/Vector.hpp>
|
| Vector (T val=T(), int sz=NDIMS) |
| Fill vector with single value. Acts as default constructor Sets first sz components of the vector to val (default 0). More...
|
|
| Vector (const NumericArray< T, NDIMS > &arr) |
| Constructor from a numeric array. More...
|
|
| Vector (const T *vals, int sz=NDIMS) |
| Creates a vector from the first sz values of the input array. More...
|
|
| Vector (const Point< T, NDIMS > &pt) |
| Constructor to create vector from a Point. More...
|
|
| Vector (const Vector< T, NDIMS > &other) |
| Copy constructor. More...
|
|
| Vector (const Point< T, NDIMS > &A, const Point< T, NDIMS > &B) |
| Constructs a vector from point A to point B. More...
|
|
| ~Vector () |
| Destructor. More...
|
|
int | dimension () const |
| Returns the dimension of this vector instance. More...
|
|
const T & | operator[] (int i) const |
| Access operator for individual components. More...
|
|
T & | operator[] (int i) |
|
const NumericArray< T, NDIMS > & | array () const |
| Returns a reference to the underlying NumericArray. More...
|
|
NumericArray< T, NDIMS > & | array () |
|
const T * | data () const |
| Returns a pointer to the underlying data. More...
|
|
T * | data () |
|
Vector< T, NDIMS > & | operator+= (const Vector< T, NDIMS > &v) |
| Adds the vector to the Vector instance \(\vec{u} +=\vec{v}\). More...
|
|
Vector< T, NDIMS > & | operator-= (const Vector< T, NDIMS > &v) |
| Adds the vector ot the Vector instance \(\vec{u} -=\vec{v}\). More...
|
|
Vector< T, NDIMS > & | operator*= (T scalar) |
| Scalar multiplication on the Vector instance. More...
|
|
Vector< T, NDIMS > & | operator/= (T scalar) |
| Scalar division on the Vector instance. More...
|
|
T | dot (const Vector< T, NDIMS > &v) const |
| Dot product of the Vector instance with another vector v. More...
|
|
double | squared_norm () const |
| Computes the squared \( l^2\) norm of this vector instance. More...
|
|
double | norm () const |
| Computes the \( l^2 \) norm of this vector instance. More...
|
|
void | negate () |
| Component-wise negation of the vector. More...
|
|
Vector | unitVector () const |
| Creates a new unit vector in the direction of the vector instance. More...
|
|
std::ostream & | print (std::ostream &os) const |
| Simple formatted print of a Vector instance. More...
|
|
|
static T | dot_product (const Vector< T, NDIMS > &u, const Vector< T, NDIMS > &v) |
| Computes the dot product of two vectors u, v. More...
|
|
static Vector< T, 3 > | cross_product (const Vector< T, 2 > &u, const Vector< T, 2 > &v) |
| Computes the cross product of vector u and v, treating them as 3D. More...
|
|
static Vector< T, 3 > | cross_product (const Vector< T, 3 > &u, const Vector< T, 3 > &v) |
| Computes the 3-D cross product of vector u and v. More...
|
|
static Vector | make_vector (const T &x, const T &y, const T &z=0.0) |
| Utility function to constructs a Vector with the given coordinates. More...
|
|
template<typename T, int NDIMS>
class axom::primal::Vector< T, NDIMS >
Represents a vector, \( v \in \mathcal{R}^d \). It provides access methods for setting and querying the vector components as well as vector math operators, e.g., adding, subtracting, dot_product and cross_product.
- Template Parameters
-
T | the coordinate type, e.g., double, float, etc. |
NDIMS | the number of dimensions |
- See also
- NumericArray
-
Point
◆ PointType
template<typename T, int NDIMS>
◆ Vector() [1/6]
template<typename T, int NDIMS>
◆ Vector() [2/6]
template<typename T, int NDIMS>
Constructor from a numeric array.
- Parameters
-
[in] | arr | The numeric array to copy from |
◆ Vector() [3/6]
template<typename T, int NDIMS>
Creates a vector from the first sz values of the input array.
- Parameters
-
[in] | vals | An array containing at least sz values |
[in] | sz | The number of coordinates to take from the array. Defaults to NDIMS. If sz is greater than NDIMS, we only take the first NDIMS values. |
◆ Vector() [4/6]
template<typename T, int NDIMS>
Constructor to create vector from a Point.
- Parameters
-
[in] | pt | The point containing the vector's coordinates. |
- Note
- Equivalent to Vector( Point::zero(), pt)
◆ Vector() [5/6]
template<typename T, int NDIMS>
Copy constructor.
- Parameters
-
[in] | other | The vector to copy |
◆ Vector() [6/6]
template<typename T, int NDIMS>
Constructs a vector from point A to point B.
- Parameters
-
[in] | A | origin point of the vector. |
[in] | B | destination point of the vector. |
- Precondition
- A.dimension() == B.dimension()
-
A.dimension() == ndims
◆ ~Vector()
template<typename T, int NDIMS>
◆ dimension()
template<typename T, int NDIMS>
◆ operator[]() [1/2]
template<typename T, int NDIMS>
Access operator for individual components.
- Parameters
-
[in] | i | the component index to access |
- Returns
- p[i] the value at the given component index.
- Precondition
- (i >= 0) && (i < ndims)
◆ operator[]() [2/2]
template<typename T, int NDIMS>
◆ array() [1/2]
template<typename T, int NDIMS>
Returns a reference to the underlying NumericArray.
Referenced by axom::primal::OrientedBoundingBox< T, NDIMS >::bisect(), axom::primal::OrientedBoundingBox< T, NDIMS >::furthestPoint(), axom::primal::OrientedBoundingBox< T, NDIMS >::getPoints(), axom::primal::Vector< SpaceCoordType, NDIMS >::operator+=(), axom::primal::Vector< SpaceCoordType, NDIMS >::operator-=(), axom::primal::BoundingBox< double, DIM >::scale(), and axom::primal::BoundingBox< double, DIM >::shift().
◆ array() [2/2]
template<typename T, int NDIMS>
◆ data() [1/2]
template<typename T, int NDIMS>
◆ data() [2/2]
template<typename T, int NDIMS>
◆ operator+=()
template<typename T, int NDIMS>
Adds the vector to the Vector instance \(\vec{u} +=\vec{v}\).
- Parameters
-
- Returns
- A reference to the Vector instance after vector addition.
◆ operator-=()
template<typename T, int NDIMS>
Adds the vector ot the Vector instance \(\vec{u} -=\vec{v}\).
- Parameters
-
[in] | v | the vector to subtract. |
- Returns
- A reference to the Vector instance after vector subtraction.
◆ operator*=()
template<typename T, int NDIMS>
Scalar multiplication on the Vector instance.
- Parameters
-
[in] | scalar | the scalar value to multiply with this vector. |
- Returns
- A reference to the vector instance after scalar multiplication.
◆ operator/=()
template<typename T, int NDIMS>
Scalar division on the Vector instance.
- Parameters
-
[in] | scalar | the scalar value to divide with this vector. |
- Precondition
- scalar != 0
- Returns
- A reference to the vector instance after scalar division.
◆ dot()
template<typename T, int NDIMS>
◆ squared_norm()
template<typename T , int NDIMS>
◆ norm()
template<typename T , int NDIMS>
◆ negate()
template<typename T , int NDIMS>
◆ unitVector()
template<typename T , int NDIMS>
Creates a new unit vector in the direction of the vector instance.
- Note
- The unit vector of the zero vector is (1,0,0,...) when normalized.
- Postcondition
- this->norm() == 1.0f
Referenced by axom::primal::Ray< T, NDIMS >::Ray().
◆ print()
template<typename T , int NDIMS>
Simple formatted print of a Vector instance.
- Parameters
-
os | The output stream to write to |
- Returns
- A reference to the modified ostream
Referenced by axom::primal::operator<<().
◆ dot_product()
template<typename T, int NDIMS>
◆ cross_product() [1/2]
template<typename T, int NDIMS>
◆ cross_product() [2/2]
template<typename T, int NDIMS>
Computes the 3-D cross product of vector u and v.
- Parameters
-
[in] | u | the vector on the right-hand side. |
[in] | v | the vector on the left-hand side. |
- Returns
- C the resulting vector from A x B.
◆ make_vector()
template<typename T, int NDIMS>
Utility function to constructs a Vector with the given coordinates.
- Parameters
-
[in] | x | the x–coordinate of the vector. |
[in] | y | the y–coordinate of the vector. |
[in] | z | the z–coordinate of the vector. Default is 0.0. |
- Returns
- v a Vector instance with the given coordinates.
◆ operator==
template<typename T, int NDIMS>
bool operator== |
( |
const Vector< T, NDIMS > & |
lhs, |
|
|
const Vector< T, NDIMS > & |
rhs |
|
) |
| |
|
friend |
Equality comparison operator for vectors.
◆ operator!=
template<typename T, int NDIMS>
bool operator!= |
( |
const Vector< T, NDIMS > & |
lhs, |
|
|
const Vector< T, NDIMS > & |
rhs |
|
) |
| |
|
friend |
Inequality operator for points.
The documentation for this class was generated from the following file:
- /home/docs/checkouts/readthedocs.org/user_builds/axom/checkouts/v0.3.3/src/axom/primal/geometry/Vector.hpp