3rd Eye Scene C#
3rd Eye Scene C# documentation
Tes::Maths::Quaternion Struct Reference

A quaternion implementation for applying 3D rotations. More...

List of all members.

Public Member Functions

 Quaternion (float x, float y, float z, float w)
 Initialise a quaternion with the given component values.
 Quaternion (Vector3 axis, float angle)
 Initialise a quaternion using an axis and an angle.
void SetFromTo (Vector3 from, Vector3 to)
 Initialise this quaternion as the rotation between from and to .
void GetAxisAngle (ref Vector3 axis, ref float angle)
 Converts this quaternion into a axis of rotation and the rotation angle around that axis (radians).
void SetAxisAngle (Vector3 axis, float angle)
 Sets this quaternion from an axis of rotation and the angle of rotation about that axis (radians).
void Invert ()
 Inverts this quaternion so that it expresses the counter rotation to its current value.
void Conjugate ()
 Sets this quaternion to its conjugate.
float Normalise (float epsilon=Epsilon)
 Attempts to normalise this quaternion.
float Dot (Quaternion other)
 Calculates the dot product of

this

and other .

Vector3 Transform (Vector3 v)
 Transforms v by this quaternion rotation.
void Multiply (float scalar)
 Multiply all components of this quaternion by a scalar.
override bool Equals (object obj)
 Compare two quaternions for precise numeric equality.
override int GetHashCode ()
 Generates a simple hash code for the quaternion.

Static Public Member Functions

static Quaternion FromTo (Vector3 from, Vector3 to)
 Static method for constructing a quaternion as a rotation between from and to .
static Quaternion AxisAngle (Vector3 axis, float angle)
 Creates a quaternion from an axis an angle.
static Quaternion Slerp (Quaternion from, Quaternion to, float t)
 Performs a spherical linear interpolation of one quaternion to another.
static bool operator== (Quaternion a, Quaternion b)
 Compare two quaternions for precise numeric equality.
static bool operator!= (Quaternion a, Quaternion b)
 Compare two quaternions for inequality using precise numeric equality.
static Quaternion operator* (Quaternion a, Quaternion b)
 Transform (rotate) one quaternion by another.
static Vector3 operator* (Quaternion q, Vector3 v)
 Transform (rotate) a vector by a quaternion.
static Quaternion operator* (Quaternion q, float s)
 Multiply a quaternion by a scalar.
static Quaternion operator* (float s, Quaternion q)
 Multiply a quaternion by a scalar.
static Quaternion operator/ (Quaternion q, float s)
 Divide a quaternion by a scalar.

Public Attributes

const float Epsilon = 1e-6f
 Default epsilon value used in various calculations.

Static Public Attributes

static Quaternion Identity = new Quaternion { X = 0, Y = 0, Z = 0, W = 1 }
 The identity quaternion (0, 0, 0, 1).
static Quaternion Zero = new Quaternion { X = 0, Y = 0, Z = 0, W = 0 }
 A zero quaternion (0, 0, 0, 0).

Properties

float X [get, set]
 The quaternion X component.
float Y [get, set]
 The quaternion Y component.
float Z [get, set]
 The quaternion Z component.
float W [get, set]
 The quaternion W component.
float this[int index] [get, set]
 Indexing accessor.
bool IsZero [get]
 Is this quaternion exactly zero (0, 0, 0, 0)?
bool IsIdentity [get]
 Is this quaternion exactly identity (0, 0, 0, 1)?
float Magnitude [get]
 Returns the magnitude of this quaternion.
float MagnitudeSquared [get]
 Returns the magnitude squared of this quaternion.
Quaternion Inverse [get]
 Calculates and returns the inverse, or counter rotation, of this quaternion.
Quaternion Conjugated [get]
 Calculates and returns the conjugate of this quaternion.
Quaternion normalised [get]
 Returns a normalised copy of this quaternion.

Detailed Description

A quaternion implementation for applying 3D rotations.

See Wikipedia or Wolfram MathWorld for technical details on quaternions.

Note that all angles expressed by this class are in radians.


Constructor & Destructor Documentation

Tes::Maths::Quaternion::Quaternion ( float  x,
float  y,
float  z,
float  w 
) [inline]

Initialise a quaternion with the given component values.

Parameters:
xX component value.
yY component value.
zZ component value.
wW component value.
Tes::Maths::Quaternion::Quaternion ( Vector3  axis,
float  angle 
) [inline]

Initialise a quaternion using an axis and an angle.

Parameters:
axisThe quaternion rotation axis. Must be a unity vector for well defined behaviour.
angleThe rotation angle around axis (radians).

Member Function Documentation

static Quaternion Tes::Maths::Quaternion::AxisAngle ( Vector3  axis,
float  angle 
) [inline, static]

Creates a quaternion from an axis an angle.

This provides a static alternative to SetAxisAngle(Vector3, float).

Parameters:
axisThe axis of rotation. Must be a unit vector.
angleThe rotation angle around axis (radians).
Returns:
The quaternion expressing the desired axis rotation.
void Tes::Maths::Quaternion::Conjugate ( ) [inline]

Sets this quaternion to its conjugate.

The conjugate is the same quaternion with x, y, z values negated, but w remains as is.

float Tes::Maths::Quaternion::Dot ( Quaternion  other) [inline]

Calculates the dot product of

this

and other .

Returns:
The dot product.
override bool Tes::Maths::Quaternion::Equals ( object  obj) [inline]

Compare two quaternions for precise numeric equality.

Parameters:
objThe quaternion to compare to.
Returns:
True if the quaternions are precisely equal.
Exceptions:
InvalidCastExceptionWhen obj is not a Quaternion.
static Quaternion Tes::Maths::Quaternion::FromTo ( Vector3  from,
Vector3  to 
) [inline, static]

Static method for constructing a quaternion as a rotation between from and to .

Parameters:
fromThe vector to rotate from. Should ideally be normalised.
toThe vector to rotate to. Should ideally be normalised.
Returns:
The rotation quaternion between the given vectors.
void Tes::Maths::Quaternion::GetAxisAngle ( ref Vector3  axis,
ref float  angle 
) [inline]

Converts this quaternion into a axis of rotation and the rotation angle around that axis (radians).

Parameters:
angleSet to the rotation angle (radians). Zero if this quaternion is identity.
axisSet to the axis of rotation. Set to (0, 0, 1) if this quaternion is identity or near zero length.
override int Tes::Maths::Quaternion::GetHashCode ( ) [inline]

Generates a simple hash code for the quaternion.

Not a very good hash.

Returns:
The hash code for this quaternion.
void Tes::Maths::Quaternion::Multiply ( float  scalar) [inline]

Multiply all components of this quaternion by a scalar.

Generally not a very useful operation for a quaternion as quaternions should stay normalised.

Parameters:
scalarThe scalar to multiply the vector components by.
float Tes::Maths::Quaternion::Normalise ( float  epsilon = Epsilon) [inline]

Attempts to normalise this quaternion.

Normalisation fails if the length of this quaternion is less than or equal to epsilon . In this case, the quaternion becomes identity.

Returns:
The magnitude of this quaternion before normalisation or zero if normalisation failed.
static bool Tes::Maths::Quaternion::operator!= ( Quaternion  a,
Quaternion  b 
) [inline, static]

Compare two quaternions for inequality using precise numeric equality.

Parameters:
aA quaternion to compare.
bA quaternion to compare.
Returns:
True if the quaternions are not precisely equal.
static Vector3 Tes::Maths::Quaternion::operator* ( Quaternion  q,
Vector3  v 
) [inline, static]

Transform (rotate) a vector by a quaternion.

Parameters:
qThe quaternion to rotate by.
vThe vector to rotate.
Returns:
The vector v rotated by q .
static Quaternion Tes::Maths::Quaternion::operator* ( float  s,
Quaternion  q 
) [inline, static]

Multiply a quaternion by a scalar.

Not a very useful operation for a quaternion as they should stay normalised. Provided for completeness.

Parameters:
sThe scalar to multiply by.
qThe quaternion to operate on.
Returns:
The scaled quaternion.
static Quaternion Tes::Maths::Quaternion::operator* ( Quaternion  a,
Quaternion  b 
) [inline, static]

Transform (rotate) one quaternion by another.

The resulting quaternion represents a combined rotation, applying b then a .

Parameters:
aThe quaternion to rotate by.
bThe quaternion to rotate
Returns:
The quaternion a rotated by b .
static Quaternion Tes::Maths::Quaternion::operator* ( Quaternion  q,
float  s 
) [inline, static]

Multiply a quaternion by a scalar.

Not a very useful operation for a quaternion as they should stay normalised. Provided for completeness.

Parameters:
qThe quaternion to operate on.
sThe scalar to multiply by.
Returns:
The scaled quaternion.
static Quaternion Tes::Maths::Quaternion::operator/ ( Quaternion  q,
float  s 
) [inline, static]

Divide a quaternion by a scalar.

Not a very useful operation for a quaternion as they should stay normalised. Provided for completeness.

Parameters:
qThe quaternion to operate on.
sThe scalar to divide by.
Returns:
The scaled quaternion.
static bool Tes::Maths::Quaternion::operator== ( Quaternion  a,
Quaternion  b 
) [inline, static]

Compare two quaternions for precise numeric equality.

Parameters:
aA quaternion to compare.
bA quaternion to compare.
Returns:
True if the quaternions are precisely equal.
void Tes::Maths::Quaternion::SetAxisAngle ( Vector3  axis,
float  angle 
) [inline]

Sets this quaternion from an axis of rotation and the angle of rotation about that axis (radians).

Parameters:
axisThe axis of rotation. Must be a unit vector.
angleThe rotation angle around axis (radians).
void Tes::Maths::Quaternion::SetFromTo ( Vector3  from,
Vector3  to 
) [inline]

Initialise this quaternion as the rotation between from and to .

Parameters:
fromThe vector to rotate from. Should ideally be normalised.
toThe vector to rotate to. Should ideally be normalised.
static Quaternion Tes::Maths::Quaternion::Slerp ( Quaternion  from,
Quaternion  to,
float  t 
) [inline, static]

Performs a spherical linear interpolation of one quaternion to another.

This results in a quaternion which rotates partway between from and to .

This is an ambiguity in rotation when from and to are exactly opposed and the resulting quaternion is not well defined.

Parameters:
fromThe quaternion rotation to interpolate from.
toThe quaternion rotation to interpolate to.
tThe interpolation "time", [0, 1]. Zero selects from while one selects to .
Returns:
The interpolated result.
Vector3 Tes::Maths::Quaternion::Transform ( Vector3  v) [inline]

Transforms v by this quaternion rotation.

The transformation signifies a rotation of v by this quaternion.

Returns:
The transformed vector.

Property Documentation

Quaternion Tes::Maths::Quaternion::Conjugated [get]

Calculates and returns the conjugate of this quaternion.

The conjugate is the same quaternion with x, y, z values negated, but w remains as is.

Returns:
This quaternion's conjugate.
Quaternion Tes::Maths::Quaternion::Inverse [get]

Calculates and returns the inverse, or counter rotation, of this quaternion.

Returns:
The inverse of this quaternion.
bool Tes::Maths::Quaternion::IsIdentity [get]

Is this quaternion exactly identity (0, 0, 0, 1)?

bool Tes::Maths::Quaternion::IsZero [get]

Is this quaternion exactly zero (0, 0, 0, 0)?

Quaternion Tes::Maths::Quaternion::normalised [get]

Returns a normalised copy of this quaternion.

Normalisation fails if the length of this quaternion is less than or equal to epsilon.

Returns:
A normalised copy of this quaternion, or a zero quaternion if if normalisation failed.
float Tes::Maths::Quaternion::this[int index] [get, set]

Indexing accessor.

Indexes X, Y, Z, W across the range [0, 3].

Parameters:
indexThe component index [0, 3].
Returns:
The requested component.
Exceptions:
IndexOutOfRangeExceptionThrown when index is out of range.

The documentation for this struct was generated from the following file:
 All Classes Namespaces Functions Variables Enumerations Properties Events