Algebra3D
Algebra for 3D transformations
 All Classes Namespaces Files Functions Variables Typedefs Macros
Public Member Functions | Public Attributes | Protected Attributes | Friends | List of all members
algebra3d::Vector3< fpType > Class Template Reference

A class to store vectors of 3 elements. More...

#include <Vector3.h>

Public Member Functions

 Vector3 ()
 
 Vector3 (const fpType *const data)
 
 Vector3 (fpType x, fpType y, fpType z)
 
 Vector3 (const Vector3< fpType > &vec)
 
 Vector3 (const Vector3< fpType > &axis, fpType angle)
 
 Vector3 (const Quaternion< fpType > &quat)
 
 Vector3 (const Matrix3< fpType > &mat)
 
virtual ~Vector3 ()
 
virtual void set (const fpType *data)
 
virtual void get (fpType *storage) const
 
virtual fpType dot (const Vector3< fpType > &vec) const
 
virtual Vector3< fpType > cross (const Vector3< fpType > &vec) const
 
virtual Matrix3< fpType > outer (const Vector3< fpType > &vec) const
 
virtual Matrix3< fpType > crossMatrix () const
 
virtual fpType getNorm () const
 
virtual void normalize ()
 
bool isZero () const
 
Vector3< fpType > getUnit () const
 
fpType getAngle () const
 
Vector3< fpType > getSqrtRotation () const
 
virtual void operator= (const Vector3< fpType > &vec)
 
virtual const fpType & operator[] (int ind) const
 
virtual fpType & operator[] (int ind)
 
virtual bool compare (const Vector3< fpType > &vec, const fpType &precision=PRECISION) const
 
virtual bool operator== (const Vector3< fpType > &vec) const
 
virtual bool operator!= (const Vector3< fpType > &vec) const
 
virtual void operator+= (const Vector3< fpType > &vec)
 
virtual Vector3< fpType > operator+ (const Vector3< fpType > &vec) const
 
virtual Vector3< fpType > operator- () const
 
virtual void operator-= (const Vector3< fpType > &vec)
 
virtual Vector3< fpType > operator- (const Vector3< fpType > &vec) const
 
void operator*= (const Matrix3< fpType > &mat)
 
virtual Vector3< fpType > operator* (const Matrix3< fpType > &mat) const
 
virtual Vector3< fpType > operator* (const Vector3< fpType > &vec) const
 
virtual void operator*= (const fpType &s)
 
virtual Vector3< fpType > operator* (const fpType &s) const
 
virtual void operator/= (const fpType &s)
 
virtual Vector3< fpType > operator/ (const fpType &s) const
 

Public Attributes

fpType & x
 
fpType & y
 
fpType & z
 

Protected Attributes

fpType data [3]
 

Friends

template<class fpT >
std::istream & operator>> (std::istream &stream, Vector3< fpT > &vec)
 

Detailed Description

template<class fpType>
class algebra3d::Vector3< fpType >

A class to store vectors of 3 elements.

Author
Jarek Glowacki

Constructor & Destructor Documentation

template<class fpType>
algebra3d::Vector3< fpType >::Vector3 ( )

Creates an instance of a 0 vector.

template<class fpType>
algebra3d::Vector3< fpType >::Vector3 ( const fpType *const  data)

Creates an instance using the provided data.

Parameters
[in]dataReference to the data to initialize the vector with.
template<class fpType>
algebra3d::Vector3< fpType >::Vector3 ( fpType  x,
fpType  y,
fpType  z 
)

Initializes the vector with the provided values.

Parameters
[in]xFirst coordinate.
[in]ySecond coordinate.
[in]zThird coordinate.
template<class fpType>
algebra3d::Vector3< fpType >::Vector3 ( const Vector3< fpType > &  vec)

Copies elements of the provided vector into this one.

Parameters
[in]vecThe vector to copy.
template<class fpType>
algebra3d::Vector3< fpType >::Vector3 ( const Vector3< fpType > &  axis,
fpType  angle 
)

Creates a Cayley vector for the provided rotation given by axis and angle.

Parameters
[in]axisThe rotation axis (not necessary a unit vector).
[in]angleThe angle of rotation.
template<class fpType>
algebra3d::Vector3< fpType >::Vector3 ( const Quaternion< fpType > &  quat)

Creates a Cayley vector for the provided rotation given by a quaternion.

Parameters
[in]quatThe quaternion representing the rotation.
template<class fpType>
algebra3d::Vector3< fpType >::Vector3 ( const Matrix3< fpType > &  mat)

Creates a Cayley vector for the provided rotation given by a matrix.

Note
Watch out for the singular case with trace of the provided matrix equal to -1 where the norm of the Cayley vector tends to infinity.
Parameters
[in]matThe matrix of the rotation.
template<class fpType>
virtual algebra3d::Vector3< fpType >::~Vector3 ( )
virtual

Does nothing. Virtual classes require virtual destructors.

Member Function Documentation

template<class fpType>
virtual bool algebra3d::Vector3< fpType >::compare ( const Vector3< fpType > &  vec,
const fpType &  precision = PRECISION 
) const
virtual

Checks if all elements of the provided vector are the same as in this one up to the provided precision. The comparison is simply checking if the difference between numbers is smaller or equal the precision.

Parameters
[in]vecThe vector to compare this with.
[in]precisionThe precision to use; by default the global PRECISION is used.
Returns
true if all entries are equal up to the precision, false otherwise.
template<class fpType>
virtual Vector3<fpType> algebra3d::Vector3< fpType >::cross ( const Vector3< fpType > &  vec) const
virtual

Returns the cross product of this vector with the provided one.

Parameters
[in]vecThe other vector of the cross product.
Returns
The cross product of this vector with the provided one.
template<class fpType>
virtual Matrix3<fpType> algebra3d::Vector3< fpType >::crossMatrix ( ) const
virtual

Returns the cross product matrix of this vector, i.e. a cross product operator for the vector.

Returns
The cross product matrix of this vector
template<class fpType>
virtual fpType algebra3d::Vector3< fpType >::dot ( const Vector3< fpType > &  vec) const
virtual

Returns the dot product of this vector and the provided one.

Parameters
[in]vecThe vector to multiply this by.
Returns
The dot product of this vector and the provided one.
template<class fpType>
virtual void algebra3d::Vector3< fpType >::get ( fpType *  storage) const
virtual

Copies the vector data to the provided array. First 3 positions from the given pointer are written).

Parameters
[out]storageThe array to copy the data to.
template<class fpType>
fpType algebra3d::Vector3< fpType >::getAngle ( ) const

Returns the angle of rotation represented by this Cayley vector.

Returns
The angle of rotation represented by this Cayley vector.
template<class fpType>
virtual fpType algebra3d::Vector3< fpType >::getNorm ( ) const
virtual

Returns the L2 norm of the vector (sqrt(*this * *this)).

Returns
The L2 norm of the vector (sqrt(*this * *this)).
template<class fpType>
Vector3<fpType> algebra3d::Vector3< fpType >::getSqrtRotation ( ) const

Returns the Cayley vector representation of half of the rotation represented by this instance.

Returns
the Cayley vector representation of half of the rotation represented by this instance.
template<class fpType>
Vector3<fpType> algebra3d::Vector3< fpType >::getUnit ( ) const

Returns a unit vector in the direction of this one. For infinite and zero vectors their copies are returned.

Returns
A unit vector in the direction of this one.
template<class fpType>
bool algebra3d::Vector3< fpType >::isZero ( ) const

Returns true if all components are 0 (up to the precision), false otherwise.

Returns
true if all components are 0 (up to the precision), false otherwise.
template<class fpType>
virtual void algebra3d::Vector3< fpType >::normalize ( )
virtual

Normalizes the vector to unit length. Divides the vector by sqrt(*this * *this).

template<class fpType>
virtual bool algebra3d::Vector3< fpType >::operator!= ( const Vector3< fpType > &  vec) const
virtual

Comparing operator. Checks if any element of this vector differs from respective element of the parameter.

Parameters
[in]vecThe vector to compare this with.
Returns
false if all entries are equal, true otherwise.
template<class fpType>
virtual Vector3<fpType> algebra3d::Vector3< fpType >::operator* ( const Matrix3< fpType > &  mat) const
virtual

Returns the product of this vector and the provided matrix (v * m - vector treated as 1x3).

Parameters
[in]matThe matrix to multiply this vector by.
Returns
The product of this vector and the provided matrix (post-multiplication).
template<class fpType>
virtual Vector3<fpType> algebra3d::Vector3< fpType >::operator* ( const Vector3< fpType > &  vec) const
virtual

Returns the effect of rotating the provided vector according to this Cayley vector.

Parameters
[in]vecThe vector to transform according to this Cayley vector.
Returns
The effect of rotating the provided vector according to this Cayley vector.
template<class fpType>
virtual Vector3<fpType> algebra3d::Vector3< fpType >::operator* ( const fpType &  s) const
virtual

Scales a copy of this vector by the provided number and returns it.

Parameters
[in]sThe scaling factor.
Returns
The scaled vector.
template<class fpType>
void algebra3d::Vector3< fpType >::operator*= ( const Matrix3< fpType > &  mat)

Post-multiplies this vector by the provided matrix (v * m - vector treated as a 1x3).

Parameters
[in]matThe matrix to multiply this vector by.
Returns
The product of this vector and the provided matrix (post-multiplication).
template<class fpType>
virtual void algebra3d::Vector3< fpType >::operator*= ( const fpType &  s)
virtual

Scales a this vector by the provided number.

Parameters
[in]sThe scaling factor.
template<class fpType>
virtual Vector3<fpType> algebra3d::Vector3< fpType >::operator+ ( const Vector3< fpType > &  vec) const
virtual

Returns the sum of this vector and the provided one.

Parameters
[in]vecThe other argument of the sum.
Returns
The sum of this vector and the provided one.
template<class fpType>
virtual void algebra3d::Vector3< fpType >::operator+= ( const Vector3< fpType > &  vec)
virtual

Adds the provided vector to this one.

Parameters
[in]vecThe vector to add.
template<class fpType>
virtual Vector3<fpType> algebra3d::Vector3< fpType >::operator- ( ) const
virtual

Returns a copy of this vector multiplied by -1.

Returns
A copy of this vector multiplied by -1.
template<class fpType>
virtual Vector3<fpType> algebra3d::Vector3< fpType >::operator- ( const Vector3< fpType > &  vec) const
virtual

Returns the result of subtracting the provided vector from this one.

Parameters
[in]vecThe matrix to subtract.
Returns
The result of subtracting the provided vector from this one.
template<class fpType>
virtual void algebra3d::Vector3< fpType >::operator-= ( const Vector3< fpType > &  vec)
virtual

Subtracts the provided vector from this one.

Parameters
[in]vecThe vector to subtract.
template<class fpType>
virtual Vector3<fpType> algebra3d::Vector3< fpType >::operator/ ( const fpType &  s) const
virtual

Scales a copy of this vector by the inverse of the provided number and returns it.

Parameters
[in]sThe inverse scaling factor.
Returns
The scaled matrix.
template<class fpType>
virtual void algebra3d::Vector3< fpType >::operator/= ( const fpType &  s)
virtual

Scales a this matrix by the inverse of the provided number.

Parameters
[in]sThe inverse scaling factor.
template<class fpType>
virtual void algebra3d::Vector3< fpType >::operator= ( const Vector3< fpType > &  vec)
virtual

Copies elements of the provided vector into this one.

Parameters
[in]vecThe vector to copy.
template<class fpType>
virtual bool algebra3d::Vector3< fpType >::operator== ( const Vector3< fpType > &  vec) const
virtual

Comparing operator. Checks if all elements of the provided vector are the same as this.

Parameters
[in]vecThe vector to compare this with.
Returns
true if all entries are equal, false otherwise.
template<class fpType>
virtual const fpType& algebra3d::Vector3< fpType >::operator[] ( int  ind) const
virtual

Returns a reference to the element of the vector with the provided index. If the index is incorrect the closest correct one is used is returned. Version for constant instances.

Parameters
[in]indIndex of the element to return.
Returns
Reference to the selected element.
template<class fpType>
virtual fpType& algebra3d::Vector3< fpType >::operator[] ( int  ind)
virtual

Returns a reference to the element of the vector with the provided index. If the index is incorrect the closest correct one is used is returned.

Parameters
[in]indIndex of the element to return.
Returns
Reference to the selected element.
template<class fpType>
virtual Matrix3<fpType> algebra3d::Vector3< fpType >::outer ( const Vector3< fpType > &  vec) const
virtual

Returns the outer product of this vector and the provided one.

Parameters
[in]vecThe vector to multiply this by.
Returns
The outer product of this vector and the provided one.
template<class fpType>
virtual void algebra3d::Vector3< fpType >::set ( const fpType *  data)
virtual

Set the vector data to the values in the provided array. First 3 positions from the given pointer are read.

Parameters
[in]dataThe array with values to set.

Member Data Documentation

template<class fpType>
fpType algebra3d::Vector3< fpType >::data[3]
protected

The vector data.

template<class fpType>
fpType& algebra3d::Vector3< fpType >::x

Reference to the first element of data.

template<class fpType>
fpType& algebra3d::Vector3< fpType >::y

Reference to the second element of data.

template<class fpType>
fpType& algebra3d::Vector3< fpType >::z

Reference to the third element of data.


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