RobWorkProject  23.9.11-
Public Types | Public Member Functions | Static Public Member Functions | Friends | Related Functions | List of all members
VectorND< N, T > Class Template Reference

A N-Dimensional Vector. More...

#include <VectorND.hpp>

Inherits Serializable.

Public Types

typedef Eigen::Matrix< T, N, 1 > EigenVectorND
 The type of the internal Eigen Vector.
 
typedef T value_type
 Value type.
 

Public Member Functions

 VectorND ()
 Creates a N-dimensional VectorND.
 
template<typename... ARGS>
 VectorND (T arg0, ARGS... args)
 Construct a Vector from N arguments. More...
 
 VectorND (const std::vector< T > &vec)
 construct vector from std::vector More...
 
template<class R >
 VectorND (const Eigen::MatrixBase< R > &v)
 Creates a 3D VectorND from Eigen type. More...
 
size_t size () const
 The dimension of the VectorND (i.e. 3). This method is provided to help support generic algorithms using size() and operator[].
 
template<class R >
VectorND< N, T > elemMultiply (const Eigen::MatrixBase< R > &rhs) const
 element wise multiplication. More...
 
template<class R >
VectorND< N, T > elemDivide (const Eigen::MatrixBase< R > &rhs) const
 element wise division. More...
 
template<class R >
VectorND< N, T > operator- (const Eigen::MatrixBase< R > &rhs) const
 Vector subtraction.
 
template<class R >
VectorND< N, T > operator+ (const Eigen::MatrixBase< R > &rhs) const
 Vector addition.
 
VectorND< N, T > elemDivide (const VectorND< N, T > &rhs) const
 element wise division. More...
 
VectorND< N, T > elemMultiply (const VectorND< N, T > &rhs) const
 Elementweise multiplication. More...
 
VectorND< N, T > operator- (const VectorND< N, T > &rhs) const
 Vector subtraction.
 
VectorND< N, T > operator+ (const VectorND< N, T > &rhs) const
 Vector addition.
 
VectorND< N, T > operator- () const
 Unary minus. More...
 
VectorND< N, T > operator/ (T rhs) const
 Scalar division. More...
 
VectorND< N, T > operator* (T rhs) const
 Scalar multiplication. More...
 
VectorND< N, T > elemSubtract (const T &rhs) const
 Scalar subtraction.
 
VectorND< N, T > elemAdd (const T &rhs) const
 Scalar addition.
 
norm2 () const
 Returns the Euclidean norm (2-norm) of the VectorND. More...
 
norm1 () const
 Returns the Manhatten norm (1-norm) of the VectorND. More...
 
normInf () const
 Returns the infinte norm ( \(\inf\)-norm) of the VectorND. More...
 
double dot (const VectorND< N, T > &vec) const
 calculate the dot product More...
 
VectorND< N, T > normalize ()
 normalize vector to get length 1 More...
 
const T & operator() (size_t i) const
 Returns reference to VectorND element. More...
 
T & operator() (size_t i)
 Returns reference to VectorND element. More...
 
const T & operator[] (size_t i) const
 Returns reference to VectorND element. More...
 
T & operator[] (size_t i)
 Returns reference to VectorND element. More...
 
EigenVectorNDe ()
 Accessor for the internal Eigen VectorND.
 
const EigenVectorNDe () const
 Accessor for the internal Eigen VectorND.
 
std::vector< T > toStdVector () const
 converts the vector to a std:vector More...
 
VectorND< N, T > & operator*= (double s)
 Scalar multiplication.
 
VectorND< N, T > & operator/= (double s)
 Scalar division.
 
VectorND< N, T > & operator+= (const VectorND< N, T > &v)
 Vector addition.
 
VectorND< N, T > & operator-= (const VectorND< N, T > &v)
 Vector subtraction.
 
template<class R >
VectorND< N, T > & operator= (const Eigen::MatrixBase< R > &r)
 copy a vector from eigen type More...
 
template<class R >
VectorND< N, T > & operator+= (const Eigen::MatrixBase< R > &r)
 Vector addition.
 
template<class R >
VectorND< N, T > & operator-= (const Eigen::MatrixBase< R > &r)
 Vector subtraction.
 
template<class R >
bool operator== (const Eigen::MatrixBase< R > &rhs) const
 Compare with rhs for equality. More...
 
template<class R >
bool operator!= (const Eigen::MatrixBase< R > &rhs) const
 Compare with rhs for inequality. More...
 
bool operator== (const VectorND< N, T > &rhs) const
 Compare with rhs for equality. More...
 
bool operator!= (const VectorND< N, T > &rhs) const
 Compare with rhs for inequality. More...
 
void write (rw::common::OutputArchive &oarchive, const std::string &id) const
 
void read (rw::common::InputArchive &iarchive, const std::string &id)
 
 operator EigenVectorND () const
 implicit conversion to EigenVector
 
 operator EigenVectorND & ()
 implicit conversion to EigenVector
 
- Public Member Functions inherited from Serializable
virtual ~Serializable ()
 destructor
 

Static Public Member Functions

static VectorND< N, T > zero ()
 Get zero-initialized vector. More...
 

Friends

template<class R >
VectorND< N, T > operator- (const Eigen::MatrixBase< R > &lhs, const VectorND< N, T > &rhs)
 Vector subtraction.
 
template<class R >
VectorND< N, T > operator+ (const Eigen::MatrixBase< R > &lhs, const VectorND< N, T > &rhs)
 Vector subtraction.
 
VectorND< N, T > operator/ (T lhs, const VectorND< N, T > &rhs)
 Scalar division. More...
 
VectorND< N, T > operator* (T lhs, const VectorND< N, T > &rhs)
 Scalar multiplication. More...
 
std::ostream & operator<< (std::ostream &out, const VectorND< N, T > &v)
 Streaming operator. More...
 
template<class R >
bool operator== (const Eigen::MatrixBase< R > &lhs, const VectorND< N, T > &rhs)
 Compare with rhs for equality. More...
 
template<class R >
bool operator!= (const Eigen::MatrixBase< R > &lhs, const VectorND< N, T > &rhs)
 Compare with rhs for inequality. More...
 

Related Functions

(Note that these are not member functions.)

template<size_t ND, class T >
const VectorND< ND, T > cross (const VectorND< ND, T > &v1, const VectorND< ND, T > &v2)
 Calculates the 3D VectorND cross product \( \mathbf{v1} \times \mathbf{v2} \). More...
 
template<size_t ND, class T >
void cross (const VectorND< ND, T > &v1, const VectorND< ND, T > &v2, VectorND< ND, T > &dst)
 Calculates the 3D VectorND cross product \( \mathbf{v1} \times \mathbf{v2} \). More...
 
template<size_t ND, class T >
dot (const VectorND< ND, T > &v1, const VectorND< ND, T > &v2)
 Calculates the dot product \( \mathbf{v1} . \mathbf{v2} \). More...
 
template<size_t ND, class T >
const VectorND< ND, T > normalize (const VectorND< ND, T > &v)
 Returns the normalized VectorND \(\mathbf{n}=\frac{\mathbf{v}}{\|\mathbf{v}\|} \). In case \( \|mathbf{v}\| = 0\) the zero VectorND is returned. More...
 
template<size_t ND, class T >
double angle (const VectorND< ND, T > &v1, const VectorND< ND, T > &v2, const VectorND< ND, T > &n)
 Calculates the angle from \( \mathbf{v1}\) to \( \mathbf{v2} \) around the axis defined by \( \mathbf{v1} \times \mathbf{v2} \) with n determining the sign. More...
 
template<size_t ND, class T >
double angle (const VectorND< ND, T > &v1, const VectorND< ND, T > &v2)
 Calculates the angle from \( \mathbf{v1}\) to \( \mathbf{v2} \) around the axis defined by \( \mathbf{v1} \times \mathbf{v2} \). More...
 
template<class Q , size_t ND, class T >
const VectorND< ND, Qcast (const VectorND< ND, T > &v)
 Casts VectorND<N,T> to VectorND<Q> More...
 

Detailed Description

template<size_t N, class T = double>
class rw::math::VectorND< N, T >

A N-Dimensional Vector.

Constructor & Destructor Documentation

◆ VectorND() [1/3]

VectorND ( arg0,
ARGS...  args 
)
inline

Construct a Vector from N arguments.

Parameters
arg0[in] first argument
args[in] a list of arguments

◆ VectorND() [2/3]

VectorND ( const std::vector< T > &  vec)
inline

construct vector from std::vector

Parameters
vec[in] the vector to construct from

◆ VectorND() [3/3]

VectorND ( const Eigen::MatrixBase< R > &  v)
inline

Creates a 3D VectorND from Eigen type.

Parameters
v[in] an Eigen vector.

Member Function Documentation

◆ dot()

double dot ( const VectorND< N, T > &  vec) const
inline

calculate the dot product

Parameters
vec[in] the vecor to be dotted
Returns
the dot product

◆ elemDivide() [1/2]

VectorND<N, T> elemDivide ( const Eigen::MatrixBase< R > &  rhs) const
inline

element wise division.

Parameters
rhs[in] vector
Returns
the resulting VectorND

◆ elemDivide() [2/2]

VectorND<N, T> elemDivide ( const VectorND< N, T > &  rhs) const
inline

element wise division.

Parameters
rhs[in] the vector being devided with
Returns
the resulting Vector3D

◆ elemMultiply() [1/2]

VectorND<N, T> elemMultiply ( const Eigen::MatrixBase< R > &  rhs) const
inline

element wise multiplication.

Parameters
rhs[in] the vector being multiplied with
Returns
the resulting VectorND

◆ elemMultiply() [2/2]

VectorND<N, T> elemMultiply ( const VectorND< N, T > &  rhs) const
inline

Elementweise multiplication.

Parameters
rhs[in] vector
Returns
the element wise product

◆ norm1()

T norm1 ( ) const
inline

Returns the Manhatten norm (1-norm) of the VectorND.

Returns
the norm

◆ norm2()

T norm2 ( ) const
inline

Returns the Euclidean norm (2-norm) of the VectorND.

Returns
the norm

◆ normalize()

VectorND<N, T> normalize ( )
inline

normalize vector to get length 1

Returns
the normalized Vector

◆ normInf()

T normInf ( ) const
inline

Returns the infinte norm ( \(\inf\)-norm) of the VectorND.

Returns
the norm

◆ operator!=() [1/2]

bool operator!= ( const Eigen::MatrixBase< R > &  rhs) const
inline

Compare with rhs for inequality.

Parameters
rhs[in] other vector.
Returns
True if this and rhs are different, false otherwise.

◆ operator!=() [2/2]

bool operator!= ( const VectorND< N, T > &  rhs) const
inline

Compare with rhs for inequality.

Parameters
rhs[in] other vector.
Returns
True if this and rhs are different, false otherwise.

◆ operator()() [1/2]

T& operator() ( size_t  i)
inline

Returns reference to VectorND element.

Parameters
i[in] index in the VectorND \(i\in \{0,1,2\} \)
Returns
reference to element

◆ operator()() [2/2]

const T& operator() ( size_t  i) const
inline

Returns reference to VectorND element.

Parameters
i[in] index in the VectorND \(i\in \{0,1,2\} \)
Returns
const reference to element

◆ operator*()

VectorND<N, T> operator* ( rhs) const
inline

Scalar multiplication.

Parameters
rhs[in] the scalar to multiply with
Returns
the product

◆ operator-()

VectorND<N, T> operator- ( ) const
inline

Unary minus.

negative version

◆ operator/()

VectorND<N, T> operator/ ( rhs) const
inline

Scalar division.

Parameters
rhs[in] the scalar to devide with
Returns
result of devision

◆ operator=()

VectorND<N, T>& operator= ( const Eigen::MatrixBase< R > &  r)
inline

copy a vector from eigen type

Parameters
r[in] an Eigen Vector

◆ operator==() [1/2]

bool operator== ( const Eigen::MatrixBase< R > &  rhs) const
inline

Compare with rhs for equality.

Parameters
rhs[in] other vector.
Returns
True if a equals b, false otherwise.

◆ operator==() [2/2]

bool operator== ( const VectorND< N, T > &  rhs) const
inline

Compare with rhs for equality.

Parameters
rhs[in] other vector.
Returns
True if this equals rhs, false otherwise.

◆ operator[]() [1/2]

T& operator[] ( size_t  i)
inline

Returns reference to VectorND element.

Parameters
i[in] index in the VectorND \(i\in \{0,1,2\} \)
Returns
reference to element

◆ operator[]() [2/2]

const T& operator[] ( size_t  i) const
inline

Returns reference to VectorND element.

Parameters
i[in] index in the VectorND \(i\in \{0,1,2\} \)
Returns
const reference to element

◆ read()

void read ( rw::common::InputArchive iarchive,
const std::string &  id 
)
inlinevirtual

Enable read-serialization of inherited class by implementing this method. Data is read from iarchive and filled into this object.

Parameters
iarchive[in] the InputArchive from which to read data.
id[in] The id of the serialized sobject.
Note
the id can be empty in which case the overloaded method should provide a default identifier. E.g. the Vector3D class defined "Vector3D" as its default id.

Implements Serializable.

◆ toStdVector()

std::vector<T> toStdVector ( ) const
inline

converts the vector to a std:vector

Returns
a std::vector

◆ write()

void write ( rw::common::OutputArchive oarchive,
const std::string &  id 
) const
inlinevirtual

Enable write-serialization of inherited class by implementing this method. Data is written to oarchive from this object.

Parameters
oarchive[out] the OutputArchive in which data should be written.
id[in] The id of the serialized sobject.
Note
the id can be empty in which case the overloaded method should provide a default identifier. E.g. the Vector3D class defined "Vector3D" as its default id.

Implements Serializable.

◆ zero()

static VectorND<N, T> zero ( )
inlinestatic

Get zero-initialized vector.

Returns
vector.

Friends And Related Function Documentation

◆ angle() [1/2]

double angle ( const VectorND< ND, T > &  v1,
const VectorND< ND, T > &  v2 
)
related

Calculates the angle from \( \mathbf{v1}\) to \( \mathbf{v2} \) around the axis defined by \( \mathbf{v1} \times \mathbf{v2} \).

Parameters
v1[in] \( \mathbf{v1} \)
v2[in] \( \mathbf{v2} \)
Returns
the angle

◆ angle() [2/2]

double angle ( const VectorND< ND, T > &  v1,
const VectorND< ND, T > &  v2,
const VectorND< ND, T > &  n 
)
related

Calculates the angle from \( \mathbf{v1}\) to \( \mathbf{v2} \) around the axis defined by \( \mathbf{v1} \times \mathbf{v2} \) with n determining the sign.

Parameters
v1[in] \( \mathbf{v1} \)
v2[in] \( \mathbf{v2} \)
n[in] \( \mathbf{n} \)
Returns
the angle

◆ cast()

const VectorND< ND, Q > cast ( const VectorND< ND, T > &  v)
related

Casts VectorND<N,T> to VectorND<Q>

Parameters
v[in] VectorND with type T
Returns
VectorND with type Q

◆ cross() [1/2]

const VectorND< ND, T > cross ( const VectorND< ND, T > &  v1,
const VectorND< ND, T > &  v2 
)
related

Calculates the 3D VectorND cross product \( \mathbf{v1} \times \mathbf{v2} \).

Parameters
v1[in] \( \mathbf{v1} \)
v2[in] \( \mathbf{v2} \)
Returns
the 3D VectorND cross product \( \mathbf{v1} \times \mathbf{v2} \)

The 3D VectorND cross product is defined as: \( \mathbf{v1} \times \mathbf{v2} = \left[\begin{array}{c} v1_y * v2_z - v1_z * v2_y \\ v1_z * v2_x - v1_x * v2_z \\ v1_x * v2_y - v1_y * v2_x \end{array}\right] \)

◆ cross() [2/2]

void cross ( const VectorND< ND, T > &  v1,
const VectorND< ND, T > &  v2,
VectorND< ND, T > &  dst 
)
related

Calculates the 3D VectorND cross product \( \mathbf{v1} \times \mathbf{v2} \).

Parameters
v1[in] \( \mathbf{v1} \)
v2[in] \( \mathbf{v2} \)
dst[out] the 3D VectorND cross product \( \mathbf{v1} \times \mathbf{v2} \)

The 3D VectorND cross product is defined as: \( \mathbf{v1} \times \mathbf{v2} = \left[\begin{array}{c} v1_y * v2_z - v1_z * v2_y \\ v1_z * v2_x - v1_x * v2_z \\ v1_x * v2_y - v1_y * v2_x \end{array}\right] \)

◆ dot()

T dot ( const VectorND< ND, T > &  v1,
const VectorND< ND, T > &  v2 
)
related

Calculates the dot product \( \mathbf{v1} . \mathbf{v2} \).

Parameters
v1[in] \( \mathbf{v1} \)
v2[in] \( \mathbf{v2} \)
Returns
the dot product \( \mathbf{v1} . \mathbf{v2} \)

◆ normalize()

const VectorND< ND, T > normalize ( const VectorND< ND, T > &  v)
related

Returns the normalized VectorND \(\mathbf{n}=\frac{\mathbf{v}}{\|\mathbf{v}\|} \). In case \( \|mathbf{v}\| = 0\) the zero VectorND is returned.

Parameters
v[in] \( \mathbf{v} \) which should be normalized
Returns
the normalized VectorND \( \mathbf{n} \)

◆ operator!=

bool operator!= ( const Eigen::MatrixBase< R > &  lhs,
const VectorND< N, T > &  rhs 
)
friend

Compare with rhs for inequality.

Parameters
lhs[in] first vector.
rhs[in] other vector.
Returns
True if lhs and rhs are different, false otherwise.

◆ operator*

VectorND<N, T> operator* ( lhs,
const VectorND< N, T > &  rhs 
)
friend

Scalar multiplication.

Parameters
lhs[in] the scalar to multiply with
rhs[in] the Vector to be multiplied
Returns
the product

◆ operator/

VectorND<N, T> operator/ ( lhs,
const VectorND< N, T > &  rhs 
)
friend

Scalar division.

Parameters
lhs[in] the scalar to devide with
rhs[out] the vector beind devided
Returns
result of devision

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const VectorND< N, T > &  v 
)
friend

Streaming operator.

Parameters
out[in/out] the stream to continue
v[in] the vector to stream
Returns
reference to out

◆ operator==

bool operator== ( const Eigen::MatrixBase< R > &  lhs,
const VectorND< N, T > &  rhs 
)
friend

Compare with rhs for equality.

Parameters
lhs[in] first vector.
rhs[in] other vector.
Returns
True if lhs equals rhs, false otherwise.

The documentation for this class was generated from the following files: