RobWorkProject  24.8.23-
Public Types | Public Member Functions | Static Public Member Functions | Friends | Related Functions | List of all members
Vector3D< T > Class Template Reference

A 3D vector \( \mathbf{v}\in \mathbb{R}^3 \). More...

#include <Vector3D.hpp>

Public Types

typedef Eigen::Matrix< T, 3, 1 > EigenVector3D
 Eigen type equivalent to Vector3D.
 
typedef T value_type
 Value type.
 

Public Member Functions

 Vector3D ()
 Creates a 3D vector initialized with 0's.
 
 Vector3D (T x, T y, T z)
 Creates a 3D vector. More...
 
 Vector3D (const Vector3D< T > &copy_vec)
 Copy constructor. More...
 
template<class R >
 Vector3D (const Eigen::MatrixBase< R > &r)
 Creates a 3D vector from vector_expression. More...
 
 Vector3D (const std::vector< T > &vec)
 construct vector from std::vector More...
 
size_t size () const
 The dimension of the vector (i.e. 3). This method is provided to help support generic algorithms using size() and operator[]. More...
 
template<class R >
Vector3D< T > elemDivide (const Eigen::MatrixBase< R > &rhs) const
 element wise division. More...
 
template<class R >
Vector3D< T > elemMultiply (const Eigen::MatrixBase< R > &rhs) const
 Elementweise multiplication. More...
 
template<class R >
Vector3D< T > operator- (const Eigen::MatrixBase< R > &rhs) const
 Vector subtraction.
 
template<class R >
Vector3D< T > operator+ (const Eigen::MatrixBase< R > &rhs) const
 Vector addition.
 
Vector3D< T > elemDivide (const Vector3D< T > &rhs) const
 element wise division. More...
 
Vector3D< T > elemMultiply (const Vector3D< T > &rhs) const
 Elementweise multiplication. More...
 
Vector3D< T > operator- (const Vector3D< T > &b) const
 Vector subtraction.
 
Vector3D< T > operator+ (const Vector3D< T > &b) const
 Vector addition.
 
Vector3D< T > operator- () const
 Unary minus. More...
 
Vector3D< T > operator/ (T s) const
 Scalar division. More...
 
Vector3D< T > operator* (T rhs) const
 Scalar multiplication. More...
 
template<class R >
Vector3D< T > operator* (const Eigen::MatrixBase< R > &rhs) const
 Scalar multiplication. More...
 
Vector3D< T > elemSubtract (const T rhs) const
 Scalar subtraction.
 
Vector3D< T > elemAdd (const T rhs) const
 Scalar addition.
 
norm2 () const
 Returns the Euclidean norm (2-norm) of the vector. More...
 
norm1 () const
 Returns the Manhatten norm (1-norm) of the vector. More...
 
normInf () const
 Returns the infinte norm ( \(\inf\)-norm) of the vector. More...
 
Vector3D< T > cross (const Vector3D &vec) const
 Calculate cross product. More...
 
dot (const Vector3D &vec) const
 calculate the dot product More...
 
Vector3D< T > normalize ()
 normalize vector to get length 1 More...
 
EigenVector3De ()
 Returns Reference to Eigen Vector. More...
 
const EigenVector3D e () const
 Returns Reference to Eigen Vector. More...
 
const T & operator() (size_t i) const
 Returns reference to vector element. More...
 
T & operator() (size_t i)
 Returns reference to vector element. More...
 
const T & operator[] (size_t i) const
 Returns reference to vector element. More...
 
T & operator[] (size_t i)
 Returns reference to vector element. More...
 
Vector3D< T > & operator*= (T s)
 Scalar multiplication.
 
Vector3D< T > & operator/= (T s)
 Scalar division.
 
Vector3D< T > & operator+= (const Vector3D< T > &v)
 Vector addition.
 
Vector3D< T > & operator-= (const Vector3D< T > &v)
 Vector subtraction.
 
template<class R >
Vector3D< T > & operator= (const Eigen::MatrixBase< R > &r)
 copy a vector from eigen type More...
 
template<class R >
Vector3D< T > & operator+= (const Eigen::MatrixBase< R > &r)
 Vector addition.
 
template<class R >
Vector3D< T > & operator-= (const Eigen::MatrixBase< R > &r)
 Vector subtraction.
 
bool operator== (const Vector3D< T > &b) const
 Compare with b for equality. More...
 
bool operator!= (const Vector3D< T > &b) const
 Compare with b for inequality. More...
 
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...
 
 operator EigenVector3D () const
 implicit conversion to EigenVector
 
 operator EigenVector3D & ()
 implicit conversion to EigenVector
 

Static Public Member Functions

static Vector3D< T > zero ()
 Get zero vector. More...
 
static Vector3D< T > x ()
 Get x vector (1,0,0) More...
 
static Vector3D< T > y ()
 Get y vector (0,1,0) More...
 
static Vector3D< T > z ()
 Get z vector (0,0,1) More...
 

Friends

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

Related Functions

(Note that these are not member functions.)

template<class T >
const Vector3D< T > cross (const Vector3D< T > &v1, const Vector3D< T > &v2)
 Calculates the 3D vector cross product \( \mathbf{v1} \times \mathbf{v2} \). More...
 
template<class T >
void cross (const Vector3D< T > &v1, const Vector3D< T > &v2, Vector3D< T > &dst)
 Calculates the 3D vector cross product \( \mathbf{v1} \times \mathbf{v2} \). More...
 
template<class T >
dot (const Vector3D< T > &v1, const Vector3D< T > &v2)
 Calculates the dot product \( \mathbf{v1} . \mathbf{v2} \). More...
 
template<class T >
const Vector3D< T > normalize (const Vector3D< T > &v)
 Returns the normalized vector \(\mathbf{n}=\frac{\mathbf{v}}{\|\mathbf{v}\|} \). In case \( \|mathbf{v}\| = 0\) the zero vector is returned. More...
 
template<class T >
double angle (const Vector3D< T > &v1, const Vector3D< T > &v2, const Vector3D< 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<class T >
double angle (const Vector3D< T > &v1, const Vector3D< 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 , class T >
const Vector3D< Qcast (const Vector3D< T > &v)
 Casts Vector3D<T> to Vector3D<Q> More...
 
template<>
void write (const rw::math::Vector3D< double > &sobject, rw::common::OutputArchive &oarchive, const std::string &id)
 
template<>
void write (const rw::math::Vector3D< float > &sobject, rw::common::OutputArchive &oarchive, const std::string &id)
 
template<>
void read (rw::math::Vector3D< double > &sobject, rw::common::InputArchive &iarchive, const std::string &id)
 
template<>
void read (rw::math::Vector3D< float > &sobject, rw::common::InputArchive &iarchive, const std::string &id)
 
template<class Archive , class T >
void serialize (Archive &archive, rw::math::Vector3D< T > &vector, const unsigned int version)
 Boost serialization. More...
 

Detailed Description

template<class T = double>
class rw::math::Vector3D< T >

A 3D vector \( \mathbf{v}\in \mathbb{R}^3 \).

\( \robabx{i}{j}{\mathbf{v}} = \left[ \begin{array}{c} v_x \\ v_y \\ v_z \end{array} \right] \)

Usage example:

const Vector3D<> v1(1.0, 2.0, 3.0);
const Vector3D<> v2(6.0, 7.0, 8.0);
const Vector3D<> v3 = cross(v1, v2);
const double d = dot(v1, v2);
const Vector3D<> v4 = v2 - v1;
T dot(const Vector3D &vec) const
calculate the dot product
Definition: Vector3D.hpp:364
Vector3D< T > cross(const Vector3D &vec) const
Calculate cross product.
Definition: Vector3D.hpp:355

Constructor & Destructor Documentation

◆ Vector3D() [1/4]

Vector3D ( x,
y,
z 
)
inline

Creates a 3D vector.

Parameters
x[in] \( x \)
y[in] \( y \)
z[in] \( z \)

◆ Vector3D() [2/4]

Vector3D ( const Vector3D< T > &  copy_vec)
inline

Copy constructor.

Parameters
copy_vec[in] vector to copy

◆ Vector3D() [3/4]

Vector3D ( const Eigen::MatrixBase< R > &  r)
inlineexplicit

Creates a 3D vector from vector_expression.

Parameters
r[in] an Eigen Vector

◆ Vector3D() [4/4]

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

construct vector from std::vector

Parameters
vec[in] the vector to construct from

Member Function Documentation

◆ cross()

Vector3D<T> cross ( const Vector3D< T > &  vec) const
inline

Calculate cross product.

Parameters
vec[in] the vector to cross with
Returns
the cross product

◆ dot()

T dot ( const Vector3D< T > &  vec) const
inline

calculate the dot product

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

◆ e() [1/2]

EigenVector3D& e ( )
inline

Returns Reference to Eigen Vector.

Returns
reference to underling eigen

◆ e() [2/2]

const EigenVector3D e ( ) const
inline

Returns Reference to Eigen Vector.

Returns
copy of eigen vector

◆ elemDivide() [1/2]

Vector3D<T> elemDivide ( const Eigen::MatrixBase< R > &  rhs) const
inline

element wise division.

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

◆ elemDivide() [2/2]

Vector3D<T> elemDivide ( const Vector3D< T > &  rhs) const
inline

element wise division.

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

◆ elemMultiply() [1/2]

Vector3D<T> elemMultiply ( const Eigen::MatrixBase< R > &  rhs) const
inline

Elementweise multiplication.

Parameters
rhs[in] vector
Returns
the element wise product

◆ elemMultiply() [2/2]

Vector3D<T> elemMultiply ( const Vector3D< 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 vector.

Returns
the norm

◆ norm2()

T norm2 ( ) const
inline

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

Returns
the norm

◆ normalize()

Vector3D<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 vector.

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 object and rhs are different, false otherwise.

◆ operator!=() [2/2]

bool operator!= ( const Vector3D< T > &  b) const
inline

Compare with b for inequality.

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

◆ operator()() [1/2]

T& operator() ( size_t  i)
inline

Returns reference to vector element.

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

◆ operator()() [2/2]

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

Returns reference to vector element.

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

◆ operator*() [1/2]

Vector3D<T> operator* ( const Eigen::MatrixBase< R > &  rhs) const
inline

Scalar multiplication.

Parameters
rhs[in] the Eigen vector^T or matrix to multiply with
Returns
the product

◆ operator*() [2/2]

Vector3D<T> operator* ( rhs) const
inline

Scalar multiplication.

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

◆ operator-()

Vector3D<T> operator- ( ) const
inline

Unary minus.

negative version

◆ operator/()

Vector3D<T> operator/ ( s) const
inline

Scalar division.

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

◆ operator=()

Vector3D<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 this equals rhs, false otherwise.

◆ operator==() [2/2]

bool operator== ( const Vector3D< T > &  b) const
inline

Compare with b for equality.

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

◆ operator[]() [1/2]

T& operator[] ( size_t  i)
inline

Returns reference to vector element.

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

◆ operator[]() [2/2]

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

Returns reference to vector element.

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

◆ size()

size_t size ( ) const
inline

The dimension of the vector (i.e. 3). This method is provided to help support generic algorithms using size() and operator[].

Returns
the size

◆ x()

static Vector3D<T> x ( )
inlinestatic

Get x vector (1,0,0)

Returns
vector.

◆ y()

static Vector3D<T> y ( )
inlinestatic

Get y vector (0,1,0)

Returns
vector.

◆ z()

static Vector3D<T> z ( )
inlinestatic

Get z vector (0,0,1)

Returns
vector.

◆ zero()

static Vector3D<T> zero ( )
inlinestatic

Get zero vector.

Returns
vector.

Friends And Related Function Documentation

◆ angle() [1/2]

double angle ( const Vector3D< T > &  v1,
const Vector3D< 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 Vector3D< T > &  v1,
const Vector3D< T > &  v2,
const Vector3D< 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 Vector3D< Q > cast ( const Vector3D< T > &  v)
related

Casts Vector3D<T> to Vector3D<Q>

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

◆ cross() [1/2]

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

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

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

The 3D vector 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 Vector3D< T > &  v1,
const Vector3D< T > &  v2,
Vector3D< T > &  dst 
)
related

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

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

The 3D vector 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 Vector3D< T > &  v1,
const Vector3D< 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 Vector3D< T > normalize ( const Vector3D< T > &  v)
related

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

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

◆ operator!=

bool operator!= ( const Eigen::MatrixBase< R > &  lhs,
const Vector3D< 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* [1/2]

Vector3D<T> operator* ( const Eigen::MatrixBase< R > &  lhs,
const Vector3D< T > &  rhs 
)
friend

Scalar multiplication.

Parameters
lhs[in] the Eigen vector^T or matrix to multiply with
rhs[in] the Vector to be multiplied
Returns
the product

◆ operator* [2/2]

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

Scalar multiplication.

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

◆ operator/

Vector3D<T> operator/ ( lhs,
const Vector3D< 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 Vector3D< 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 Vector3D< 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.

◆ read() [1/2]

void read ( rw::math::Vector3D< double > &  sobject,
rw::common::InputArchive iarchive,
const std::string &  id 
)
related

Enable read-serialization of class T by overloading this method. Data is read from iarchive and filled into sobject.

Parameters
sobject[out] the object in which the data should be streamed into
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.

◆ read() [2/2]

void read ( rw::math::Vector3D< float > &  sobject,
rw::common::InputArchive iarchive,
const std::string &  id 
)
related

Enable read-serialization of class T by overloading this method. Data is read from iarchive and filled into sobject.

Parameters
sobject[out] the object in which the data should be streamed into
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.

◆ serialize()

void serialize ( Archive &  archive,
rw::math::Vector3D< T > &  vector,
const unsigned int  version 
)
related

Boost serialization.

Parameters
archive[in] the boost archive to read from or write to.
vector[in/out] the vector to read/write.
version[in] class version (currently version 0).

◆ write() [1/2]

void write ( const rw::math::Vector3D< double > &  sobject,
rw::common::OutputArchive oarchive,
const std::string &  id 
)
related

Enable write-serialization of class T by overloading this method. Data is written to oarchive from the sobject.

Parameters
sobject[in] the object from which the data should be streamed.
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.

◆ write() [2/2]

void write ( const rw::math::Vector3D< float > &  sobject,
rw::common::OutputArchive oarchive,
const std::string &  id 
)
related

Enable write-serialization of class T by overloading this method. Data is written to oarchive from the sobject.

Parameters
sobject[in] the object from which the data should be streamed.
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.

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