chrono::ChVector2< Real > Class Template Reference

## Description

### template<class Real = double> class chrono::ChVector2< Real >

Definition of a general purpose 2d vector.

ChVector2 is templated by precision, with default 'double'.

#include <ChVector2.h>

## Public Member Functions

ChVector2 (Real x, Real y)

ChVector2 (Real a)

ChVector2 (const ChVector2< Real > &other)

template<class RealB >
ChVector2 (const ChVector2< RealB > &other)
Copy constructor with type change.

Real & x ()

Real & y ()

const Real & x () const

const Real & y () const

const Real * data () const
Return const pointer to underlying array storage.

void Set (Real x, Real y)
Set the two values of the vector at once.

void Set (const ChVector2< Real > &v)
Sets 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 ChVector2< Real > &other) const
Return true if this vector is equal to another vector.

bool Equals (const ChVector2< 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 infinite 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

ChVector2< Real > & operator= (const ChVector2< Real > &other)
Assignment operator (copy from another vector).

template<class RealB >
ChVector2< Real > & operator= (const ChVector2< RealB > &other)
Assignment operator (copy from another vector) with type change.

ChVector2< Real > operator+ () const
Operators for sign change.

ChVector2< Real > operator- () const

ChVector2< Real > operator+ (const ChVector2< Real > &other) const
Operator for vector sum.

ChVector2< Real > & operator+= (const ChVector2< Real > &other)

ChVector2< Real > operator- (const ChVector2< Real > &other) const
Operator for vector difference.

ChVector2< Real > & operator-= (const ChVector2< Real > &other)

ChVector2< Real > operator* (const ChVector2< Real > &other) const
Operator for element-wise multiplication. More...

ChVector2< Real > & operator*= (const ChVector2< Real > &other)

ChVector2< Real > operator/ (const ChVector2< Real > &other) const
Operator for element-wise division.

ChVector2< Real > & operator/= (const ChVector2< Real > &other)

ChVector2< Real > operator* (const Real s) const
Operator for scaling the vector by a scalar value, as V*s.

ChVector2< Real > & operator*= (const Real s)

ChVector2< Real > operator/ (const Real v) const
Operator for scaling the vector by inverse of a scalar value, as v/s.

ChVector2< Real > & operator/= (const Real v)

Real operator^ (const ChVector2< 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!)

bool operator<= (const ChVector2< Real > &other) const
Component-wise comparison operators.

bool operator>= (const ChVector2< Real > &other) const

bool operator< (const ChVector2< Real > &other) const

bool operator> (const ChVector2< Real > &other) const

bool operator== (const ChVector2< Real > &other) const

bool operator!= (const ChVector2< Real > &other) const

void Add (const ChVector2< Real > &A, const ChVector2< Real > &B)
Set this vector to the sum of A and B: this = A + B.

void Sub (const ChVector2< Real > &A, const ChVector2< Real > &B)
Set this vector to the difference of A and B: this = A - B.

void Mul (const ChVector2< Real > &A, const Real s)
Set this vector to the product of a vector A and scalar s: this = A * s.

void Scale (const Real s)
Scale this vector by a scalar: this *= s.

Real Dot (const ChVector2< 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...

ChVector2< 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 Rotate (Real angle)
Apply a 2D rotation of given angle (positive counterclockwise).

int GetMaxComponent () const
Return the index of the largest component in absolute value.

ChVector2< Real > GetOrthogonalVector () const
Return a unit vector orthogonal to this vector.

void ArchiveOUT (ChArchiveOut &marchive)
Method to allow serialization of transient m_data to archives.

void ArchiveIN (ChArchiveIn &marchive)
Method to allow de-serialization of transient m_data from archives.

## Friends

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

## ◆ GetNormalized()

template<class Real >
 ChVector2< Real > chrono::ChVector2< 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::ChVector2< 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 set to [1,0,0]) and return true otherwise.

## ◆ operator*()

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

Operator for element-wise multiplication.

Note that this is not the dot product.

## ◆ SetNull()

template<class Real >
 void chrono::ChVector2< 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/ChVector2.h