JSci.maths
Class Quaternion

java.lang.Object
  extended by JSci.maths.Quaternion
All Implemented Interfaces:
java.io.Serializable, Algebra.Member, BanachSpace.Member, CStarAlgebra.Member, Module.Member, VectorSpace.Member, Field.Member, Ring.Member, AbelianGroup.Member, Member

public final class Quaternion
extends java.lang.Object
implements Field.Member, CStarAlgebra.Member

The Quaternion class encapsulates quaternions.

See Also:
Serialized Form
PlanetMath references:
Quaternions
Wikipedia references:
Quaternion

Field Summary
static Quaternion I
           
static Quaternion J
           
static Quaternion K
           
static Quaternion ONE
           
 
Constructor Summary
Quaternion(double real, Double3Vector imag)
          Constructs a quaternion.
Quaternion(double q0, double q1, double q2, double q3)
          Constructs the quaternion q0+iq1+jq2+kq3.
 
Method Summary
 AbelianGroup.Member add(AbelianGroup.Member x)
          Returns the addition of this number and another.
 Quaternion add(Quaternion q)
          Returns the addition of this quaternion and another.
 Quaternion addImag(Double3Vector imag)
          Returns the addition of this quaternion with an imaginary part.
 Quaternion addReal(double real)
          Returns the addition of this quaternion with a real part.
 Quaternion conjugate()
          Returns the conjugate of this quaternion.
static Quaternion cos(Quaternion q)
           
static Quaternion cosh(Quaternion q)
           
 Quaternion divide(double x)
          Returns the division of this quaternion by a scalar.
 Field.Member divide(Field.Member x)
          Returns the division of this number and another.
 Quaternion divide(Quaternion q)
          Returns the division of this quaternion by another.
 boolean equals(java.lang.Object obj)
          Compares two quaternions for equality.
static Quaternion exp(Quaternion q)
           
 java.lang.Object getSet()
           
 int hashCode()
          Returns a hashcode for this quaternion.
 Double3Vector imag()
          Returns the imaginary part of this quaternion.
 Field.Member inverse()
          Returns the inverse of this quaternion.
 CStarAlgebra.Member involution()
          Returns the involution of this quaternion.
 boolean isInfinite()
          Returns true if either the real or imaginary part is infinite.
 boolean isNaN()
          Returns true if either the real or imaginary part is NaN.
static Quaternion log(Quaternion q)
           
 Quaternion multiply(double x)
          Returns the multiplication of this quaternion by a scalar.
 Quaternion multiply(Quaternion q)
          Returns the multiplication of this quaternion and another.
 Ring.Member multiply(Ring.Member x)
          Returns the multiplication of this number and another.
 AbelianGroup.Member negate()
          Returns the negative of this quaternion.
 double norm()
          Returns the l2-norm (magnitude), which is also the C* norm.
 Quaternion normalize()
           
 double real()
          Returns the real part of this quaternion.
static Quaternion rotation(AbstractDoubleSquareMatrix m)
          Constructs a quaternion representing a rotation matrix.
 VectorSpace.Member scalarDivide(Field.Member x)
          Returns the division of this number by a real scalar.
 Module.Member scalarMultiply(Ring.Member x)
          Returns the multiplication of this number by a real scalar.
static Quaternion sin(Quaternion q)
           
static Quaternion sinh(Quaternion q)
           
 AbelianGroup.Member subtract(AbelianGroup.Member x)
          Returns the subtraction of this number and another.
 Quaternion subtract(Quaternion q)
          Returns the subtraction of this quaternion by another.
 Quaternion subtractImag(Double3Vector imag)
          Returns the subtraction of this quaternion by an imaginary part.
 Quaternion subtractReal(double real)
          Returns the subtraction of this quaternion by a real part.
 double sumSquares()
          Returns the sum of the squares of the components.
static Quaternion tan(Quaternion q)
           
static Quaternion tanh(Quaternion q)
           
 AbstractDoubleSquareMatrix toRotationMatrix()
          Returns a 3D rotation matrix representing this quaternion.
 java.lang.String toString()
          Returns a string representing the value of this quaternion.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ONE

public static final Quaternion ONE

I

public static final Quaternion I

J

public static final Quaternion J

K

public static final Quaternion K
Constructor Detail

Quaternion

public Quaternion(double real,
                  Double3Vector imag)
Constructs a quaternion.


Quaternion

public Quaternion(double q0,
                  double q1,
                  double q2,
                  double q3)
Constructs the quaternion q0+iq1+jq2+kq3.

Method Detail

rotation

public static Quaternion rotation(AbstractDoubleSquareMatrix m)
Constructs a quaternion representing a rotation matrix. Note: if the matrix is not orthogonal then the quaternion will not have unit norm. Note: unit quaternions are a double cover of SO(3).

Parameters:
m - a rotation matrix

toRotationMatrix

public AbstractDoubleSquareMatrix toRotationMatrix()
Returns a 3D rotation matrix representing this quaternion. Note: if this quaternion does not have unit norm then the matrix will not be orthogonal.


equals

public boolean equals(java.lang.Object obj)
Compares two quaternions for equality.

Overrides:
equals in class java.lang.Object
Parameters:
obj - a quaternion

toString

public java.lang.String toString()
Returns a string representing the value of this quaternion.

Overrides:
toString in class java.lang.Object

hashCode

public int hashCode()
Returns a hashcode for this quaternion.

Overrides:
hashCode in class java.lang.Object

isNaN

public boolean isNaN()
Returns true if either the real or imaginary part is NaN.


isInfinite

public boolean isInfinite()
Returns true if either the real or imaginary part is infinite.


real

public double real()
Returns the real part of this quaternion.


imag

public Double3Vector imag()
Returns the imaginary part of this quaternion.


getSet

public java.lang.Object getSet()
Specified by:
getSet in interface Member

norm

public double norm()
Returns the l2-norm (magnitude), which is also the C* norm.

Specified by:
norm in interface BanachSpace.Member

sumSquares

public double sumSquares()
Returns the sum of the squares of the components.


negate

public AbelianGroup.Member negate()
Returns the negative of this quaternion.

Specified by:
negate in interface AbelianGroup.Member

inverse

public Field.Member inverse()
Returns the inverse of this quaternion.

Specified by:
inverse in interface Field.Member

involution

public CStarAlgebra.Member involution()
Returns the involution of this quaternion.

Specified by:
involution in interface CStarAlgebra.Member

conjugate

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


add

public AbelianGroup.Member add(AbelianGroup.Member x)
Returns the addition of this number and another.

Specified by:
add in interface AbelianGroup.Member
Parameters:
x - a group member

add

public Quaternion add(Quaternion q)
Returns the addition of this quaternion and another.

Parameters:
q - a quaternion

addReal

public Quaternion addReal(double real)
Returns the addition of this quaternion with a real part.

Parameters:
real - a real part

addImag

public Quaternion addImag(Double3Vector imag)
Returns the addition of this quaternion with an imaginary part.

Parameters:
imag - an imaginary part

subtract

public AbelianGroup.Member subtract(AbelianGroup.Member x)
Returns the subtraction of this number and another.

Specified by:
subtract in interface AbelianGroup.Member
Parameters:
x - a group member

subtract

public Quaternion subtract(Quaternion q)
Returns the subtraction of this quaternion by another.

Parameters:
q - a quaternion

subtractReal

public Quaternion subtractReal(double real)
Returns the subtraction of this quaternion by a real part.

Parameters:
real - a real part

subtractImag

public Quaternion subtractImag(Double3Vector imag)
Returns the subtraction of this quaternion by an imaginary part.

Parameters:
imag - an imaginary part

scalarMultiply

public Module.Member scalarMultiply(Ring.Member x)
Returns the multiplication of this number by a real scalar.

Specified by:
scalarMultiply in interface Module.Member
Parameters:
x - a ring member

multiply

public Ring.Member multiply(Ring.Member x)
Returns the multiplication of this number and another.

Specified by:
multiply in interface Ring.Member
Parameters:
x - a ring member

multiply

public Quaternion multiply(Quaternion q)
Returns the multiplication of this quaternion and another.

Parameters:
q - a quaternion

multiply

public Quaternion multiply(double x)
Returns the multiplication of this quaternion by a scalar.

Parameters:
x - a real number

scalarDivide

public VectorSpace.Member scalarDivide(Field.Member x)
Returns the division of this number by a real scalar.

Specified by:
scalarDivide in interface VectorSpace.Member
Parameters:
x - a field member

divide

public Field.Member divide(Field.Member x)
Returns the division of this number and another.

Specified by:
divide in interface Field.Member
Parameters:
x - a field member

divide

public Quaternion divide(Quaternion q)
Returns the division of this quaternion by another.

Parameters:
q - a quaternion
Throws:
java.lang.ArithmeticException - If divide by zero.

divide

public Quaternion divide(double x)
Returns the division of this quaternion by a scalar.

Parameters:
x - a real number
Throws:
java.lang.ArithmeticException - If divide by zero.

normalize

public Quaternion normalize()

exp

public static Quaternion exp(Quaternion q)

log

public static Quaternion log(Quaternion q)

sin

public static Quaternion sin(Quaternion q)

cos

public static Quaternion cos(Quaternion q)

tan

public static Quaternion tan(Quaternion q)

sinh

public static Quaternion sinh(Quaternion q)

cosh

public static Quaternion cosh(Quaternion q)

tanh

public static Quaternion tanh(Quaternion q)