ParM  parm
A molecular dynamics library
Public Member Functions | Static Public Member Functions | Friends | List of all members
Vector2< T > Class Template Reference

A 2D physics vector, with methods for adding, subtracting, dot product, etc. More...

#include <vec.hpp>

Inheritance diagram for Vector2< T >:
NumVector< T, 2 > NVector< T, N >

Public Member Functions

 Vector2 ()
 
 Vector2 (const T a, const T b)
 
 Vector2 (const NumVector< T, 2 > rhs)
 
 Vector2 (const NVector< T, 2 > rhs)
 
const T getx () const
 
const T gety () const
 
double getxd () const
 
double getyd () const
 
void setx (const T a)
 
void sety (const T b)
 
void setxd (const double a)
 
void setyd (const double b)
 
void set (const T a, const T b)
 
Vector2 operator- () const
 
Vector2 operator+ (const Vector2 &rhs) const
 
Vector2 operator- (const Vector2 &rhs) const
 
operator* (const Vector2 &rhs) const
 
template<class U >
Vector2 operator* (const U rhs) const
 
template<class U >
Vector2 operator/ (const U rhs) const
 
cross (const Vector2 &rhs) const
 The 2D cross product, returning a scalar. More...
 
Vector2 cross (const T v) const
 The 2D cross product with the "missing" third dimension, returning a vector. More...
 
Vector2 perp () const
 The vector perpendicular to this one, in the clockwise direction. More...
 
Vector2 norm () const
 The normalized version of this vector. More...
 
Vector2operator-= (const Vector2 &rhs)
 
Vector2operator+= (const Vector2 &rhs)
 
template<class U >
Vector2operator*= (const U rhs)
 
template<class U >
Vector2operator/= (const U rhs)
 
Vector2 rotate (uint i)
 Rotate by 90 degrees counter-clockwise. More...
 
Vector2 flip ()
 
Vector2 rotate_flip (uint i)
 Rotate and flip, for \(0 \le i < 8 \). More...
 
Vector2 rotate_flip_inv (uint i)
 The inverse of rotate_flip(i). More...
 
 ~Vector2 ()
 
template<class U >
Vector2< T > & operator*= (const U rhs)
 
template<class U >
Vector2< T > & operator/= (const U rhs)
 
- Public Member Functions inherited from NumVector< T, 2 >
 NumVector ()
 
 NumVector (const NVector< T, N > &rhs)
 
 NumVector (const T rhs[N])
 
dot (const NumVector &other) const
 Inner product. More...
 
sq () const
 
mag () const
 The square of the vector, \(\vec r^2 \). More...
 
distance (const NumVector &rhs) const
 The magnitude of the vector, \( \left| \vec r \right| \). More...
 
NumVector perpto (const NumVector &other) const
 
void normalize ()
 Normalize in place. More...
 
NumVector norm () const
 Return the normalized version. More...
 
 ~NumVector ()
 
- Public Member Functions inherited from NVector< T, N >
 NVector ()
 
 NVector (const NVector &rhs)
 
template<class U >
 NVector (const NVector< U, N > &rhs)
 
 NVector (const T locs[N])
 
const T & get (const unsigned int n) const
 
void set (const unsigned int n, const T a)
 
unsigned int len () const
 
NVectoroperator+= (const NVector &rhs)
 
NVectoroperator-= (const NVector &rhs)
 
template<class U >
NVectoroperator*= (const U rhs)
 
template<class U >
NVectoroperator/= (const U rhs)
 
NVector operator- () const
 
NVector operator+ (const NVector &rhs) const
 
NVector operator- (const NVector &rhs) const
 
T & operator[] (const unsigned int i)
 
const T & operator[] (const unsigned int i) const
 
template<class U >
NVector operator* (const U rhs) const
 Multiplication by a scalar. More...
 
template<class U >
NVector operator/ (const U rhs) const
 Division by a scalar. More...
 
T * begin ()
 
T * end ()
 
 ~NVector ()
 
template<class U >
NVector< T, N > & operator*= (const U rhs)
 
template<class U >
NVector< T, N > & operator/= (const U rhs)
 

Static Public Member Functions

static T angle (const Vector2 &dx1, const Vector2 &dx2)
 The angle between two vectors, assuming they start at the same point (i.e. the origin). More...
 
static T angle (const Vector2 &x1, const Vector2 &x2, const Vector2 &x3)
 The angle between three points. More...
 

Friends

template<class U >
ostream & operator<< (ostream &out, const Vector2< U > v)
 

Additional Inherited Members

- Public Types inherited from NVector< T, N >
typedef T * iterator
 
- Protected Attributes inherited from NVector< T, N >
vals [N]
 

Detailed Description

template<class T>
class Vector2< T >

A 2D physics vector, with methods for adding, subtracting, dot product, etc.

This is aliased as Vec when compiled with NDIM=2.

Template Parameters
Ta numerical type, as as float or double.

Constructor & Destructor Documentation

template<class T >
Vector2< T >::Vector2 ( )
inline
template<class T >
Vector2< T >::Vector2 ( const T  a,
const T  b 
)
inline
template<class T >
Vector2< T >::Vector2 ( const NumVector< T, 2 >  rhs)
inline
template<class T >
Vector2< T >::Vector2 ( const NVector< T, 2 >  rhs)
inline
template<class T >
Vector2< T >::~Vector2 ( )
inline

Member Function Documentation

template<class T >
static T Vector2< T >::angle ( const Vector2< T > &  dx1,
const Vector2< T > &  dx2 
)
inlinestatic

The angle between two vectors, assuming they start at the same point (i.e. the origin).

Equal to \(\theta = \arccos \left(\frac{\vec x_1 \cdot \vec x_2}{\left| \vec x_1 \right| \left| \vec x_2 \right|}\right) \)

Parameters
dx1\(\vec x_1 \)
dx2\(\vec x_2 \)
template<class T >
static T Vector2< T >::angle ( const Vector2< T > &  x1,
const Vector2< T > &  x2,
const Vector2< T > &  x3 
)
inlinestatic

The angle between three points.

Equivalent to angle(x1 - x2, x3 - x2).

Parameters
x1The first point.
x2The middle point, around which we are finding the angle.
x3The third point.
template<class T >
T Vector2< T >::cross ( const Vector2< T > &  rhs) const
inline

The 2D cross product, returning a scalar.

template<class T >
Vector2 Vector2< T >::cross ( const T  v) const
inline

The 2D cross product with the "missing" third dimension, returning a vector.

template<class T >
Vector2 Vector2< T >::flip ( )
inline
template<class T >
const T Vector2< T >::getx ( ) const
inline
template<class T >
double Vector2< T >::getxd ( ) const
inline
template<class T >
const T Vector2< T >::gety ( ) const
inline
template<class T >
double Vector2< T >::getyd ( ) const
inline
template<class T >
Vector2 Vector2< T >::norm ( ) const
inline

The normalized version of this vector.

template<class T >
T Vector2< T >::operator* ( const Vector2< T > &  rhs) const
inline
template<class T >
template<class U >
Vector2 Vector2< T >::operator* ( const U  rhs) const
inline
template<class T >
template<class U >
Vector2& Vector2< T >::operator*= ( const U  rhs)
template<class T >
template<class U >
Vector2<T>& Vector2< T >::operator*= ( const U  rhs)
template<class T >
Vector2 Vector2< T >::operator+ ( const Vector2< T > &  rhs) const
inline
template<class T >
Vector2& Vector2< T >::operator+= ( const Vector2< T > &  rhs)
inline
template<class T >
Vector2 Vector2< T >::operator- ( ) const
inline
template<class T >
Vector2 Vector2< T >::operator- ( const Vector2< T > &  rhs) const
inline
template<class T >
Vector2& Vector2< T >::operator-= ( const Vector2< T > &  rhs)
inline
template<class T >
template<class U >
Vector2 Vector2< T >::operator/ ( const U  rhs) const
inline
template<class T >
template<class U >
Vector2& Vector2< T >::operator/= ( const U  rhs)
template<class T >
template<class U >
Vector2<T>& Vector2< T >::operator/= ( const U  rhs)
template<class T >
Vector2 Vector2< T >::perp ( ) const
inline

The vector perpendicular to this one, in the clockwise direction.

template<class T >
Vector2< T > Vector2< T >::rotate ( uint  i)

Rotate by 90 degrees counter-clockwise.

Todo:
TODO: this direction is inconsistent with cross and perp.
template<class T >
Vector2 Vector2< T >::rotate_flip ( uint  i)
inline

Rotate and flip, for \(0 \le i < 8 \).

For \(0 \le i < 4 \), equivalent to rotate(i). For \(4 \le i < 8 \), equivalent to flip().rotate(i % 4). For \(i \ge 8 \), equivalent to rotate_flip(i % 8).

template<class T >
Vector2 Vector2< T >::rotate_flip_inv ( uint  i)
inline

The inverse of rotate_flip(i).

template<class T >
void Vector2< T >::set ( const T  a,
const T  b 
)
inline
template<class T >
void Vector2< T >::setx ( const T  a)
inline
template<class T >
void Vector2< T >::setxd ( const double  a)
inline
template<class T >
void Vector2< T >::sety ( const T  b)
inline
template<class T >
void Vector2< T >::setyd ( const double  b)
inline

Friends And Related Function Documentation

template<class T >
template<class U >
ostream& operator<< ( ostream &  out,
const Vector2< U >  v 
)
friend

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