QSDK 1.1 Documentation
Main Page | Modules | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members | Related Pages

Maths::Vec2< T > Struct Template Reference
[Vectors]

A two-element vector template. More...

#include <Q/maths.h>

List of all members.

Public Member Functions

 Vec2 ()
 Create a new uninitialised vector.

 Vec2 (const Vec2 &v)
 Create a copy of an existing vector.

 Vec2 (T tx, T ty)
 Create a vector from two existing values.

 Vec2 (T val)
 Create a vector with both elements initialised to the same value.

 Vec2 (const Vec3< T > &v)
 Convert a three element vector to a new two element vector.

 Vec2 (const Vec4< T > &v)
 Convert a four element vector to a new two element vector.

T & operator[] (unsigned int i)
 Return a reference to some element of the vector.

const T & operator[] (unsigned int i) const
 Return a reference to some element of the vector.

Vec2 operator- () const
 Negate each element of the vector.

bool isZero () const
 Test the value of a vector.

bool equals (const Vec2 &v, float e=Epsilon) const
 Compare two vectors.

void normalize ()
 Normalise the vector.

void zero ()
 Zero a vector.

Vec2negate ()
 Negate a vector.

Vec2product (const Vec2 &v, float s)
 Calculate the product of a vector and a floating point value.

modulus ()
 Calculate the length of a vector.

dot (const Vec2 &b) const
 Calculate the inner product of two vectors.


Static Public Member Functions

const Vec2origin ()
 The vector representing the origin.

const Vec2xAxis ()
 The vector representing the X axis.

const Vec2yAxis ()
 The vector representing the Y axis.


Public Attributes

x
 The first element of the vector.

y
 The second element of the vector.


Friends

Vec2 operator+ (const Vec2 &v1, const Vec2 &v2)
 Calculate the sum of two vectors.

Vec2 operator- (const Vec2 &v1, const Vec2 &v2)
 Calculate the difference of two vectors.

Vec2 operator * (const Vec2 &v1, const Vec2 &v2)
 Calculate the elementwise product of two vectors.

Vec2 operator * (const Vec2 &v, T s)
 Calculate a scalar multiple of a vector.

Vec2 operator * (T s, const Vec2 &v)
 Calculate a scalar multiple of a vector.

Vec2 operator/ (const Vec2 &v1, const Vec2 &v2)
 Calculate the quotient of two vectors.

Vec2 operator/ (const Vec2 &v, T s)
 Calculate a scalar quotient of a vector.

Vec2 operator/ (T s, const Vec2 &v)
 Calculate a scalar quotient of a vector.

Vec2operator+= (Vec2 &a, const Vec2 &s)
 Calculate the sum of two vectors.

Vec2operator-= (Vec2 &a, const Vec2 &s)
 Calculate the difference of two vectors.

Vec2operator *= (Vec2 &a, const Vec2 &s)
 Calculate the elementwise product of two vectors.

Vec2operator *= (Vec2 &a, T s)
 Calculate the scalar product of two vectors.

Vec2operator/= (Vec2 &a, const Vec2 &v)
 Calculate the quotient of two vectors.

Vec2operator/= (Vec2 &a, T s)
 Calculate a scalar quotient of a vector.

bool operator== (const Vec2 &v1, const Vec2 &v2)
 Compare two vectors.

bool operator!= (const Vec2 &v1, const Vec2 &v2)
 Compare two vectors.

cross (const Vec2 &v1, const Vec2 &v2)
 Calculate the cross (or outer) product of two vectors.

dot (const Vec2 &v1, const Vec2 &v2)
 Calculate the inner product of two vectors.


Detailed Description

template<class T>
struct Maths::Vec2< T >

A two-element vector template.

Instantiate this template using an arithmetic type of the required precision. Various common types of two element vectors are pre-defined as templates (e.g. Vec2f, Vec2d, Vec2i).


Constructor & Destructor Documentation

template<class T>
Maths::Vec2< T >::Vec2 const Vec3< T > &  v  )  [inline, explicit]
 

Convert a three element vector to a new two element vector.

The two elements of the new vector are initialised to the first two elements of the existing vector

template<class T>
Maths::Vec2< T >::Vec2 const Vec4< T > &  v  )  [inline, explicit]
 

Convert a four element vector to a new two element vector.

The two elements of the new vector are initialised to the first two elements of the existing vector divided by its fourth element


Member Function Documentation

template<class T>
T Maths::Vec2< T >::dot const Vec2< T > &  b  )  const [inline]
 

Calculate the inner product of two vectors.

Returns:
A value which is the product of the lengths of the two vectors and the cosine of the angle between them

template<class T>
bool Maths::Vec2< T >::equals const Vec2< T > &  v,
float  e = Epsilon
const [inline]
 

Compare two vectors.

Return values:
true if the absolute difference between each corresponding pair of element of the two vectors is less than e
false otherwise

template<class T>
bool Maths::Vec2< T >::isZero  )  const [inline]
 

Test the value of a vector.

Return values:
true if both elements of the vector are zero.
false otherwise

template<class T>
T Maths::Vec2< T >::modulus  ) 
 

Calculate the length of a vector.

Returns:
The square root of the sum of the squares of each element of the vector

template<class T>
Vec2< T > & Maths::Vec2< T >::negate  )  [inline]
 

Negate a vector.

Negate each element of the vector.

Returns:
A reference to this vector

template<class T>
void Maths::Vec2< T >::normalize  ) 
 

Normalise the vector.

Normalise the vector by dividing each element by the vector's modulus.

See also:
Vec2::modulus.

template<class T>
Vec2 Maths::Vec2< T >::operator-  )  const [inline]
 

Negate each element of the vector.

See also:
negate

template<class T>
const T& Maths::Vec2< T >::operator[] unsigned int  i  )  const [inline]
 

Return a reference to some element of the vector.

Parameters:
i The index of the required element, ranging from zero to one.

template<class T>
T& Maths::Vec2< T >::operator[] unsigned int  i  )  [inline]
 

Return a reference to some element of the vector.

Parameters:
i The index of the required element, ranging from zero to one.

template<class T>
const Vec2< T > & Maths::Vec2< T >::origin  )  [inline, static]
 

The vector representing the origin.

Returns:
A vector with all elements set to zero

template<class T>
Vec2< T > & Maths::Vec2< T >::product const Vec2< T > &  v,
float  s
 

Calculate the product of a vector and a floating point value.

Set each element of this vector to the product of the corresponding element of v and s.

Returns:
A reference to this vector

template<class T>
const Vec2< T > & Maths::Vec2< T >::xAxis  )  [inline, static]
 

The vector representing the X axis.

Returns:
A vector with the first element set to one and all other elements set to zero

template<class T>
const Vec2< T > & Maths::Vec2< T >::yAxis  )  [inline, static]
 

The vector representing the Y axis.

Returns:
A vector with the second element set to one and all other elements set to zero

template<class T>
void Maths::Vec2< T >::zero  ) 
 

Zero a vector.

Set each element of the vector to zero.


Friends And Related Function Documentation

template<class T>
T cross const Vec2< T > &  v1,
const Vec2< T > &  v2
[friend]
 

Calculate the cross (or outer) product of two vectors.

Returns:
A vector which is normal to both v1 and v2, scaled by the product of the lengths of both v1 and v2 and the sine of the angle between them.

template<class T>
T dot const Vec2< T > &  v1,
const Vec2< T > &  v2
[friend]
 

Calculate the inner product of two vectors.

Returns:
A value which is the product of the lengths of the two vectors and the cosine of the angle between them

template<class T>
Vec2 operator * s,
const Vec2< T > &  v
[friend]
 

Calculate a scalar multiple of a vector.

Returns:
A new vector where each element is set to the product of the corresponding elements of v and s

template<class T>
Vec2 operator * const Vec2< T > &  v,
s
[friend]
 

Calculate a scalar multiple of a vector.

Returns:
A new vector where each element is set to the product of the corresponding elements of v and s

template<class T>
Vec2 operator * const Vec2< T > &  v1,
const Vec2< T > &  v2
[friend]
 

Calculate the elementwise product of two vectors.

Returns:
A new vector where each element is set to the product of the corresponding elements of v1 and v2

template<class T>
Vec2& operator *= Vec2< T > &  a,
s
[friend]
 

Calculate the scalar product of two vectors.

Set the value of each element of a to the product of the corresponding elements of a and s.

Returns:
A reference to a

template<class T>
Vec2& operator *= Vec2< T > &  a,
const Vec2< T > &  s
[friend]
 

Calculate the elementwise product of two vectors.

Set the value of each element of a to the product of the corresponding elements of a and s.

Returns:
A reference to a

template<class T>
bool operator!= const Vec2< T > &  v1,
const Vec2< T > &  v2
[friend]
 

Compare two vectors.

Return values:
true if the two vectors are not equal
false otherwise

template<class T>
Vec2 operator+ const Vec2< T > &  v1,
const Vec2< T > &  v2
[friend]
 

Calculate the sum of two vectors.

Returns:
A new vector where each element is set to the sum of the corresponding elements of v1 and v2

template<class T>
Vec2& operator+= Vec2< T > &  a,
const Vec2< T > &  s
[friend]
 

Calculate the sum of two vectors.

Set the value of each element of a to the sum of the corresponding elements of a and s.

Returns:
A reference to a

template<class T>
Vec2 operator- const Vec2< T > &  v1,
const Vec2< T > &  v2
[friend]
 

Calculate the difference of two vectors.

Returns:
A new vector where each element is set to the difference of the corresponding elements of v1 and v2

template<class T>
Vec2& operator-= Vec2< T > &  a,
const Vec2< T > &  s
[friend]
 

Calculate the difference of two vectors.

Set the value of each element of a to the sum of the corresponding elements of a and s.

Returns:
A reference to a

template<class T>
Vec2 operator/ s,
const Vec2< T > &  v
[friend]
 

Calculate a scalar quotient of a vector.

Returns:
A new vector where each element is set to quotient of s and the corresponding element of v

template<class T>
Vec2 operator/ const Vec2< T > &  v,
s
[friend]
 

Calculate a scalar quotient of a vector.

Returns:
A new vector where each element is set to the quotient of the corresponding element of v and s

template<class T>
Vec2 operator/ const Vec2< T > &  v1,
const Vec2< T > &  v2
[friend]
 

Calculate the quotient of two vectors.

Returns:
A new vector where each element is set to the quotient of the corresponding elements of v1 and v2

template<class T>
Vec2& operator/= Vec2< T > &  a,
s
[friend]
 

Calculate a scalar quotient of a vector.

Set the value of each element of the vector to the quotient of the corresponding elements of a and s.

Returns:
A reference to a

template<class T>
Vec2& operator/= Vec2< T > &  a,
const Vec2< T > &  v
[friend]
 

Calculate the quotient of two vectors.

Set the value of each element of the vector to the quotient of the corresponding elements of a and v.

Returns:
A reference to a

template<class T>
bool operator== const Vec2< T > &  v1,
const Vec2< T > &  v2
[friend]
 

Compare two vectors.

Return values:
true if the two vectors are equal
false otherwise

Return to QSDK documentation Contents page. Contact details for support, information and fault-reporting.
Qube Software Limited © 2000-2004