Class Quaternion

java.lang.Object
  extended by Quaternion

public class Quaternion
extends java.lang.Object

Quaternions. Basic operations.


Constructor Summary
Quaternion(double a, double b, double c, double d)
          Constructor from four double values.
 
Method Summary
 java.lang.Object clone()
          Clone of the quaternion.
 Quaternion conjugate()
          Conjugate of the quaternion.
 Quaternion divideByLeft(Quaternion q)
          Left quotient of quaternions.
 Quaternion divideByRight(Quaternion q)
          Right quotient of quaternions.
 Quaternion dotMult(Quaternion q)
          Dot product of quaternions.
 boolean equals(java.lang.Object qo)
          Equality test of quaternions.
 double getIpart()
          Imaginary part i of the quaternion.
 double getJpart()
          Imaginary part j of the quaternion.
 double getKpart()
          Imaginary part k of the quaternion.
 double getRpart()
          Real part of the quaternion.
 int hashCode()
          Integer hashCode has to be the same for equal objects.
 Quaternion inverse()
          Inverse of the quaternion.
 boolean isZero()
          Test whether the quaternion is zero.
 Quaternion minus(Quaternion q)
          Difference of quaternions.
 double norm()
          Norm of the quaternion.
 Quaternion opposite()
          Opposite of the quaternion.
 Quaternion plus(Quaternion q)
          Sum of quaternions.
 Quaternion times(double r)
          Multiplication by a coefficient.
 Quaternion times(Quaternion q)
          Product of quaternions.
 java.lang.String toString()
          Conversion of the quaternion to the string.
static Quaternion valueOf(java.lang.String s)
          Conversion from the string to the quaternion.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Quaternion

public Quaternion(double a,
                  double b,
                  double c,
                  double d)
Constructor from four double values.

Parameters:
a - real part
b - imaginary part i
c - imaginary part j
d - imaginary part k
Method Detail

getRpart

public double getRpart()
Real part of the quaternion.

Returns:
real part

getIpart

public double getIpart()
Imaginary part i of the quaternion.

Returns:
imaginary part i

getJpart

public double getJpart()
Imaginary part j of the quaternion.

Returns:
imaginary part j

getKpart

public double getKpart()
Imaginary part k of the quaternion.

Returns:
imaginary part k

toString

public java.lang.String toString()
Conversion of the quaternion to the string.

Overrides:
toString in class java.lang.Object
Returns:
a string form of this quaternion: "a+bi+cj+dk" (without any brackets)

valueOf

public static Quaternion valueOf(java.lang.String s)
Conversion from the string to the quaternion. Reverse to toString method.

Parameters:
s - string of form produced by the toString method
Returns:
a quaternion represented by string s
Throws:
java.lang.IllegalArgumentException - if string s does not represent a quaternion (defined by the toString method)

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Clone of the quaternion.

Overrides:
clone in class java.lang.Object
Returns:
independent clone of this
Throws:
java.lang.CloneNotSupportedException

isZero

public boolean isZero()
Test whether the quaternion is zero.

Returns:
true, if the real part and all the imaginary parts are (close to) zero

conjugate

public Quaternion conjugate()
Conjugate of the quaternion. Expressed by the formula conjugate(a+bi+cj+dk) = a-bi-cj-dk

Returns:
conjugate of this

opposite

public Quaternion opposite()
Opposite of the quaternion. Expressed by the formula opposite(a+bi+cj+dk) = -a-bi-cj-dk

Returns:
quaternion -this

plus

public Quaternion plus(Quaternion q)
Sum of quaternions. Expressed by the formula (a1+b1i+c1j+d1k) + (a2+b2i+c2j+d2k) = (a1+a2) + (b1+b2)i + (c1+c2)j + (d1+d2)k

Parameters:
q - addend
Returns:
quaternion this+q

times

public Quaternion times(Quaternion q)
Product of quaternions. Expressed by the formula (a1+b1i+c1j+d1k) * (a2+b2i+c2j+d2k) = (a1a2-b1b2-c1c2-d1d2) + (a1b2+b1a2+c1d2-d1c2)i + (a1c2-b1d2+c1a2+d1b2)j + (a1d2+b1c2-c1b2+d1a2)k

Parameters:
q - factor
Returns:
quaternion this*q

times

public Quaternion times(double r)
Multiplication by a coefficient.

Parameters:
r - coefficient
Returns:
quaternion this*r

inverse

public Quaternion inverse()
Inverse of the quaternion. Expressed by the formula 1/(a+bi+cj+dk) = a/(a*a+b*b+c*c+d*d) + ((-b)/(a*a+b*b+c*c+d*d))i + ((-c)/(a*a+b*b+c*c+d*d))j + ((-d)/(a*a+b*b+c*c+d*d))k

Returns:
quaternion 1/this

minus

public Quaternion minus(Quaternion q)
Difference of quaternions. Expressed as addition to the opposite.

Parameters:
q - subtrahend
Returns:
quaternion this-q

divideByRight

public Quaternion divideByRight(Quaternion q)
Right quotient of quaternions. Expressed as multiplication to the inverse.

Parameters:
q - (right) divisor
Returns:
quaternion this*inverse(q)

divideByLeft

public Quaternion divideByLeft(Quaternion q)
Left quotient of quaternions.

Parameters:
q - (left) divisor
Returns:
quaternion inverse(q)*this

equals

public boolean equals(java.lang.Object qo)
Equality test of quaternions. Difference of equal numbers is (close to) zero.

Overrides:
equals in class java.lang.Object
Parameters:
qo - second quaternion
Returns:
logical value of the expression this.equals(qo)

dotMult

public Quaternion dotMult(Quaternion q)
Dot product of quaternions. (p*conjugate(q) + q*conjugate(p))/2

Parameters:
q - factor
Returns:
dot product of this and q

hashCode

public int hashCode()
Integer hashCode has to be the same for equal objects.

Overrides:
hashCode in class java.lang.Object
Returns:
hashcode

norm

public double norm()
Norm of the quaternion. Expressed by the formula norm(a+bi+cj+dk) = Math.sqrt(a*a+b*b+c*c+d*d)

Returns:
norm of this (norm is a real number)