OpenTK.Quaterniond Struct Reference

Represents a double-precision Quaternion. More...

List of all members.

Public Member Functions

 Quaterniond (Vector3d v, double w)
 Construct a new Quaterniond from vector and w components.
 Quaterniond (double x, double y, double z, double w)
 Construct a new Quaterniond.
void ToAxisAngle (out Vector3d axis, out double angle)
 Convert the current quaternion to axis angle representation.
Vector4d ToAxisAngle ()
 Convert this instance to an axis-angle representation.
void Normalize ()
 Scales the Quaterniond to unit length.
void Conjugate ()
 Convert this Quaterniond to its conjugate.
override string ToString ()
 Returns a System.String that represents the current Quaterniond.
override bool Equals (object other)
 Compares this object instance to another object for equality.
override int GetHashCode ()
 Provides the hash code for this object.
bool Equals (Quaterniond other)
 Compares this Quaterniond instance to another Quaterniond for equality.

Static Public Member Functions

static Quaterniond Add (Quaterniond left, Quaterniond right)
 Add two quaternions.
static void Add (ref Quaterniond left, ref Quaterniond right, out Quaterniond result)
 Add two quaternions.
static Quaterniond Sub (Quaterniond left, Quaterniond right)
 Subtracts two instances.
static void Sub (ref Quaterniond left, ref Quaterniond right, out Quaterniond result)
 Subtracts two instances.
static Quaterniond Mult (Quaterniond left, Quaterniond right)
 Multiplies two instances.
static void Mult (ref Quaterniond left, ref Quaterniond right, out Quaterniond result)
 Multiplies two instances.
static Quaterniond Multiply (Quaterniond left, Quaterniond right)
 Multiplies two instances.
static void Multiply (ref Quaterniond left, ref Quaterniond right, out Quaterniond result)
 Multiplies two instances.
static void Multiply (ref Quaterniond quaternion, double scale, out Quaterniond result)
 Multiplies an instance by a scalar.
static Quaterniond Multiply (Quaterniond quaternion, double scale)
 Multiplies an instance by a scalar.
static Quaterniond Conjugate (Quaterniond q)
 Get the conjugate of the given Quaterniond.
static void Conjugate (ref Quaterniond q, out Quaterniond result)
 Get the conjugate of the given Quaterniond.
static Quaterniond Invert (Quaterniond q)
 Get the inverse of the given Quaterniond.
static void Invert (ref Quaterniond q, out Quaterniond result)
 Get the inverse of the given Quaterniond.
static Quaterniond Normalize (Quaterniond q)
 Scale the given Quaterniond to unit length.
static void Normalize (ref Quaterniond q, out Quaterniond result)
 Scale the given Quaterniond to unit length.
static Quaterniond FromAxisAngle (Vector3d axis, double angle)
 Build a Quaterniond from the given axis and angle.
static Quaterniond Slerp (Quaterniond q1, Quaterniond q2, double blend)
 Do Spherical linear interpolation between two quaternions.
static Quaterniond operator+ (Quaterniond left, Quaterniond right)
 Adds two instances.
static Quaterniond operator- (Quaterniond left, Quaterniond right)
 Subtracts two instances.
static Quaterniond operator* (Quaterniond left, Quaterniond right)
 Multiplies two instances.
static Quaterniond operator* (Quaterniond quaternion, double scale)
 Multiplies an instance by a scalar.
static Quaterniond operator* (double scale, Quaterniond quaternion)
 Multiplies an instance by a scalar.
static bool operator== (Quaterniond left, Quaterniond right)
 Compares two instances for equality.
static bool operator!= (Quaterniond left, Quaterniond right)
 Compares two instances for inequality.

Public Attributes

Vector3d xyz
double w

Static Public Attributes

static readonly Quaterniond Identity = new Quaterniond(0, 0, 0, 1)
 Defines the identity quaternion.

Properties

Vector3d XYZ [get, set]
 Gets or sets an OpenTK.Vector3d with the X, Y and Z components of this instance.
Vector3d Xyz [get, set]
 Gets or sets an OpenTK.Vector3d with the X, Y and Z components of this instance.
double X [get, set]
 Gets or sets the X component of this instance.
double Y [get, set]
 Gets or sets the Y component of this instance.
double Z [get, set]
 Gets or sets the Z component of this instance.
double W [get, set]
 Gets or sets the W component of this instance.
double Length [get]
 Gets the length (magnitude) of the Quaterniond.
double LengthSquared [get]
 Gets the square of the Quaterniond length (magnitude).

Detailed Description

Represents a double-precision Quaternion.

Definition at line 37 of file Quaterniond.cs.


Constructor & Destructor Documentation

OpenTK.Quaterniond.Quaterniond ( Vector3d  v,
double  w 
)

Construct a new Quaterniond from vector and w components.

Parameters:
v The vector part
w The w part

Definition at line 53 of file Quaterniond.cs.

00054         {
00055             this.xyz = v;
00056             this.w = w;
00057         }

OpenTK.Quaterniond.Quaterniond ( double  x,
double  y,
double  z,
double  w 
)

Construct a new Quaterniond.

Parameters:
x The x component
y The y component
z The z component
w The w component

Definition at line 66 of file Quaterniond.cs.

00067             : this(new Vector3d(x, y, z), w)
00068         { }


Member Function Documentation

static void OpenTK.Quaterniond.Add ( ref Quaterniond  left,
ref Quaterniond  right,
out Quaterniond  result 
) [static]

Add two quaternions.

Parameters:
left The first operand
right The second operand
result The result of the addition

Definition at line 252 of file Quaterniond.cs.

00253         {
00254             result = new Quaterniond(
00255                 left.Xyz + right.Xyz,
00256                 left.W + right.W);
00257         }

static Quaterniond OpenTK.Quaterniond.Add ( Quaterniond  left,
Quaterniond  right 
) [static]

Add two quaternions.

Parameters:
left The first operand
right The second operand
Returns:
The result of the addition

Definition at line 239 of file Quaterniond.cs.

00240         {
00241             return new Quaterniond(
00242                 left.Xyz + right.Xyz,
00243                 left.W + right.W);
00244         }

static void OpenTK.Quaterniond.Conjugate ( ref Quaterniond  q,
out Quaterniond  result 
) [static]

Get the conjugate of the given Quaterniond.

Parameters:
q The Quaterniond
result The conjugate of the given Quaterniond

Definition at line 388 of file Quaterniond.cs.

00389         {
00390             result = new Quaterniond(-q.Xyz, q.W);
00391         }

static Quaterniond OpenTK.Quaterniond.Conjugate ( Quaterniond  q  )  [static]

Get the conjugate of the given Quaterniond.

Parameters:
q The Quaterniond
Returns:
The conjugate of the given Quaterniond

Definition at line 378 of file Quaterniond.cs.

00379         {
00380             return new Quaterniond(-q.Xyz, q.W);
00381         }

void OpenTK.Quaterniond.Conjugate (  ) 

Convert this Quaterniond to its conjugate.

Definition at line 211 of file Quaterniond.cs.

00212         {
00213             Xyz = -Xyz;
00214         }

bool OpenTK.Quaterniond.Equals ( Quaterniond  other  ) 

Compares this Quaterniond instance to another Quaterniond for equality.

Parameters:
other The other Quaterniond to be used in the comparison.
Returns:
True if both instances are equal; false otherwise.

Definition at line 1317 of file Quaterniond.cs.

01318         {
01319             return Xyz == other.Xyz && W == other.W;
01320         }

override bool OpenTK.Quaterniond.Equals ( object  other  ) 

Compares this object instance to another object for equality.

Parameters:
other The other object to be used in the comparison.
Returns:
True if both objects are Quaternions of equal value. Otherwise it returns false.

Definition at line 660 of file Quaterniond.cs.

00661         {
00662             if (other is Quaterniond == false) return false;
00663             return this == (Quaterniond)other;
00664         }

static Quaterniond OpenTK.Quaterniond.FromAxisAngle ( Vector3d  axis,
double  angle 
) [static]

Build a Quaterniond from the given axis and angle.

Parameters:
axis The axis to rotate about
angle The rotation angle in radians
Returns:

Definition at line 465 of file Quaterniond.cs.

00466         {
00467             if (axis.LengthSquared == 0.0f)
00468                 return Identity;
00469 
00470             Quaterniond result = Identity;
00471 
00472             angle *= 0.5f;
00473             axis.Normalize();
00474             result.Xyz = axis * (double)System.Math.Sin(angle);
00475             result.W = (double)System.Math.Cos(angle);
00476 
00477             return Normalize(result);
00478         }

override int OpenTK.Quaterniond.GetHashCode (  ) 

Provides the hash code for this object.

Returns:
A hash code formed from the bitwise XOR of this objects members.

Definition at line 674 of file Quaterniond.cs.

00675         {
00676             return Xyz.GetHashCode() ^ W.GetHashCode();
00677         }

static void OpenTK.Quaterniond.Invert ( ref Quaterniond  q,
out Quaterniond  result 
) [static]

Get the inverse of the given Quaterniond.

Parameters:
q The Quaterniond to invert
result The inverse of the given Quaterniond

Definition at line 414 of file Quaterniond.cs.

00415         {
00416             double lengthSq = q.LengthSquared;
00417             if (lengthSq != 0.0)
00418             {
00419                 double i = 1.0f / lengthSq;
00420                 result = new Quaterniond(q.Xyz * -i, q.W * i);
00421             }
00422             else
00423             {
00424                 result = q;
00425             }
00426         }

static Quaterniond OpenTK.Quaterniond.Invert ( Quaterniond  q  )  [static]

Get the inverse of the given Quaterniond.

Parameters:
q The Quaterniond to invert
Returns:
The inverse of the given Quaterniond

Definition at line 402 of file Quaterniond.cs.

00403         {
00404             Quaterniond result;
00405             Invert(ref q, out result);
00406             return result;
00407         }

static void OpenTK.Quaterniond.Mult ( ref Quaterniond  left,
ref Quaterniond  right,
out Quaterniond  result 
) [static]

Multiplies two instances.

Parameters:
left The first instance.
right The second instance.
result A new instance containing the result of the calculation.

Definition at line 314 of file Quaterniond.cs.

00315         {
00316             result = new Quaterniond(
00317                 right.W * left.Xyz + left.W * right.Xyz + Vector3d.Cross(left.Xyz, right.Xyz),
00318                 left.W * right.W - Vector3d.Dot(left.Xyz, right.Xyz));
00319         }

static Quaterniond OpenTK.Quaterniond.Mult ( Quaterniond  left,
Quaterniond  right 
) [static]

Multiplies two instances.

Parameters:
left The first instance.
right The second instance.
Returns:
A new instance containing the result of the calculation.

Definition at line 300 of file Quaterniond.cs.

00301         {
00302             return new Quaterniond(
00303                 right.W * left.Xyz + left.W * right.Xyz + Vector3d.Cross(left.Xyz, right.Xyz),
00304                 left.W * right.W - Vector3d.Dot(left.Xyz, right.Xyz));
00305         }

static Quaterniond OpenTK.Quaterniond.Multiply ( Quaterniond  quaternion,
double  scale 
) [static]

Multiplies an instance by a scalar.

Parameters:
quaternion The instance.
scale The scalar.
Returns:
A new instance containing the result of the calculation.

Definition at line 364 of file Quaterniond.cs.

00365         {
00366             return new Quaterniond(quaternion.X * scale, quaternion.Y * scale, quaternion.Z * scale, quaternion.W * scale);
00367         }

static void OpenTK.Quaterniond.Multiply ( ref Quaterniond  quaternion,
double  scale,
out Quaterniond  result 
) [static]

Multiplies an instance by a scalar.

Parameters:
quaternion The instance.
scale The scalar.
result A new instance containing the result of the calculation.

Definition at line 353 of file Quaterniond.cs.

00354         {
00355             result = new Quaterniond(quaternion.X * scale, quaternion.Y * scale, quaternion.Z * scale, quaternion.W * scale);
00356         }

static void OpenTK.Quaterniond.Multiply ( ref Quaterniond  left,
ref Quaterniond  right,
out Quaterniond  result 
) [static]

Multiplies two instances.

Parameters:
left The first instance.
right The second instance.
result A new instance containing the result of the calculation.

Definition at line 340 of file Quaterniond.cs.

00341         {
00342             result = new Quaterniond(
00343                 right.W * left.Xyz + left.W * right.Xyz + Vector3d.Cross(left.Xyz, right.Xyz),
00344                 left.W * right.W - Vector3d.Dot(left.Xyz, right.Xyz));
00345         }

static Quaterniond OpenTK.Quaterniond.Multiply ( Quaterniond  left,
Quaterniond  right 
) [static]

Multiplies two instances.

Parameters:
left The first instance.
right The second instance.
Returns:
A new instance containing the result of the calculation.

Definition at line 327 of file Quaterniond.cs.

00328         {
00329             Quaterniond result;
00330             Multiply(ref left, ref right, out result);
00331             return result;
00332         }

static void OpenTK.Quaterniond.Normalize ( ref Quaterniond  q,
out Quaterniond  result 
) [static]

Scale the given Quaterniond to unit length.

Parameters:
q The Quaterniond to normalize
result The normalized Quaterniond

Definition at line 449 of file Quaterniond.cs.

00450         {
00451             double scale = 1.0f / q.Length;
00452             result = new Quaterniond(q.Xyz * scale, q.W * scale);
00453         }

static Quaterniond OpenTK.Quaterniond.Normalize ( Quaterniond  q  )  [static]

Scale the given Quaterniond to unit length.

Parameters:
q The Quaterniond to normalize
Returns:
The normalized Quaterniond

Definition at line 437 of file Quaterniond.cs.

00438         {
00439             Quaterniond result;
00440             Normalize(ref q, out result);
00441             return result;
00442         }

void OpenTK.Quaterniond.Normalize (  ) 

Scales the Quaterniond to unit length.

Definition at line 197 of file Quaterniond.cs.

00198         {
00199             double scale = 1.0f / this.Length;
00200             Xyz *= scale;
00201             W *= scale;
00202         }

static bool OpenTK.Quaterniond.operator!= ( Quaterniond  left,
Quaterniond  right 
) [static]

Compares two instances for inequality.

Parameters:
left The first instance.
right The second instance.
Returns:
True, if left does not equal right; false otherwise.

Definition at line 631 of file Quaterniond.cs.

00632         {
00633             return !left.Equals(right);
00634         }

static Quaterniond OpenTK.Quaterniond.operator* ( double  scale,
Quaterniond  quaternion 
) [static]

Multiplies an instance by a scalar.

Parameters:
quaternion The instance.
scale The scalar.
Returns:
A new instance containing the result of the calculation.

Definition at line 609 of file Quaterniond.cs.

00610         {
00611             return new Quaterniond(quaternion.X * scale, quaternion.Y * scale, quaternion.Z * scale, quaternion.W * scale);
00612         }

static Quaterniond OpenTK.Quaterniond.operator* ( Quaterniond  quaternion,
double  scale 
) [static]

Multiplies an instance by a scalar.

Parameters:
quaternion The instance.
scale The scalar.
Returns:
A new instance containing the result of the calculation.

Definition at line 597 of file Quaterniond.cs.

00598         {
00599             Multiply(ref quaternion, scale, out quaternion);
00600             return quaternion;
00601         }

static Quaterniond OpenTK.Quaterniond.operator* ( Quaterniond  left,
Quaterniond  right 
) [static]

Multiplies two instances.

Parameters:
left The first instance.
right The second instance.
Returns:
The result of the calculation.

Definition at line 585 of file Quaterniond.cs.

00586         {
00587             Multiply(ref left, ref right, out left);
00588             return left;
00589         }

static Quaterniond OpenTK.Quaterniond.operator+ ( Quaterniond  left,
Quaterniond  right 
) [static]

Adds two instances.

Parameters:
left The first instance.
right The second instance.
Returns:
The result of the calculation.

Definition at line 559 of file Quaterniond.cs.

00560         {
00561             left.Xyz += right.Xyz;
00562             left.W += right.W;
00563             return left;
00564         }

static Quaterniond OpenTK.Quaterniond.operator- ( Quaterniond  left,
Quaterniond  right 
) [static]

Subtracts two instances.

Parameters:
left The first instance.
right The second instance.
Returns:
The result of the calculation.

Definition at line 572 of file Quaterniond.cs.

00573         {
00574             left.Xyz -= right.Xyz;
00575             left.W -= right.W;
00576             return left;
00577         }

static bool OpenTK.Quaterniond.operator== ( Quaterniond  left,
Quaterniond  right 
) [static]

Compares two instances for equality.

Parameters:
left The first instance.
right The second instance.
Returns:
True, if left equals right; false otherwise.

Definition at line 620 of file Quaterniond.cs.

00621         {
00622             return left.Equals(right);
00623         }

static Quaterniond OpenTK.Quaterniond.Slerp ( Quaterniond  q1,
Quaterniond  q2,
double  blend 
) [static]

Do Spherical linear interpolation between two quaternions.

Parameters:
q1 The first Quaterniond
q2 The second Quaterniond
blend The blend factor
Returns:
A smooth blend between the given quaternions

Definition at line 491 of file Quaterniond.cs.

00492         {
00493             // if either input is zero, return the other.
00494             if (q1.LengthSquared == 0.0f)
00495             {
00496                 if (q2.LengthSquared == 0.0f)
00497                 {
00498                     return Identity;
00499                 }
00500                 return q2;
00501             }
00502             else if (q2.LengthSquared == 0.0f)
00503             {
00504                 return q1;
00505             }
00506 
00507 
00508             double cosHalfAngle = q1.W * q2.W + Vector3d.Dot(q1.Xyz, q2.Xyz);
00509 
00510             if (cosHalfAngle >= 1.0f || cosHalfAngle <= -1.0f)
00511             {
00512                 // angle = 0.0f, so just return one input.
00513                 return q1;
00514             }
00515             else if (cosHalfAngle < 0.0f)
00516             {
00517                 q2.Xyz = -q2.Xyz;
00518                 q2.W = -q2.W;
00519                 cosHalfAngle = -cosHalfAngle;
00520             }
00521 
00522             double blendA;
00523             double blendB;
00524             if (cosHalfAngle < 0.99f)
00525             {
00526                 // do proper slerp for big angles
00527                 double halfAngle = (double)System.Math.Acos(cosHalfAngle);
00528                 double sinHalfAngle = (double)System.Math.Sin(halfAngle);
00529                 double oneOverSinHalfAngle = 1.0f / sinHalfAngle;
00530                 blendA = (double)System.Math.Sin(halfAngle * (1.0f - blend)) * oneOverSinHalfAngle;
00531                 blendB = (double)System.Math.Sin(halfAngle * blend) * oneOverSinHalfAngle;
00532             }
00533             else
00534             {
00535                 // do lerp if angle is really small.
00536                 blendA = 1.0f - blend;
00537                 blendB = blend;
00538             }
00539 
00540             Quaterniond result = new Quaterniond(blendA * q1.Xyz + blendB * q2.Xyz, blendA * q1.W + blendB * q2.W);
00541             if (result.LengthSquared > 0.0f)
00542                 return Normalize(result);
00543             else
00544                 return Identity;
00545         }

static void OpenTK.Quaterniond.Sub ( ref Quaterniond  left,
ref Quaterniond  right,
out Quaterniond  result 
) [static]

Subtracts two instances.

Parameters:
left The left instance.
right The right instance.
result The result of the operation.

Definition at line 282 of file Quaterniond.cs.

00283         {
00284             result = new Quaterniond(
00285                 left.Xyz - right.Xyz,
00286                 left.W - right.W);
00287         }

static Quaterniond OpenTK.Quaterniond.Sub ( Quaterniond  left,
Quaterniond  right 
) [static]

Subtracts two instances.

Parameters:
left The left instance.
right The right instance.
Returns:
The result of the operation.

Definition at line 269 of file Quaterniond.cs.

00270         {
00271             return new Quaterniond(
00272                 left.Xyz - right.Xyz,
00273                 left.W - right.W);
00274         }

Vector4d OpenTK.Quaterniond.ToAxisAngle (  ) 

Convert this instance to an axis-angle representation.

Returns:
A Vector4 that is the axis-angle representation of this quaternion.

Definition at line 135 of file Quaterniond.cs.

00136         {
00137             Quaterniond q = this;
00138             if (q.W > 1.0f)
00139                 q.Normalize();
00140 
00141             Vector4d result = new Vector4d();
00142 
00143             result.W = 2.0f * (float)System.Math.Acos(q.W); // angle
00144             float den = (float)System.Math.Sqrt(1.0 - q.W * q.W);
00145             if (den > 0.0001f)
00146             {
00147                 result.Xyz = q.Xyz / den;
00148             }
00149             else
00150             {
00151                 // This occurs when the angle is zero. 
00152                 // Not a problem: just set an arbitrary normalized axis.
00153                 result.Xyz = Vector3d.UnitX;
00154             }
00155 
00156             return result;
00157         }

void OpenTK.Quaterniond.ToAxisAngle ( out Vector3d  axis,
out double  angle 
)

Convert the current quaternion to axis angle representation.

Parameters:
axis The resultant axis
angle The resultant angle

Definition at line 124 of file Quaterniond.cs.

00125         {
00126             Vector4d result = ToAxisAngle();
00127             axis = result.Xyz;
00128             angle = result.W;
00129         }

override string OpenTK.Quaterniond.ToString (  ) 

Returns a System.String that represents the current Quaterniond.

Returns:

Definition at line 646 of file Quaterniond.cs.

00647         {
00648             return String.Format("V: {0}, W: {1}", Xyz, W);
00649         }


Member Data Documentation

readonly Quaterniond OpenTK.Quaterniond.Identity = new Quaterniond(0, 0, 0, 1) [static]

Defines the identity quaternion.

Definition at line 227 of file Quaterniond.cs.


Property Documentation

double OpenTK.Quaterniond.Length [get]

Gets the length (magnitude) of the Quaterniond.

See also:
LengthSquared

Definition at line 168 of file Quaterniond.cs.

double OpenTK.Quaterniond.LengthSquared [get]

Gets the square of the Quaterniond length (magnitude).

Definition at line 183 of file Quaterniond.cs.

double OpenTK.Quaterniond.W [get, set]

Gets or sets the W component of this instance.

Definition at line 111 of file Quaterniond.cs.

double OpenTK.Quaterniond.X [get, set]

Gets or sets the X component of this instance.

Definition at line 94 of file Quaterniond.cs.

Vector3d OpenTK.Quaterniond.Xyz [get, set]

Gets or sets an OpenTK.Vector3d with the X, Y and Z components of this instance.

Definition at line 88 of file Quaterniond.cs.

Vector3d OpenTK.Quaterniond.XYZ [get, set]

Gets or sets an OpenTK.Vector3d with the X, Y and Z components of this instance.

Definition at line 83 of file Quaterniond.cs.

double OpenTK.Quaterniond.Y [get, set]

Gets or sets the Y component of this instance.

Definition at line 100 of file Quaterniond.cs.

double OpenTK.Quaterniond.Z [get, set]

Gets or sets the Z component of this instance.

Definition at line 106 of file Quaterniond.cs.

 All Classes Functions Variables Enumerations Properties Events

Generated on Tue Mar 9 14:59:15 2010 for The Open Toolkit library by  doxygen 1.6.1