chrono::ChVector3< Real > Class Template Reference

Description

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

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

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

Further info at the Mathematical objects in Chrono manual page.

#include <ChVector3.h>

Public Member Functions

 ChVector3 (Real x, Real y, Real z)
 
 ChVector3 (Real a)
 
 ChVector3 (const ChVector3< Real > &other)
 
template<class RealB >
 ChVector3 (const ChVector3< 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
 
Real * data ()
 Access to underlying array storage.
 
const Real * data () const
 
template<typename Derived >
 ChVector3 (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 >
ChVector3operator= (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 ChVector3< 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 ChVector3< Real > &other) const
 Return true if this vector is equal to another vector.
 
bool Equals (const ChVector3< 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
 
ChVector3< Real > & operator= (const ChVector3< Real > &other)
 Assignment operator (copy from another vector).
 
template<class RealB >
ChVector3< Real > & operator= (const ChVector3< RealB > &other)
 Assignment operator (copy from another vector) with type change.
 
ChVector3< Real > operator+ () const
 Operators for sign change.
 
ChVector3< Real > operator- () const
 
ChVector3< Real > operator+ (const ChVector3< Real > &other) const
 Operator for vector sum.
 
ChVector3< Real > & operator+= (const ChVector3< Real > &other)
 
ChVector3< Real > operator- (const ChVector3< Real > &other) const
 Operator for vector difference.
 
ChVector3< Real > & operator-= (const ChVector3< Real > &other)
 
ChVector3< Real > operator* (const ChVector3< Real > &other) const
 Operator for element-wise multiplication. More...
 
ChVector3< Real > & operator*= (const ChVector3< Real > &other)
 
ChVector3< Real > operator/ (const ChVector3< Real > &other) const
 Operator for element-wise division. More...
 
ChVector3< Real > & operator/= (const ChVector3< Real > &other)
 
ChVector3< Real > operator* (Real s) const
 Operator for scaling the vector by a scalar value, as V*s.
 
ChVector3< Real > & operator*= (Real s)
 
ChVector3< Real > operator/ (Real v) const
 Operator for scaling the vector by inverse of a scalar value, as v/s.
 
ChVector3< Real > & operator/= (Real v)
 
Real operator^ (const ChVector3< 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!)
 
ChVector3< Real > operator% (const ChVector3< 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!)
 
ChVector3< Real > & operator%= (const ChVector3< Real > &other)
 
bool operator<= (const ChVector3< Real > &other) const
 Component-wise comparison operators.
 
bool operator>= (const ChVector3< Real > &other) const
 
bool operator< (const ChVector3< Real > &other) const
 
bool operator> (const ChVector3< Real > &other) const
 
bool operator== (const ChVector3< Real > &other) const
 
bool operator!= (const ChVector3< Real > &other) const
 
void Add (const ChVector3< Real > &A, const ChVector3< Real > &B)
 Set this vector to the sum of A and B: this = A + B.
 
void Sub (const ChVector3< Real > &A, const ChVector3< Real > &B)
 Set this vector to the difference of A and B: this = A - B.
 
void Mul (const ChVector3< 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 ChVector3< Real > &A, const ChVector3< Real > &B)
 Set this vector to the cross product of A and B: this = A x B.
 
ChVector3< Real > Cross (const ChVector3< Real > other) const
 Return the cross product with another vector: result = this x other.
 
Real Dot (const ChVector3< 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...
 
ChVector3< 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 GetDirectionAxesAsX (ChVector3< Real > &Vx, ChVector3< Real > &Vy, ChVector3< Real > &Vz, ChVector3< Real > y_sugg=ChVector3< Real >(0, 1, 0)) const
 Output three orthonormal vectors considering this vector along X axis. More...
 
void GetDirectionAxesAsY (ChVector3< Real > &Vx, ChVector3< Real > &Vy, ChVector3< Real > &Vz, ChVector3< Real > z_sugg=ChVector3< Real >(0, 0, 1)) const
 Output three orthonormal vectors considering this vector along Y axis. More...
 
void GetDirectionAxesAsZ (ChVector3< Real > &Vx, ChVector3< Real > &Vy, ChVector3< Real > &Vz, ChVector3< Real > x_sugg=ChVector3< Real >(1, 0, 0)) const
 Output three orthonormal vectors considering this vector along Y axis. More...
 
int GetMaxComponent () const
 Return the index of the largest component in absolute value.
 
ChVector3< Real > GetOrthogonalVector () const
 Return a unit vector orthogonal to this vector.
 
void ArchiveOut (ChArchiveOut &archive_out)
 Method to allow serialization of transient m_data to archives.
 
void ArchiveIn (ChArchiveIn &archive_in)
 Method to allow de-serialization of transient m_data from archives.
 

Friends

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

Member Function Documentation

◆ GetDirectionAxesAsX()

template<class Real>
void chrono::ChVector3< Real >::GetDirectionAxesAsX ( ChVector3< Real > &  Vx,
ChVector3< Real > &  Vy,
ChVector3< Real > &  Vz,
ChVector3< Real >  y_sugg = ChVector3<Real>(0, 1, 0) 
) const
inline

Output three orthonormal vectors considering this vector along X axis.

Optionally, the z_sugg vector can be used to suggest the Z axis. It is recommended to set y_sugg to be not parallel to this vector. The Z axis will be orthogonal to X and y_sugg. Rely on Gram-Schmidt orthonormalization.

◆ GetDirectionAxesAsY()

template<class Real>
void chrono::ChVector3< Real >::GetDirectionAxesAsY ( ChVector3< Real > &  Vx,
ChVector3< Real > &  Vy,
ChVector3< Real > &  Vz,
ChVector3< Real >  z_sugg = ChVector3<Real>(0, 0, 1) 
) const
inline

Output three orthonormal vectors considering this vector along Y axis.

Optionally, the z_sugg vector can be used to suggest the Z axis. It is recommended to set z_sugg to be not parallel to this vector. Rely on Gram-Schmidt orthonormalization.

◆ GetDirectionAxesAsZ()

template<class Real>
void chrono::ChVector3< Real >::GetDirectionAxesAsZ ( ChVector3< Real > &  Vx,
ChVector3< Real > &  Vy,
ChVector3< Real > &  Vz,
ChVector3< Real >  x_sugg = ChVector3<Real>(1, 0, 0) 
) const
inline

Output three orthonormal vectors considering this vector along Y axis.

Optionally, the x_sugg vector can be used to suggest the X axis. It is recommended to set x_sugg to be not parallel to this vector. Rely on Gram-Schmidt orthonormalization.

◆ GetNormalized()

template<class Real >
ChVector3< Real > chrono::ChVector3< 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::ChVector3< 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>
ChVector3< Real > chrono::ChVector3< Real >::operator* ( const ChVector3< Real > &  other) const
inline

Operator for element-wise multiplication.

Note that this is neither dot product nor cross product.

◆ operator/()

template<class Real>
ChVector3< Real > chrono::ChVector3< Real >::operator/ ( const ChVector3< 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::ChVector3< 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/ChVector3.h