chrono::ChVector< Real > Class Template Reference

Description

template<class Real = double>
class chrono::ChVector< Real >

Definition of general purpose 3d vector variables, such as points in 3D.

This class implements the vectorial algebra in 3D (Gibbs products). ChVector is templated by precision, with default 'double'.

Further info at the Mathematical objects in Chrono manual page.

#include <ChVector.h>

Public Member Functions

 ChVector (Real x, Real y, Real z)
 
 ChVector (Real a)
 
 ChVector (const ChVector< Real > &other)
 
template<class RealB >
 ChVector (const ChVector< RealB > &other)
 Copy constructor with type change.
 
Real & x ()
 Access to components.
 
Real & y ()
 
Real & z ()
 
const Real & x () const
 
const Real & y () const
 
const Real & z () const
 
template<typename Derived >
 ChVector (const Eigen::MatrixBase< Derived > &vec, typename std::enable_if<(Derived::MaxRowsAtCompileTime==1||Derived::MaxColsAtCompileTime==1), Derived >::type *=0)
 Construct a 3d vector from an Eigen vector expression.
 
Eigen::Map< Eigen::Matrix< Real, 3, 1 > > eigen ()
 View this 3d vector as an Eigen vector.
 
Eigen::Map< const Eigen::Matrix< Real, 3, 1 > > eigen () const
 
template<typename Derived >
ChVectoroperator= (const Eigen::MatrixBase< Derived > &vec)
 Assign an Eigen vector expression to this 3d vector.
 
void Set (Real x, Real y, Real z)
 Set the three values of the vector at once.
 
void Set (const ChVector< Real > &v)
 Set the vector as a copy of another vector.
 
void Set (Real s)
 Set all the vector components ts to the same scalar.
 
void SetNull ()
 Set the vector to the null vector. More...
 
bool IsNull () const
 Return true if this vector is the null vector.
 
bool Equals (const ChVector< Real > &other) const
 Return true if this vector is equal to another vector.
 
bool Equals (const ChVector< Real > &other, Real tol) const
 Return true if this vector is equal to another vector, within a tolerance 'tol'.
 
Real Length () const
 Compute the euclidean norm of the vector, that is its length or magnitude.
 
Real Length2 () const
 Compute the squared euclidean norm of the vector.
 
Real LengthInf () const
 Compute the infinity norm of the vector, that is the maximum absolute value of one of its elements.
 
Real & operator[] (unsigned index)
 Subscript operator.
 
const Real & operator[] (unsigned index) const
 
ChVector< Real > & operator= (const ChVector< Real > &other)
 Assignment operator (copy from another vector).
 
template<class RealB >
ChVector< Real > & operator= (const ChVector< RealB > &other)
 Assignment operator (copy from another vector) with type change.
 
ChVector< Real > operator+ () const
 Operators for sign change.
 
ChVector< Real > operator- () const
 
ChVector< Real > operator+ (const ChVector< Real > &other) const
 Operator for vector sum.
 
ChVector< Real > & operator+= (const ChVector< Real > &other)
 
ChVector< Real > operator- (const ChVector< Real > &other) const
 Operator for vector difference.
 
ChVector< Real > & operator-= (const ChVector< Real > &other)
 
ChVector< Real > operator* (const ChVector< Real > &other) const
 Operator for element-wise multiplication. More...
 
ChVector< Real > & operator*= (const ChVector< Real > &other)
 
ChVector< Real > operator/ (const ChVector< Real > &other) const
 Operator for element-wise division. More...
 
ChVector< Real > & operator/= (const ChVector< Real > &other)
 
ChVector< Real > operator* (Real s) const
 Operator for scaling the vector by a scalar value, as V*s.
 
ChVector< Real > & operator*= (Real s)
 
ChVector< Real > operator/ (Real v) const
 Operator for scaling the vector by inverse of a scalar value, as v/s.
 
ChVector< Real > & operator/= (Real v)
 
Real operator^ (const ChVector< Real > &other) const
 Operator for dot product: A^B means the scalar dot-product A*B Note: pay attention to operator low precedence (see C++ precedence rules!)
 
ChVector< Real > operator% (const ChVector< Real > &other) const
 Operator for cross product: AB means the vector cross-product AxB Note: pay attention to operator low precedence (see C++ precedence rules!)
 
ChVector< Real > & operator%= (const ChVector< Real > &other)
 
bool operator<= (const ChVector< Real > &other) const
 Component-wise comparison operators.
 
bool operator>= (const ChVector< Real > &other) const
 
bool operator< (const ChVector< Real > &other) const
 
bool operator> (const ChVector< Real > &other) const
 
bool operator== (const ChVector< Real > &other) const
 
bool operator!= (const ChVector< Real > &other) const
 
void Add (const ChVector< Real > &A, const ChVector< Real > &B)
 Set this vector to the sum of A and B: this = A + B.
 
void Sub (const ChVector< Real > &A, const ChVector< Real > &B)
 Set this vector to the difference of A and B: this = A - B.
 
void Mul (const ChVector< Real > &A, Real s)
 Set this vector to the product of a vector A and scalar s: this = A * s.
 
void Scale (Real s)
 Scale this vector by a scalar: this *= s.
 
void Cross (const ChVector< Real > &A, const ChVector< Real > &B)
 Set this vector to the cross product of A and B: this = A x B.
 
ChVector< Real > Cross (const ChVector< Real > other) const
 Return the cross product with another vector: result = this x other.
 
Real Dot (const ChVector< Real > &B) const
 Return the dot product with another vector: result = this ^ B.
 
bool Normalize ()
 Normalize this vector in place, so that its euclidean length is 1. More...
 
ChVector< Real > GetNormalized () const
 Return a normalized copy of this vector, with euclidean length = 1. More...
 
void SetLength (Real s)
 Impose a new length to the vector, keeping the direction unchanged.
 
void DirToDxDyDz (ChVector< Real > &Vx, ChVector< Real > &Vy, ChVector< Real > &Vz, const ChVector< Real > &Vsingular=ChVector< Real >(0, 1, 0)) const
 Use the Gram-Schmidt orthonormalization to find the three orthogonal vectors of a coordinate system whose X axis is this vector. More...
 
int GetMaxComponent () const
 Return the index of the largest component in absolute value.
 
ChVector< Real > GetOrthogonalVector () const
 Return a unit vector orthogonal to this vector.
 
void ArchiveOUT (ChArchiveOut &marchive)
 Method to allow serialization of transient data to archives.
 
void ArchiveIN (ChArchiveIn &marchive)
 Method to allow de-serialization of transient data from archives.
 

Friends

template<typename RealB >
class ChVector
 Declaration of friend classes.
 

Member Function Documentation

◆ DirToDxDyDz()

template<class Real>
void chrono::ChVector< Real >::DirToDxDyDz ( ChVector< Real > &  Vx,
ChVector< Real > &  Vy,
ChVector< Real > &  Vz,
const ChVector< Real > &  Vsingular = ChVector<Real>(0, 1, 0) 
) const
inline

Use the Gram-Schmidt orthonormalization to find the three orthogonal vectors of a coordinate system whose X axis is this vector.

Vsingular (optional) sets the normal to the plane on which Dz must lie.

◆ GetNormalized()

template<class Real >
ChVector< Real > chrono::ChVector< Real >::GetNormalized ( ) const
inline

Return a normalized copy of this vector, with euclidean length = 1.

Not to be confused with Normalize() which normalizes in place.

◆ Normalize()

template<class Real >
bool chrono::ChVector< Real >::Normalize ( )
inline

Normalize this vector in place, so that its euclidean length is 1.

Return false if the original vector had zero length (in which case the vector is set to [1,0,0]) and return true otherwise.

◆ operator*()

template<class Real>
ChVector< Real > chrono::ChVector< Real >::operator* ( const ChVector< Real > &  other) const
inline

Operator for element-wise multiplication.

Note that this is neither dot product nor cross product.

◆ operator/()

template<class Real>
ChVector< Real > chrono::ChVector< Real >::operator/ ( const ChVector< Real > &  other) const
inline

Operator for element-wise division.

Note that 3D vector algebra is a skew field, non-divisional algebra, so this division operation is just an element-by element division.

◆ SetNull()

template<class Real >
void chrono::ChVector< Real >::SetNull ( )
inline

Set the vector to the null vector.

Sets the vector as a null vector.


The documentation for this class was generated from the following file:
  • /builds/uwsbel/chrono/src/chrono/core/ChVector.h