A 3D Dynamic Geometry Software

Calques 3D C++



quaternion Class Reference

Inheritance diagram for quaternion:

Inheritance graph
Collaboration diagram for quaternion:

Collaboration graph

List of all members.


Detailed Description

A generic quaternion class. The quaternion uses internally the (s,v) representation, where s is a scalar and v a vector. The most common operations from quaternion calculus are implemented.

Some internet references are:

A paper by Ken Shoemake (the quaternions "inventor") is available at


Public Member Functions

 quaternion ()
 default constructor
 quaternion (const real &scal, const vector &vec)
 constructs a quaternion from the scalar and vector components
 quaternion (const real &s1, const real &s2, const real &s3, const real &s4)
 constructs a quaternion from four real values
 quaternion (const quaternion &other)
 the copy constructor
virtual ~quaternion ()
 the distructor
real & x ()
 accessor for the x component of the vector part (can be used as l-value too)
real & y ()
 accessor for the y component of the vector part (can be used as l-value too)
real & z ()
 accessor for the z component of the vector part (can be used as l-value too)
real & w ()
 accessor for the scalar part (can be used as l-value too)
real & scalarPart ()
 other accessor for the scalar component (can be used as l-value too)
vector & vectorPart ()
 accessor for the vector part (can be used as l-value too)
quaternion & operator= (const quaternion &other)
 assignment
quaternion & operator+= (const quaternion &other)
 sum & assign
quaternion & operator-= (const quaternion &other)
 subtract & assign
quaternion & operator *= (const quaternion &other)
 multiply by a quaternion & assign
quaternion & operator/= (const quaternion &other)
 divide by a quaternion & assign
quaternion & operator *= (const real &fact)
 multiply by a scalar factor & assign
quaternion & operator/= (const real &fact)
 divide by a scalar factor & assign
real normalize ()
 normalize the quaternion
quaternion normalized () const
 normalized copy of the quaternion
void conjugate ()
 conjugate of the quaternion
quaternion conjugated () const
 conjugated copy of the quaternion
real inverse ()
 inverse of the quaternion
quaternion inversed () const
 inversed copy of the quaternion
real length () const
 get the length of the quaternion
real norm () const
 get the norm (similar to the squared length) of the quaternion
virtual tmatrix getRotMatrix ()

Static Public Member Functions

static int howMany ()
 returns how many quaternion objects exists

Protected Attributes

real s
 the scalar part of a quaternion
vector v
 the vector part of a quaternion

Static Private Attributes

static int counter = 0
 counts how many quaternion objects are present

Friends

int operator== (const quaternion &q1, const quaternion &q2)
 the equality operator
int operator!= (const quaternion &q1, const quaternion &q2)
 the inequality operator
quaternion operator+ (const quaternion &q1, const quaternion &q2)
 the sum
quaternion operator- (const quaternion &q1, const quaternion &q2)
 the difference
quaternion operator- (const quaternion &q1)
 negation
quaternion operator * (const quaternion &q1, const quaternion &q2)
 quaternion product
quaternion operator * (const quaternion &q, const real &s)
 multiply a quaternion by a scalar
quaternion operator * (const real &s, const quaternion &q)
 multiply a scalar by a quaternion
quaternion operator/ (const quaternion &q, const real &s)
 divide a quaternion by a scalar factor
quaternion operator/ (const quaternion &q1, const quaternion &q2)
 divide a quaternion by a quaternion
ostream & operator<< (ostream &os, const quaternion &q)
 print quaternion to C++ stream

Constructor & Destructor Documentation

quaternion (  )  [inline]

default constructor

quaternion ( const real &  scal,
const vector &  vec 
) [inline]

constructs a quaternion from the scalar and vector components

quaternion ( const real &  s1,
const real &  s2,
const real &  s3,
const real &  s4 
) [inline]

constructs a quaternion from four real values

This constructor assumes an (s,v) form so interprets the real calues as w,x,y,z respectively. Another common representation for quaternions, the "homogeneous" one, is x,y,x,w ordered.

Parameters:
s1 the scalar part
s2 the x component of the vector part
s3 the y component of the vector part
s4 the z component of the vector part
Date:
15/06/99

quaternion ( const quaternion &  other  )  [inline]

the copy constructor

~quaternion (  )  [inline, virtual]

the distructor


Member Function Documentation

real & x (  )  [inline]

accessor for the x component of the vector part (can be used as l-value too)

real & y (  )  [inline]

accessor for the y component of the vector part (can be used as l-value too)

real & z (  )  [inline]

accessor for the z component of the vector part (can be used as l-value too)

real & w (  )  [inline]

accessor for the scalar part (can be used as l-value too)

real & scalarPart (  )  [inline]

other accessor for the scalar component (can be used as l-value too)

vector & vectorPart (  )  [inline]

accessor for the vector part (can be used as l-value too)

quaternion & operator= ( const quaternion &  other  )  [inline]

assignment

quaternion & operator+= ( const quaternion &  other  )  [inline]

sum & assign

quaternion & operator-= ( const quaternion &  other  )  [inline]

subtract & assign

quaternion & operator *= ( const quaternion &  other  ) 

multiply by a quaternion & assign

quaternion & operator/= ( const quaternion &  other  ) 

divide by a quaternion & assign

quaternion & operator *= ( const real &  fact  )  [inline]

multiply by a scalar factor & assign

Reimplemented in unitquaternion.

quaternion & operator/= ( const real &  fact  )  [inline]

divide by a scalar factor & assign

Reimplemented in unitquaternion.

real normalize (  ) 

normalize the quaternion

This function modifies the quaternion upon which has been called.

Returns:
the length of the quaternion before normalization, this is useful to check if the normalization operation has been numerically precise.

quaternion normalized (  )  const

normalized copy of the quaternion

This function doesn't modifies the quaternion upon which has been called, it returns a new quaternion instead.

Returns:
the normalized copy of the quaternion

void conjugate (  )  [inline]

conjugate of the quaternion

quaternion conjugated (  )  const [inline]

conjugated copy of the quaternion

real inverse (  ) 

inverse of the quaternion

This function modifies the quaternion upon which has been called.

Returns:
the norm of the quaternion before the internal normalization, this is useful to check if the normalization operation has been numerically precise.

Reimplemented in unitquaternion.

quaternion inversed (  )  const

inversed copy of the quaternion

This function doesn't modifies the quaternion upon which has been called, it returns a new quaternion instead.

Reimplemented in unitquaternion.

real length (  )  const [inline]

get the length of the quaternion

real norm (  )  const

get the norm (similar to the squared length) of the quaternion

NOTE: the norm is comparable to the squared length of a vector not to the length

tmatrix getRotMatrix (  )  [virtual]

Generates a rotation matrix even from non unit quaternions (only for unit quaternoin the result is the same as unitquaternion::getRotMatrix). The generated rotation matrix is OpenGL compatible, it is intended to be post-multiplied to the current trasformation matrix to achieve the rotation.

Returns:
the rotation matrix

Reimplemented in unitquaternion.

int howMany (  )  [inline, static]

returns how many quaternion objects exists

The counting of the quaternion objects is realized trough a static counter variable.

Returns:
the number of quaternion objects in memory


Friends And Related Function Documentation

int operator== ( const quaternion &  q1,
const quaternion &  q2 
) [friend]

the equality operator

This function check if two quaternions are equal.

int operator!= ( const quaternion &  q1,
const quaternion &  q2 
) [friend]

the inequality operator

This function check if two quaternions are not equal.

quaternion operator+ ( const quaternion &  q1,
const quaternion &  q2 
) [friend]

the sum

quaternion operator- ( const quaternion &  q1,
const quaternion &  q2 
) [friend]

the difference

quaternion operator- ( const quaternion &  q1  )  [friend]

negation

quaternion operator * ( const quaternion &  q1,
const quaternion &  q2 
) [friend]

quaternion product

quaternion operator * ( const quaternion &  q,
const real &  s 
) [friend]

multiply a quaternion by a scalar

This function together with operator*(real,quaternion) implements the commutative product of a scalar by a quaternion

quaternion operator * ( const real &  s,
const quaternion &  q 
) [friend]

multiply a scalar by a quaternion

This function together with operator*(quaternion,real) implements the commutative product of a scalar by a quaternion

quaternion operator/ ( const quaternion &  q,
const real &  s 
) [friend]

divide a quaternion by a scalar factor

quaternion operator/ ( const quaternion &  q1,
const quaternion &  q2 
) [friend]

divide a quaternion by a quaternion

ostream& operator<< ( ostream &  os,
const quaternion &  q 
) [friend]

print quaternion to C++ stream


Member Data Documentation

int counter = 0 [static, private]

counts how many quaternion objects are present

real s [protected]

the scalar part of a quaternion

vector v [protected]

the vector part of a quaternion