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.9.1/src/axom/primal/geometry/Vector.hpp>
|
AXOM_HOST_DEVICE | 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...
|
|
AXOM_HOST_DEVICE | Vector (const NumericArray< T, NDIMS > &arr) |
| Constructor from a numeric array. More...
|
|
AXOM_HOST_DEVICE | Vector (const T *vals, int sz=NDIMS) |
| Creates a vector from the first sz values of the input array. More...
|
|
AXOM_HOST_DEVICE | Vector (const Point< T, NDIMS > &pt) |
| Constructor to create vector from a Point. More...
|
|
AXOM_HOST_DEVICE | Vector (const Point< T, NDIMS > &A, const Point< T, NDIMS > &B) |
| Constructs a vector from point A to point B. More...
|
|
AXOM_HOST_DEVICE | Vector (std::initializer_list< T > values) |
| Creates a vector from an initializer list. More...
|
|
AXOM_HOST_DEVICE int | dimension () const |
| Returns the dimension of this vector instance. More...
|
|
AXOM_HOST_DEVICE const T & | operator[] (int i) const |
| Access operator for individual components. More...
|
|
AXOM_HOST_DEVICE T & | operator[] (int i) |
|
AXOM_HOST_DEVICE const NumericArray< T, NDIMS > & | array () const |
| Returns a reference to the underlying NumericArray. More...
|
|
AXOM_HOST_DEVICE NumericArray< T, NDIMS > & | array () |
|
AXOM_HOST_DEVICE const T * | data () const |
| Returns a pointer to the underlying data. More...
|
|
AXOM_HOST_DEVICE T * | data () |
|
AXOM_HOST_DEVICE Vector< T, NDIMS > & | operator+= (const Vector< T, NDIMS > &v) |
| Adds the vector to the Vector instance \(\vec{u} +=\vec{v}\). More...
|
|
AXOM_HOST_DEVICE Vector< T, NDIMS > & | operator-= (const Vector< T, NDIMS > &v) |
| Adds the vector ot the Vector instance \(\vec{u} -=\vec{v}\). More...
|
|
AXOM_HOST_DEVICE Vector< T, NDIMS > & | operator*= (T scalar) |
| Scalar multiplication on the Vector instance. More...
|
|
AXOM_HOST_DEVICE Vector< T, NDIMS > & | operator/= (T scalar) |
| Scalar division on the Vector instance. More...
|
|
AXOM_HOST_DEVICE bool | is_zero () const |
| Check if this is a zero vector. More...
|
|
AXOM_HOST_DEVICE T | dot (const Vector< T, NDIMS > &v) const |
| Dot product of the Vector instance with another vector v. More...
|
|
AXOM_HOST_DEVICE double | squared_norm () const |
| Computes the squared \( l^2\) norm of this vector instance. More...
|
|
AXOM_HOST_DEVICE double | norm () const |
| Computes the \( l^2 \) norm of this vector instance. More...
|
|
AXOM_HOST_DEVICE void | negate () |
| Component-wise negation of the vector. More...
|
|
AXOM_HOST_DEVICE 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 AXOM_HOST_DEVICE T | dot_product (const Vector< T, NDIMS > &u, const Vector< T, NDIMS > &v) |
| Computes the dot product of two vectors u, v. More...
|
|
static AXOM_HOST_DEVICE 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 AXOM_HOST_DEVICE 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 AXOM_HOST_DEVICE T | scalar_triple_product (const Vector< T, 3 > &u, const Vector< T, 3 > &v, const Vector< T, 3 > &w) |
| Computes the 3-D scalar triple product of vectors u, v and w. 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>
◆ CoordType
template<typename T , int NDIMS>
◆ Vector() [1/6]
template<typename T , int NDIMS>
Fill vector with single value. Acts as default constructor Sets first sz components of the vector to val (default 0).
- Parameters
-
[in] | val | The value to set the coordinates to. Defaults to zero |
[in] | sz | The number of coordinates to set to val. The rest will be set to zero. Defaults is 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>
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() [6/6]
template<typename T , int NDIMS>
Creates a vector from an initializer list.
- Parameters
-
[in] | values | an initializer list containing the values of the vector. If the size is not the same as the size of this vector, this behaves the same way as the constructor which takes a pointer and size. |
◆ dimension()
template<typename T , int NDIMS>
Returns the dimension of this vector instance.
- Returns
- d the dimension (size) of the vector
- Postcondition
- d >= 1.
◆ 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>
◆ 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>
◆ operator-=()
template<typename T , int NDIMS>
◆ 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.
◆ is_zero()
template<typename T , int NDIMS>
◆ dot()
template<typename T , int NDIMS>
Dot product of the Vector instance with another vector v.
- Parameters
-
[in] | v | the other vector in the dot product |
- Returns
- The dot product of the two vectors.
References axom::numerics::dot_product().
◆ squared_norm()
template<typename T , int NDIMS>
Computes the squared \( l^2\) norm of this vector instance.
- Returns
- n the squared norm.
- See also
- Vector::norm()
◆ norm()
template<typename T , int NDIMS>
Computes the \( l^2 \) norm of this vector instance.
- Returns
- n the norm of the vector, a.k.a., magnitude or length.
◆ negate()
template<typename T , int NDIMS>
Component-wise negation of the vector.
◆ 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
◆ 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
◆ dot_product()
template<typename T , int NDIMS>
Computes the dot product of two vectors u, v.
- Parameters
-
[in] | u | the vector on the right-hand side. |
[in] | v | the vector on the left-hand side. |
- Returns
- dotprod the computed dot product.
- Precondition
- u.dimension() == v.dimension().
◆ cross_product() [1/2]
template<typename T , int NDIMS>
Computes the cross product of vector u and v, treating them as 3D.
- 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.
References axom::numerics::determinant().
◆ 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.
References axom::numerics::determinant().
◆ scalar_triple_product()
template<typename T , int NDIMS>
Computes the 3-D scalar triple product of vectors u, v and w.
- Parameters
-
[in] | u | the first vector |
[in] | v | the second vector |
[in] | w | the third vector |
- Returns
- The scalar triple product of u, v and w
The scalar triple product dot(u, v x w) is the signed volume of the parallelepiped defined by the three 3D vectors
References axom::numerics::determinant().
◆ 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>
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.9.1/src/axom/primal/geometry/Vector.hpp