RobWorkProject  23.9.11-
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 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 Eigen::MatrixBase< R > &r)
 Creates a 2D vector from Eigen Vector. More...
 
 Vector2D (const Vector2D< T > &copy)
 Copy Constructor.
 
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...
 
const Vector2D< T > operator/ (T s) const
 Scalar division.
 
const Vector2D< T > operator* (T s) const
 Scalar multiplication.
 
const Vector2D< T > operator- (const Vector2D< T > &b) const
 Vector subtraction.
 
const Vector2D< T > operator+ (const Vector2D< T > &b) const
 Vector addition.
 
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.
 
bool operator== (const Vector2D< T > &b) const
 Compares a and b for equality. More...
 
bool operator!= (const Vector2D< T > &b) const
 Compares a and b for inequality. More...
 
double angle () const
 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* (T s, const Vector2D< T > &v)
 Scalar multiplication.
 
std::ostream & operator<< (std::ostream &out, const Vector2D< T > &v)
 Streaming operator.
 

Related Functions

(Note that these are not member functions.)

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)
 
template<class Archive , class T >
void serialize (Archive &archive, rw::math::Vector2D< T > &vector, const unsigned int version)
 Boost serialization. More...
 

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;
Matrices, vectors, configurations, and more.
Definition: core/math_fwd.hpp:23

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 Eigen::MatrixBase< R > &  r)
inline

Creates a 2D vector from Eigen Vector.

Parameters
r[in] an Eigen Vector

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 Vector2D< T > &  b) const
inline

Compares a and b for inequality.

Parameters
b[in]
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\} \)
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\} \)
Returns
const reference to element

◆ operator==()

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

Compares a and b for equality.

Parameters
b[in]
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. 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.

◆ serialize()

void serialize ( Archive &  archive,
rw::math::Vector2D< 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::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 files: