Packagegraphics.geom
Classpublic class Quaternion
InheritanceQuaternion Inheritance Object
Implements Geometry

Quaternions are hypercomplex numbers used to represent spatial rotations in three dimensions. This class encapsulates an Hamiltonian quaternion having the form xi + yj + zk + w.



Public Properties
 PropertyDefined By
  w : Number
Represents the scalar value of the quaternion.
Quaternion
  x : Number
Defined the x component of the quaternion.
Quaternion
  y : Number
Defined the y component of the quaternion.
Quaternion
  z : Number
Defined the z component of the quaternion.
Quaternion
Public Methods
 MethodDefined By
  
Quaternion(x:Number = 0, y:Number = 0, z:Number = 0, w:Number = 0)
Creates a new Quaternion instance.
Quaternion
  
add(q:Quaternion):void
Adds the values of the specified Quaternion.
Quaternion
  
axis(x:Number, y:Number, z:Number, angle:Number):void
Sets the quaternion with values representing the given rotation around a vector.
Quaternion
  
clone():*
Returns a shallow copy of this instance.
Quaternion
  
conjugate():void
Conjugates the Quaternion.
Quaternion
  
dot(q:Quaternion):Number
Returns the dot product of two quaternions.
Quaternion
  
equals(o:*):Boolean
Compares the specified object with this object for equality.
Quaternion
  
euler(roll:Number, pitch:Number, yaw:Number, degrees:Boolean = false):void
Sets the quaternion with values representing the given euler rotation.
Quaternion
  
Calculates the exponential of a quaternion.
Quaternion
  
getEulerAngles(degrees:Boolean = false):Vector3
Returns the Vector3 representation of the roll/pitch/yaw euler angles of the current quaternion.
Quaternion
  
identity():void
Sets the Quaternion to be identity {0,0,0,1}.
Quaternion
  
invert():void
Conjugates and renormalizes a quaternion.
Quaternion
  
isIdentity():Boolean
Returns true if the Quaternion is {0,0,0,1}.
Quaternion
  
Calculates the natural logarithm of a quaternion.
Quaternion
  
Multiply the Quaternion with an other Quaternion.
Quaternion
  
normalize():void
Normalizes the Quaternion instance.
Quaternion
  
scale(value:Number):void
Scales the quaternion object with the input value.
Quaternion
  
size():Number
Returns the magnitude (length) of a Quaternion, measured in the Euclidean norm.
Quaternion
  
sizeSquared():Number
Returns the square of the length of a quaternion.
Quaternion
  
Substracts the values of the s2ecified Quaternion.
Quaternion
  
toObject():Object
Returns the Object representation of this object.
Quaternion
  
toSource(indent:int = 0):String
Returns the source code string representation of the object.
Quaternion
  
toString():String
Returns the string representation of the object.
Quaternion
  
Apply the negation of the quaternion.
Quaternion
Property Detail
wproperty
public var w:Number

Represents the scalar value of the quaternion.

xproperty 
public var x:Number

Defined the x component of the quaternion.

yproperty 
public var y:Number

Defined the y component of the quaternion.

zproperty 
public var z:Number

Defined the z component of the quaternion.

Constructor Detail
Quaternion()Constructor
public function Quaternion(x:Number = 0, y:Number = 0, z:Number = 0, w:Number = 0)

Creates a new Quaternion instance.

Parameters
x:Number (default = 0) — the x coordinate.
 
y:Number (default = 0) — the y coordinate.
 
z:Number (default = 0) — the z coordinate.
 
w:Number (default = 0) — the transform component of the quaternion.
Method Detail
add()method
public function add(q:Quaternion):void

Adds the values of the specified Quaternion.

Parameters

q:Quaternion

axis()method 
public function axis(x:Number, y:Number, z:Number, angle:Number):void

Sets the quaternion with values representing the given rotation around a vector.

Parameters

x:Number — The x value of the rotation vector.
 
y:Number — The y value of the rotation vector.
 
z:Number — The z value of the rotation vector.
 
angle:Number — The angle in radians of the rotation.

clone()method 
public function clone():*

Returns a shallow copy of this instance.

Returns
* — a shallow copy of this instance.
conjugate()method 
public function conjugate():void

Conjugates the Quaternion.

dot()method 
public function dot(q:Quaternion):Number

Returns the dot product of two quaternions.

Parameters

q:Quaternion — The quaternion to calculate the dot product.

Returns
Number — The dot product of the two quaternions.
equals()method 
public function equals(o:*):Boolean

Compares the specified object with this object for equality.

Parameters

o:*

Returns
Booleantrue if the the specified object is equal with this object.
euler()method 
public function euler(roll:Number, pitch:Number, yaw:Number, degrees:Boolean = false):void

Sets the quaternion with values representing the given euler rotation.

Note : that we are applying in order: pitch, yaw, roll but we've ordered them in x, y, and z for convenience.

Example :

         import graphics.geom.Quaternion ;
         import graphics.numeric.Trigo ;
         
         var q:Quaternion = new Quaternion();
         
         q.euler( 360 * DEG2RAD , 180 * DEG2RAD , 90 * DEG2RAD ) ;
         trace(q) ;
         trace(q.getEulerAngles(true) ) ;
         
         q.euler( 360, 180 , 90 , true ) ;
         trace(q) ;
         trace(q.getEulerAngles(true) ) ;
         
         q.euler(40,80,180,true) ;
         trace(q) ;
         trace(q.getEulerAngles(true) ) ;
         
         q.euler( 2 Math.PI , Math.PI , Math.PI / 2 ) ;
         trace(q.getEulerAngles(true) ) ;
         

Parameters

roll:Number — The angle of the rotation around the y axis (heading/azimuth/θ).
 
pitch:Number — The angle of the rotation around the z axis (attitude/elevation/φ).
 
yaw:Number — The angle of the rotation around the x axis (bank/tilt/ψ).
 
degrees:Boolean (default = false) — Indicates if the angle are in degrees or in radians (default).

exp()method 
public function exp():Quaternion

Calculates the exponential of a quaternion.

Returns
Quaternion — The new Quaternion reference.
getEulerAngles()method 
public function getEulerAngles(degrees:Boolean = false):Vector3

Returns the Vector3 representation of the roll/pitch/yaw euler angles of the current quaternion.

Note :

         roll  = Heading  = rotation about y axis
         pitch = Attitude = rotation about z axis
         yaw   = Bank     = rotation about x axis
         

used in this class : Standards

Parameters

degrees:Boolean (default = false)

Returns
Vector3 — the Vector3 representation of the roll/pitch/yaw euler angles of the current quaternion.
identity()method 
public function identity():void

Sets the Quaternion to be identity {0,0,0,1}.

invert()method 
public function invert():void

Conjugates and renormalizes a quaternion.

isIdentity()method 
public function isIdentity():Boolean

Returns true if the Quaternion is {0,0,0,1}.

Returns
Boolean — true if this Quaternion is {0,0,0,1}.
log()method 
public function log():Quaternion

Calculates the natural logarithm of a quaternion.

Returns
Quaternion — The new Quaternion reference.
multiply()method 
public function multiply(q:Quaternion):void

Multiply the Quaternion with an other Quaternion.

Parameters

q:Quaternion — The Quaternion to multiply with the current Quaternion object.

normalize()method 
public function normalize():void

Normalizes the Quaternion instance.

scale()method 
public function scale(value:Number):void

Scales the quaternion object with the input value.

Parameters

value:Number — a real number to scale the current quaternion object.

size()method 
public function size():Number

Returns the magnitude (length) of a Quaternion, measured in the Euclidean norm.

Returns
Number — The length of the quaternion.
sizeSquared()method 
public function sizeSquared():Number

Returns the square of the length of a quaternion.

Returns
Number — the square of the length of a quaternion.
substract()method 
public function substract(q:Quaternion):void

Substracts the values of the s2ecified Quaternion.

Parameters

q:Quaternion

toObject()method 
public function toObject():Object

Returns the Object representation of this object.

Returns
Object — the Object representation of this object.
toSource()method 
public function toSource(indent:int = 0):String

Returns the source code string representation of the object.

Parameters

indent:int (default = 0)

Returns
String — the source code string representation of the object.
toString()method 
public function toString():String

Returns the string representation of the object.

Returns
String — the string representation of the object.
unaryNegation()method 
public function unaryNegation():void

Apply the negation of the quaternion.