uavsim.flightdynamicsmodel
Class Quaternion

java.lang.Object
  extended by uavsim.flightdynamicsmodel.Quaternion
All Implemented Interfaces:
java.lang.Cloneable

public class Quaternion
extends java.lang.Object
implements java.lang.Cloneable

Defines a general-purpose mathematical quaternion as an alternative to Euler angles for attitude calculations without singularity limitations at extreme configurations. It is derived from Physics for Game Developers by David Bourg.

Author:
Dan Tappan [17.08.11]

Field Summary
private  double _n
          the scalar component
private  Vector _v
          the vector component
 
Constructor Summary
Quaternion()
          Creates a quaternion with the scalar and vector components zero.
Quaternion(double roll, double pitch, double yaw)
          Creates a quaternion from the Euler angles (in degrees).
Quaternion(double n, double x, double y, double z)
          Creates a quaternion from its individual elements.
Quaternion(double n, Vector vector)
          Creates a quaternion from its individual elements.
 
Method Summary
 Quaternion add(Quaternion quaternion)
          Calculates the sum of this quaternion and another.
 Quaternion clone()
          
 Quaternion conjugate()
          Calculates the conjugate of this quaternion.
 Vector convertToEulerAngles()
          Converts this quaternion to a vector of Euler angles.
 Quaternion divide(double scale)
          Calculates the scaled components of this quaternion.
 double getAngle()
          Calculates the angle component of this quaternion from its scalar component.
 Vector getAxis()
          Calculates the vector axis of this quaternion.
 double getScalar()
          Returns the scalar component of this quaternion.
 Vector getVector()
          Returns a copy of the vector component of this quaternion.
 double magnitude()
          Calculates the magnitude of this quaternion.
 Quaternion multiply(double scale)
          Calculates the scaled components of this quaternion.
 Quaternion multiply(Quaternion quaternion)
          Calculates the product of this quaternion and another.
 Quaternion multiply(Vector vector)
          Calculates the product of this quaternion and a vector.
 Quaternion rotate(Quaternion quaternion)
          Rotates this quaternion with respect to another.
 Vector rotate(Vector vector)
          Rotates this quaternion with respect to a vector.
 Quaternion subtract(Quaternion quaternion)
          Calculates the difference of this quaternion and another.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_n

private final double _n
the scalar component


_v

private Vector _v
the vector component

Constructor Detail

Quaternion

public Quaternion()
Creates a quaternion with the scalar and vector components zero.


Quaternion

public Quaternion(double roll,
                  double pitch,
                  double yaw)
Creates a quaternion from the Euler angles (in degrees).

Parameters:
roll - - the roll
pitch - - the pitch
yaw - - the yaw

Quaternion

public Quaternion(double n,
                  double x,
                  double y,
                  double z)
Creates a quaternion from its individual elements.

Parameters:
n - - the scalar component
x - - the x component of the vector
y - - the y component of the vector
z - - the z component of the vector

Quaternion

public Quaternion(double n,
                  Vector vector)
Creates a quaternion from its individual elements.

Parameters:
n - - the scalar component
vector - - the vector component
Method Detail

add

public Quaternion add(Quaternion quaternion)
Calculates the sum of this quaternion and another.

Parameters:
quaternion - - the other quaternion
Returns:
the result as a new quaternion

clone

public Quaternion clone()

Overrides:
clone in class java.lang.Object

conjugate

public Quaternion conjugate()
Calculates the conjugate of this quaternion.

Returns:
the result as a new quaternion

convertToEulerAngles

public Vector convertToEulerAngles()
Converts this quaternion to a vector of Euler angles.

Returns:
the result

divide

public Quaternion divide(double scale)
Calculates the scaled components of this quaternion.

Parameters:
scale - - the scale
Returns:
the result as a new quaternion

getAngle

public double getAngle()
Calculates the angle component of this quaternion from its scalar component.

Returns:
the result

getAxis

public Vector getAxis()
Calculates the vector axis of this quaternion.

Returns:
the result

getScalar

public double getScalar()
Returns the scalar component of this quaternion.

Returns:
the component

getVector

public Vector getVector()
Returns a copy of the vector component of this quaternion.

Returns:
the component

magnitude

public double magnitude()
Calculates the magnitude of this quaternion.

Returns:
the result

multiply

public Quaternion multiply(double scale)
Calculates the scaled components of this quaternion.

Parameters:
scale - - the scale
Returns:
the result as a new quaternion

multiply

public Quaternion multiply(Quaternion quaternion)
Calculates the product of this quaternion and another.

Parameters:
quaternion - - the other quaternion
Returns:
the result as a new quaternion

multiply

public Quaternion multiply(Vector vector)
Calculates the product of this quaternion and a vector.

Parameters:
vector - - the vector
Returns:
the result as a new quaternion

rotate

public Quaternion rotate(Quaternion quaternion)
Rotates this quaternion with respect to another.

Parameters:
quaternion - - the other quaternion
Returns:
the result as a new quaternion

rotate

public Vector rotate(Vector vector)
Rotates this quaternion with respect to a vector.

Parameters:
vector - - the other vector
Returns:
the result as a new quaternion

subtract

public Quaternion subtract(Quaternion quaternion)
Calculates the difference of this quaternion and another.

Parameters:
quaternion - - the other quaternion
Returns:
the result as a new quaternion