RobWorkProject
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 boost::numeric::ublas::bounded_vector< T, 3 > BoostBoundedVector
 Boost type equivalent to Vector3D.
 
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...
 
template<class R >
 Vector3D (const boost::numeric::ublas::vector_expression< R > &r)
 Creates a 3D vector from vector_expression. More...
 
template<class R >
 Vector3D (const Eigen::MatrixBase< R > &r)
 Creates a 3D vector from vector_expression. More...
 
const BoostBoundedVector m () const
 Returns Boost vector with the values of *this.
 
const EigenVector3D e () const
 Returns Eigen vector with the values of *this.
 
size_t size () const
 The dimension of the vector (i.e. 3). 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...
 
const Vector3D< T > operator/ (T s) const
 Scalar division.
 
const Vector3D< T > operator* (T s) const
 Scalar multiplication.
 
const Vector3D< T > operator- (const Vector3D< T > &b) const
 Vector subtraction.
 
const Vector3D< T > operator+ (const Vector3D< T > &b) const
 Vector addition.
 
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.
 
const Vector3D< T > operator- () const
 Unary minus.
 
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...
 
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...
 

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

const Vector3D< T > operator* (T s, const Vector3D< T > &v)
 Scalar multiplication.
 
std::ostream & operator<< (std::ostream &out, const Vector3D< T > &v)
 Streaming operator.
 

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)
 

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;

Constructor & Destructor Documentation

◆ Vector3D() [1/3]

Vector3D ( x,
y,
z 
)
inline

Creates a 3D vector.

Parameters
x[in] $ x $
y[in] $ y $
z[in] $ z $

◆ Vector3D() [2/3]

Vector3D ( const boost::numeric::ublas::vector_expression< R > &  r)
inlineexplicit

Creates a 3D vector from vector_expression.

Parameters
r[in] an ublas vector_expression

◆ Vector3D() [3/3]

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

Creates a 3D vector from vector_expression.

Parameters
r[in] an ublas vector_expression

Member Function Documentation

◆ 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

◆ normInf()

T normInf ( ) const
inline

Returns the infinte norm ( $\inf$-norm) of the vector.

Returns
the norm

◆ operator!=()

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]

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()() [2/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==()

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]

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[]() [2/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

◆ 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[].

◆ 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

◆ 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.

◆ 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 file: