Library of Assembled Shared Sources
lass::prim::Vector2D< T > Struct Template Reference

2D Vector More...

#include <vector_2d.h>

Inheritance diagram for lass::prim::Vector2D< T >:

Public Member Functions

Vector2D::TConstReference at (signed index) const
 Wrap index around range.
 
Vector2D::TReference at (signed index)
 Wrap index around range.
 
const Vector2D< T > & operator+ () const
 A weird way to get back the same object.
 
Vector2D< T > & operator+= (const Vector2D< T > &other)
 componentwise addition
 
Vector2D< T > & operator-= (const Vector2D< T > &other)
 componentwise subtraction
 
Vector2D< T > & operator*= (const Vector2D< T > &other)
 Componentwise multiplication.
 
Vector2D< T > & operator/= (const Vector2D< T > &other)
 Componentwise division.
 
Vector2D< T > & operator+= (TParam other)
 add other to each component of this.
 
Vector2D< T > & operator-= (TParam other)
 subtract other of each component of this.
 
Vector2D< T > & operator*= (TParam other)
 multiply each component of this with other.
 
Vector2D< T > & operator/= (TParam other)
 divide each component of this by other.
 
bool isZero () const
 Return true if all the components are (exactly!) zero.
 
bool isNaN () const
 Return true if at least one of the components is NaN.
 
const TValue squaredNorm () const
 Return squared norm of vector.
 
const TValue norm () const
 Return norm of vector.
 
const Vector2D< T > normal () const
 return a unit vector with same direction/sense as this vector.
 
const Vector2D< T > reciprocal () const
 return the reciprocal version of this vector
 
const Vector2D< T > perp () const
 return the vector perpendicular to this one, 90° CCW (to the left).
 
const Vector2D< T > project (const Vector2D< T > &other) const
 Project vector on this one.
 
const Vector2D< T > reject (const Vector2D< T > &other) const
 Project vector on this one.
 
const Vector2D< T > transform (T(*iOperator)(T)) const
 apply a function to every component
 
void normalize ()
 Normalize vector.
 

Static Public Member Functions

template<class RandomGenerator>
static Vector2D< T > random (RandomGenerator &generator)
 Random unit vector.
 

Related Symbols

(Note that these are not member symbols.)

template<typename T>
Vector2D< T >::TValue dot (const Vector2D< T > &a, const Vector2D< T > &b)
 dot product.
 
template<typename T>
Vector2D< T >::TValue cos (const Vector2D< T > &a, const Vector2D< T > &b)
 returns cosine of angle between both vectors.
 
template<typename T>
Vector2D< T >::TValue perpDot (const Vector2D< T > &a, const Vector2D< T > &b)
 perp dot product (cross product for 2D vectors).
 
template<typename T>
Vector2D< T > operator+ (const Vector2D< T > &a, const Vector2D< T > &b)
 componentwise addition
 
template<typename T>
Vector2D< T > operator- (const Vector2D< T > &a, const Vector2D< T > &b)
 componentwise subtraction
 
template<typename T>
Vector2D< T > operator* (const Vector2D< T > &a, const Vector2D< T > &b)
 Componentwise multiplication.
 
template<typename T>
Vector2D< T > operator/ (const Vector2D< T > &a, const Vector2D< T > &b)
 Componentwise division.
 
template<typename T>
Vector2D< T > operator+ (const Vector2D< T > &a, typename Vector2D< T >::TParam b)
 add b to all components of a.
 
template<typename T>
Vector2D< T > operator- (const Vector2D< T > &a, typename Vector2D< T >::TParam b)
 subtract b of all components of a.
 
template<typename T>
Vector2D< T > operator* (const Vector2D< T > &a, typename Vector2D< T >::TParam b)
 muliply all components of a by b
 
template<typename T>
Vector2D< T > operator/ (const Vector2D< T > &a, typename Vector2D< T >::TParam b)
 divide all components of a by b
 
template<typename T>
Vector2D< T > operator+ (typename Vector2D< T >::TParam a, const Vector2D< T > &b)
 add a to all components of b
 
template<typename T>
Vector2D< T > operator- (typename Vector2D< T >::TParam a, const Vector2D< T > &b)
 subtract a of all components of b
 
template<typename T>
Vector2D< T > operator* (typename Vector2D< T >::TParam a, const Vector2D< T > &b)
 multiply all components of b with a
 
template<typename T>
Vector2D< T > pointwiseMin (const Vector2D< T > &a, const Vector2D< T > &b)
 return a vector with, for each coordinate, the minimum value of a and b
 
template<typename T>
Vector2D< T > pointwiseMax (const Vector2D< T > &a, const Vector2D< T > &b)
 return a vector with, for each coordinate, the maximum value of a and b
 
template<typename T>
Vector2D< T > lerp (const Vector2D< T > &a, const Vector2D< T > &b, typename Vector2D< T >::TParam t)
 interpolate linearly between two vectors: a + t * (b - a)
 

Detailed Description

template<typename T>
struct lass::prim::Vector2D< T >

2D Vector

Author
BdG
Date
2003

Definition at line 71 of file vector_2d.h.

Member Function Documentation

◆ normal()

template<typename T>
const Vector2D< T > lass::prim::Vector2D< T >::normal ( ) const

return a unit vector with same direction/sense as this vector.

The normalized vector of X is a vector in the same direction but with norm (length) 1. It is denoted X^ and given by X^ = X / |X|, http://mathworld.wolfram.com/NormalizedVector.html.

Definition at line 299 of file vector_2d.inl.

References normal(), and normalize().

Referenced by normal().

Friends And Related Symbol Documentation

◆ perpDot()

template<typename T>
Vector2D< T >::TValue perpDot ( const Vector2D< T > & a,
const Vector2D< T > & b )
related

perp dot product (cross product for 2D vectors).

The "perp dot product" for a and b vectors in the plane is a modification of the two-dimensional dot product in which a is replaced by the perpendicular vector rotated 90° to the left defined by Hill (1994), http://mathworld.wolfram.com/PerpDotProduct.html.

It reminds a lot to the 3D cross product, as its result is equal to the z-value of the cross product of a and b extended to 3D space by setting their z-value to 0: Vector3D<T> c = cross(Vector3D<T>(a.x, a.y, 0), Vector3D<T>(b.x, b.y, 0)). We know of this that c.x and c.y are both zero, and that c.z equals the perp dot product between a and b.

Definition at line 429 of file vector_2d.inl.


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