etomica.math

## Class Quaternion

• java.lang.Object
• etomica.math.Quaternion

• ```public class Quaternion
extends java.lang.Object```
Quaternion object , its properties and associated operations
• ### Field Summary

Fields
Modifier and Type Field and Description
`protected double` `norm`
`protected double` `q0`
`protected double` `q1`
`protected double` `q2`
`protected double` `q3`
`protected static ISpace` `space`
`protected IVector` `vec`
• ### Constructor Summary

Constructors
Constructor and Description
`Quaternion(double[] p)`
Constructs the Quaternion q = p[0] + p[1]*i + p[2]*j + p[3]*k
```Quaternion(double a, double[] b)```
Constructs the Quaternion q = a + b[0]*i + b[1]*j + b[2]*k
```Quaternion(double a, double b, double c, double d)```
Constructs the Quaternion q = a + b*i + c*j + d*k
```Quaternion(double a, IVectorMutable b)```
Constructs the Quaternion q = a + b
`Quaternion(IVector[] basisVec)`
Constructs the Quaternion q for an input basis vector array.
```Quaternion(IVectorMutable axis, double angle)```
Constructs the unit Quaternion q = cos(angle/2) + axis*sin(angle/2)
`Quaternion(Jama.Matrix rotMatrix)`
Constructs the Quaternion q given an input rotation matrix.
`Quaternion(OrientationFull3D or)`
Constructs the Quaternion q for an input OrientationFull3D with two vectors.
• ### Method Summary

All Methods
Modifier and Type Method and Description
`Quaternion` `conjugate()`
Returns the complex conjugate of the Quaternion q.
`double` `getAngle()`
Returns the angle associated with the quaternion
`IVectorMutable` `getAxis()`
Returns the axis associated with the Quaternion.
`double[]` `getDoubleArray()`
Returns the Quaternion as a double array
`double` `getNorm()`
Returns the norm of the Quaternion q defined as N = sqrt(q*q)
`OrientationFull3D` `getOrientation()`
Returns an orientation corresponding to the rotation of cartesian coordinate frame {i,j,k} by the axis and angle associated with the Quaternion q.
`double` `getQ0()`
Returns the q0 component of the Quaternion
`double` `getQ1()`
Returns the q1 component of the Quaternion
`double` `getQ2()`
Returns the q2 component of the Quaternion
`double` `getQ3()`
Returns the q3 component of the Quaternion
`Jama.Matrix` `getRotationMatrix()`
Returns the rotation matrix associated with the Quaternion q as a Jama.Matrix
`double` `getScalar()`
Returns the scalar part of the Quaternion
`IVector` `getVector()`
Returns the vector part of the Quaternion as IVector
`double[]` `getVectorAsDoubleArray()`
Returns the vector associated with the Quaternion as a double array
`double` `getVectorMagnitude()`
Returns the magnitude of the vector associated with the Quaternion
`Quaternion` `inverse()`
Returns the inverse of the Quaternion q given by q^-1 = 1/(norm^2) * q*
`boolean` `isEqualTo(Quaternion p)`
Returns whether the Quaternion is equal to another given Quaternion p
`boolean` `isIllegal()`
Returns true if even a single component of the quaternion is either infinite or NaN
`boolean` `isPureQuaternion()`
Returns whether the Quaternion is pure or not
`boolean` `isUnitQuaternion()`
Returns whether the norm of the Quaternion is 1 or not
`void` `normalize()`
Normalizes the Quaternion q i.e.
`void` `PE(Quaternion p)`
Adds the input Quaternion components to its components.
`Quaternion` `preMultiply(Quaternion preMultiplier)`
Returns the Quaternion r resulting from multiplying the input Quaternion preMultiplier to the current Quaternion q.
`void` `rotateOrientation(OrientationFull3D or)`
Rotates the input orientation by using the Quaternion rotation operator L(v) = qvq*.
`void` `rotateVector(IVectorMutable v)`
Rotates the input vector by using the Quaternion rotation operator L(v) = qvq*.
`void` `TE(double a)`
Multiplies all the components of the Quaternion q by the given scalar
`java.lang.String` `toString()`
Returns the string representation of the Quaternion q
`protected void` `updateQuaternion()`
First checks if all the components are numbers.
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`
• ### Field Detail

• #### q0

`protected double q0`
• #### q1

`protected double q1`
• #### q2

`protected double q2`
• #### q3

`protected double q3`
• #### space

`protected static final ISpace space`
• #### vec

`protected final IVector vec`
• #### norm

`protected double norm`
• ### Constructor Detail

• #### Quaternion

`public Quaternion(double[] p)`
Constructs the Quaternion q = p[0] + p[1]*i + p[2]*j + p[3]*k
• #### Quaternion

```public Quaternion(double a,
IVectorMutable b)```
Constructs the Quaternion q = a + b
• #### Quaternion

```public Quaternion(IVectorMutable axis,
double angle)```
Constructs the unit Quaternion q = cos(angle/2) + axis*sin(angle/2)
Parameters:
`axis` -
`angle` -
• #### Quaternion

```public Quaternion(double a,
double b,
double c,
double d)```
Constructs the Quaternion q = a + b*i + c*j + d*k
• #### Quaternion

```public Quaternion(double a,
double[] b)```
Constructs the Quaternion q = a + b[0]*i + b[1]*j + b[2]*k
• #### Quaternion

`public Quaternion(OrientationFull3D or)`
Constructs the Quaternion q for an input OrientationFull3D with two vectors. First creates the three basis vectors from the orientation. Then converts that into a rotation matrix and finally into a Quaternion. This Quaternion represents the rotation of the {i,j,k} coordinate frame to the orthonormal coordinate frame formed by the the basis vectors.
Parameters:
`or` -
• #### Quaternion

`public Quaternion(IVector[] basisVec)`
Constructs the Quaternion q for an input basis vector array. Converts the basis vector array into a rotation matrix and finally into a Quaternion. This Quaternion represents the rotation of the {i,j,k} coordinate frame to the orthonormal coordinate frame formed by the basis vectors.
Parameters:
`basisVec` -
• #### Quaternion

`public Quaternion(Jama.Matrix rotMatrix)`
Constructs the Quaternion q given an input rotation matrix. Note that the determinant of the input matrix should be +1. Otherwise it doesn't represent a rotation
Parameters:
`rotMatrix` -
• ### Method Detail

• #### updateQuaternion

`protected void updateQuaternion()`
First checks if all the components are numbers. Then recomputes the norm and the vector of the Quaternion that has been operated upon.
• #### isIllegal

`public boolean isIllegal()`
Returns true if even a single component of the quaternion is either infinite or NaN
Returns:
boolean true/false
• #### getQ0

`public double getQ0()`
Returns the q0 component of the Quaternion
Returns:
double q0
• #### getQ1

`public double getQ1()`
Returns the q1 component of the Quaternion
Returns:
double q1
• #### getQ2

`public double getQ2()`
Returns the q2 component of the Quaternion
Returns:
double q2
• #### getQ3

`public double getQ3()`
Returns the q3 component of the Quaternion
Returns:
double q3
• #### getScalar

`public double getScalar()`
Returns the scalar part of the Quaternion
Returns:
double q0
• #### getVector

`public IVector getVector()`
Returns the vector part of the Quaternion as IVector
Returns:
IVector v = q1*i + q2*j + q3*k
• #### getAxis

`public IVectorMutable getAxis()`
Returns the axis associated with the Quaternion. Note, axis is a unit vector
• #### getAngle

`public double getAngle()`
Returns the angle associated with the quaternion
Returns:
• #### getVectorAsDoubleArray

`public double[] getVectorAsDoubleArray()`
Returns the vector associated with the Quaternion as a double array
Returns:
double [] v
• #### getVectorMagnitude

`public double getVectorMagnitude()`
Returns the magnitude of the vector associated with the Quaternion
Returns:
double magnitude = |vec|
• #### getDoubleArray

`public double[] getDoubleArray()`
Returns the Quaternion as a double array
Returns:
double [] q
• #### getRotationMatrix

`public Jama.Matrix getRotationMatrix()`
Returns the rotation matrix associated with the Quaternion q as a Jama.Matrix
Returns:
Jama.Matrix A
• #### getOrientation

`public OrientationFull3D getOrientation()`
Returns an orientation corresponding to the rotation of cartesian coordinate frame {i,j,k} by the axis and angle associated with the Quaternion q.
Returns:
OrientationFull3D or
• #### isPureQuaternion

`public boolean isPureQuaternion()`
Returns whether the Quaternion is pure or not
Returns:
boolean true/false
• #### isEqualTo

`public boolean isEqualTo(Quaternion p)`
Returns whether the Quaternion is equal to another given Quaternion p
Parameters:
`p` -
Returns:
boolean true/false
• #### isUnitQuaternion

`public boolean isUnitQuaternion()`
Returns whether the norm of the Quaternion is 1 or not
Returns:
boolean true/false
• #### PE

`public void PE(Quaternion p)`
Adds the input Quaternion components to its components. Addition is done component wise
Parameters:
`p` -
• #### TE

`public void TE(double a)`
Multiplies all the components of the Quaternion q by the given scalar
Parameters:
`a` -
• #### preMultiply

`public Quaternion preMultiply(Quaternion preMultiplier)`
Returns the Quaternion r resulting from multiplying the input Quaternion preMultiplier to the current Quaternion q. Can be thought of as a pre-multiplication with the current Quaternion. Mulitplication is done based on Hamilton's rules and result in (r = preMultiplier*q): r = p0*q0 - pVec.dot(qVec) + p0*qVec + q0*pVec + pVec X qVec
Parameters:
`preMultiplier` -
Returns:
Quaternion r = pq
• #### conjugate

`public Quaternion conjugate()`
Returns the complex conjugate of the Quaternion q.
Returns:
Quaternion q* = q0 - qVec
• #### getNorm

`public double getNorm()`
Returns the norm of the Quaternion q defined as N = sqrt(q*q)
Returns:
double N = sart(q0^2 + q1^2 + q2^2 + q3^2)
• #### normalize

`public void normalize()`
Normalizes the Quaternion q i.e. divides all components by the norm
• #### inverse

`public Quaternion inverse()`
Returns the inverse of the Quaternion q given by q^-1 = 1/(norm^2) * q*
Returns:
Quaternion q^-1
• #### rotateVector

`public void rotateVector(IVectorMutable v)`
Rotates the input vector by using the Quaternion rotation operator L(v) = qvq*. w = L(v) = qvq* = (2*q0^2 -1)v + 2*(qVec.dot(v))*qVec + 2*q0*(qVec X v)
Parameters:
`v` -
• #### rotateOrientation

`public void rotateOrientation(OrientationFull3D or)`
Rotates the input orientation by using the Quaternion rotation operator L(v) = qvq*. Rotates the two vectors that form the orientation.
Parameters:
`or` -
• #### toString

`public java.lang.String toString()`
Returns the string representation of the Quaternion q
Overrides:
`toString` in class `java.lang.Object`
Returns:
String