RobWorkProject
Public Types | Public Member Functions | Friends | Related Functions | List of all members
Vector2D< T > Class Template Reference

A 2D vector $ \mathbf{v}\in \mathbb{R}^2 $. More...

#include <Vector2D.hpp>

Public Types

typedef boost::numeric::ublas::bounded_vector< T, 2 > BoostVector2D
 Boost based Vector2D.
 
typedef Eigen::Matrix< T, 2, 1 > EigenVector2D
 Eigen based Vector2D.
 
typedef T value_type
 Value type.
 

Public Member Functions

 Vector2D ()
 Creates a 2D vector initialized with 0's.
 
 Vector2D (T x, T y)
 Creates a 2D vector. More...
 
template<class R >
 Vector2D (const boost::numeric::ublas::vector_expression< R > &r)
 Creates a 2D vector from vector_expression. More...
 
BoostVector2D m () const
 Returns Boost vector equivalent to *this.
 
EigenVector2D e () const
 Returns Eigen vector equivalent to *this.
 
size_t size () const
 The dimension of the vector (i.e. 2). 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...
 
Vector2D< T > & operator*= (T s)
 Scalar multiplication.
 
Vector2D< T > & operator/= (T s)
 Scalar division.
 
Vector2D< T > & operator+= (const Vector2D< T > &v)
 Vector addition.
 
Vector2D< T > & operator-= (const Vector2D< T > &v)
 Vector subtraction.
 
const Vector2D< T > operator- () const
 Unary minus.
 
double angle ()
 returns the counter clock-wise angle between this vector and the x-axis vector (1,0). The angle returned will be in the interval [-Pi,Pi]
 
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...
 

Friends

const Vector2D< T > operator/ (const Vector2D< T > &v, T s)
 Scalar division.
 
const Vector2D< T > operator* (const Vector2D< T > &v, T s)
 Scalar multiplication.
 
const Vector2D< T > operator* (T s, const Vector2D< T > &v)
 Scalar multiplication.
 
const Vector2D< T > operator- (const Vector2D< T > &a, const Vector2D< T > &b)
 Vector subtraction.
 
const Vector2D< T > operator+ (const Vector2D< T > &a, const Vector2D< T > &b)
 Vector addition.
 
std::ostream & operator<< (std::ostream &out, const Vector2D< T > &v)
 Streaming operator.
 

Related Functions

(Note that these are not member functions.)

template<class T >
bool operator== (const Vector2D< T > &a, const Vector2D< T > &b)
 Compares a and b for equality. More...
 
template<class T >
bool operator!= (const Vector2D< T > &a, const Vector2D< T > &b)
 Compares a and b for inequality. More...
 
template<>
void write (const rw::math::Vector2D< double > &sobject, rw::common::OutputArchive &oarchive, const std::string &id)
 
template<>
void write (const rw::math::Vector2D< float > &sobject, rw::common::OutputArchive &oarchive, const std::string &id)
 
template<>
void read (rw::math::Vector2D< double > &sobject, rw::common::InputArchive &iarchive, const std::string &id)
 
template<>
void read (rw::math::Vector2D< float > &sobject, rw::common::InputArchive &iarchive, const std::string &id)
 

Detailed Description

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

A 2D vector $ \mathbf{v}\in \mathbb{R}^2 $.

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

In addition, Vector2D supports the cross product operator: v3 = cross(v1, v2)

Usage example:

using namespace rw::math;
Vector2D<> v1(1.0, 2.0);
Vector2D<> v2(6.0, 7.0);
Vector2D<> v3 = cross( v1, v2 );
Vector2D<> v4 = v2 - v1;

Constructor & Destructor Documentation

◆ Vector2D() [1/2]

Vector2D ( x,
y 
)
inline

Creates a 2D vector.

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

◆ Vector2D() [2/2]

Vector2D ( const boost::numeric::ublas::vector_expression< R > &  r)
inline

Creates a 2D 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()() [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\} $
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\} $
Returns
reference to element

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

This method is provided to help support generic algorithms using size() and operator[].

Friends And Related Function Documentation

◆ read() [1/2]

void read ( rw::math::Vector2D< 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::Vector2D< 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::Vector2D< 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::Vector2D< 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: