Class Quaternion
- All Implemented Interfaces:
Comparable<Quaternion>, Field<Scalar<Quaternion>>, Group, Group.Additive<Scalar<Quaternion>>, Group.Multiplicative<Scalar<Quaternion>>, NormedVectorSpace<Scalar<Quaternion>, Quaternion>, Operation, Operation.Addition<Scalar<Quaternion>>, Operation.Division<Scalar<Quaternion>>, Operation.Multiplication<Scalar<Quaternion>>, Operation.Subtraction<Scalar<Quaternion>>, Ring<Scalar<Quaternion>>, ScalarOperation, ScalarOperation.Addition<Scalar<Quaternion>, Quaternion>, ScalarOperation.Division<Scalar<Quaternion>, Quaternion>, ScalarOperation.Multiplication<Scalar<Quaternion>, Quaternion>, ScalarOperation.Subtraction<Scalar<Quaternion>, Quaternion>, VectorSpace<Scalar<Quaternion>, Quaternion>, Scalar<Quaternion>, SelfDeclaringScalar<Quaternion>, Access1D<Double>, Access2D<Double>, Access2D.Collectable<Double,Mutate2D>, AccessScalar<Quaternion>, Structure1D, Structure2D, Transformation2D<Double>, Tensor<Quaternion, Scalar<Quaternion>>, NumberContext.Enforceable<Quaternion>, NumberDefinition
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface Access2D
Access2D.Aggregatable<N>, Access2D.Collectable<N,R>, Access2D.ColumnView<N>, Access2D.ElementView<N>, Access2D.RowView<N>, Access2D.SelectionView<N>, Access2D.Sliceable<N>, Access2D.Visitable<N> Nested classes/interfaces inherited from interface Group
Group.Additive<T>, Group.Multiplicative<T>Nested classes/interfaces inherited from interface Operation
Operation.Addition<T>, Operation.Division<T>, Operation.Multiplication<T>, Operation.Subtraction<T>Nested classes/interfaces inherited from interface Scalar
Scalar.Factory<N>Nested classes/interfaces inherited from interface ScalarOperation
ScalarOperation.Addition<T,N>, ScalarOperation.Division<T, N>, ScalarOperation.Multiplication<T, N>, ScalarOperation.Subtraction<T, N> Nested classes/interfaces inherited from interface Structure1D
Structure1D.BasicMapper<T>, Structure1D.IndexMapper<T>, Structure1D.IntIndex, Structure1D.Logical<S,B>, Structure1D.LongIndex, Structure1D.LoopCallback Nested classes/interfaces inherited from interface Structure2D
Structure2D.IntRowColumn, Structure2D.Logical<S,B>, Structure2D.LongRowColumn, Structure2D.ReducibleTo1D<R>, Structure2D.Reshapable, Structure2D.RowColumnKey<R, C>, Structure2D.RowColumnMapper<R, C> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final doublestatic final Scalar.Factory<Quaternion> final doublestatic final Quaternionstatic final Quaternionstatic final Quaternionfinal doublestatic final Quaternionfinal doublestatic final Quaternionprivate final booleanprivate final booleanprivate final doublestatic final Quaternionstatic final Quaternionstatic final Quaternionstatic final Quaternionstatic final Quaternion -
Constructor Summary
ConstructorsModifierConstructorDescription(package private)Quaternion(double scalar) privateQuaternion(double[] vector) privateQuaternion(double scalar, double[] vector) (package private)Quaternion(double i, double j, double k) (package private)Quaternion(double scalar, double i, double j, double k) -
Method Summary
Modifier and TypeMethodDescriptionadd(double arg) add(Quaternion arg) doubleangle()private doubleprivate doubleintcompareTo(Quaternion other) First compares the real values.This method will (most likely) be moved to some other interface in the future! Just have to figure out where it fits...longcount()count() == countRows() * countColumns()longOnly need to implement if the structure may contain more than Integer.MAX_VALUE elements.longOnly need to implement if the structure may contain more than Integer.MAX_VALUE elements.divide(double arg) divide(Quaternion arg) Will calculatethis * reciprocal(arg)which is not the same asreciprocal(arg) * this.doubledoubledoubleValue(int index) doubledoubleValue(int row, int col) Extracts one element of this matrix as a double.enforce(NumberContext context) booleanfloatget()get(long index) get(long row, long col) intdoubleThe fourth power of the norm of a quaternion is the determinant of the corresponding matrix.intdoubleinthashCode()intintValue()invert()The multiplicative inverse.booleanstatic booleanisAbsolute(Quaternion value) static booleanisInfinite(Quaternion value) static booleanisNaN(Quaternion value) booleanisPure()booleanisReal()static booleanisReal(Quaternion value) booleanisSmall(double comparedTo) static booleanisSmall(double comparedTo, Quaternion value) booleanisZero()Tests if this scalar value is exactly zero.longstatic QuaternionmakePolar(double norm, double[] unit, double angle) static QuaternionmakeRotation(Quaternion.RotationAxis axis, double angle) Create aQuaternionthat captures a rotation about the provided axis by the provided angle.multiply(double arg) multiply(Quaternion arg) negate()The additive inverse of this.doublenorm()this == this.signum().multiply(this.norm())static Quaternionof(double i, double j, double k) static Quaternionof(double scalar, double i, double j, double k) power(int power) Multiply by itselfpowertimes.doublescalar()signum()this == this.signum().multiply(this.norm())subtract(double arg) subtract(Quaternion arg) void(package private) MatrixStore<Double> toString()toString(NumberContext context) <T extends Mutate2D.ModifiableReceiver<Double>>
voidtransform(T transformable) (package private) <T extends Mutate2D.ModifiableReceiver<Double>>
voidtransformVersor(T transformable) double[]unit()static QuaternionvalueOf(double value) static QuaternionvalueOf(Comparable<?> number) vector()versor()Methods inherited from interface Access1D
asCollectable1D, asKeyed1D, asList, axpy, dot, select, supplyTo, toList, toRawCopy1DMethods inherited from interface Access2D
asCollectable2D, asKeyed2D, byteValue, byteValue, byteValue, byteValue, columns, columns, columns, doubleValue, doubleValue, elements, floatValue, floatValue, floatValue, floatValue, intValue, intValue, intValue, intValue, longValue, longValue, longValue, longValue, nonzeros, rows, rows, rows, select, select, shortValue, shortValue, shortValue, shortValue, toRawCopy2DMethods inherited from interface Access2D.Collectable
collectMethods inherited from interface NumberDefinition
booleanValue, byteValue, shortValueMethods inherited from interface Scalar
add, dimensions, divide, multiply, rank, subtract, toPlainStringMethods inherited from interface SelfDeclaringScalar
add, divide, multiply, subtractMethods inherited from interface Structure2D
firstInColumn, firstInRow, getMaxDim, getMinDim, isEmpty, isFat, isScalar, isSquare, isTall, isVector, limitOfColumn, limitOfRow, sizeMethods inherited from interface Tensor
components, isSameShape
-
Field Details
-
FACTORY
-
I
-
IJK
-
INFINITY
-
J
-
K
-
NaN
-
NEG
-
ONE
-
TWO
-
ZERO
-
ARGUMENT_TOLERANCE
private static final double ARGUMENT_TOLERANCE -
i
public final double i -
j
public final double j -
k
public final double k -
myPureForSure
private final boolean myPureForSure -
myRealForSure
private final boolean myRealForSure -
myScalar
private final double myScalar
-
-
Constructor Details
-
Quaternion
public Quaternion() -
Quaternion
private Quaternion(double scalar, double[] vector) -
Quaternion
private Quaternion(double[] vector) -
Quaternion
Quaternion(double scalar) -
Quaternion
Quaternion(double i, double j, double k) -
Quaternion
Quaternion(double scalar, double i, double j, double k)
-
-
Method Details
-
isAbsolute
-
isInfinite
-
isNaN
-
isReal
-
isSmall
-
makePolar
-
makeRotation
Create aQuaternionthat captures a rotation about the provided axis by the provided angle.The quaternion representation of the rotation may be expressed as:
q = cos(θ / 2) + sin(θ / 2) * (ub * i + uc * j + ud * k)
where θ is the angle of rotation and[ub, uc, ud]
is the axis of rotation. This method accepts a single axis, so only a single imaginary component is populated.To rotate in multiple axes, multiply multiple quaternions:
This creates a rotation in ZYX order.Quaternion xRotation = Quaternion.makeRotation(RotationAxis.X, Math.toRadians(-3)); Quaternion yRotation = Quaternion.makeRotation(RotationAxis.Y, Math.toRadians(2)); Quaternion zRotation = Quaternion.makeRotation(RotationAxis.Z, Math.toRadians(45)); Quaternion zyxRotation = zRotation.multiply(yRotation).multiply(xRotation);- Parameters:
axis- the axis to rotate about, non-nullangle- the angle, in radians to rotate about the axis- Returns:
- the quaternion
-
of
-
of
-
valueOf
-
valueOf
-
add
- Specified by:
addin interfaceScalarOperation.Addition<Scalar<Quaternion>, Quaternion>- Specified by:
addin interfaceSelfDeclaringScalar<Quaternion>- Returns:
this + scalarAddend.
-
add
- Specified by:
addin interfaceScalarOperation.Addition<Scalar<Quaternion>, Quaternion>- Specified by:
addin interfaceSelfDeclaringScalar<Quaternion>- Returns:
this + scalarAddend.
-
angle
public double angle() -
compareTo
First compares the real values. Only if they are equal will compare the imaginary part.- Specified by:
compareToin interfaceComparable<Quaternion>
-
conjugate
Description copied from interface:VectorSpaceThis method will (most likely) be moved to some other interface in the future! Just have to figure out where it fits...
The conjugate transpose of a matrix and/or the conjugate of a scalar/field like ComplexNumber or Quaternion.
The conjugate transpose of a real matrix is simply its transpose.
- Specified by:
conjugatein interfaceSelfDeclaringScalar<Quaternion>- Specified by:
conjugatein interfaceVectorSpace<Scalar<Quaternion>, Quaternion>
-
count
public long count()Description copied from interface:Structure2Dcount() == countRows() * countColumns()- Specified by:
countin interfaceStructure1D- Specified by:
countin interfaceStructure2D
-
countColumns
public long countColumns()Description copied from interface:Structure2DOnly need to implement if the structure may contain more than Integer.MAX_VALUE elements.- Specified by:
countColumnsin interfaceStructure2D- Returns:
- The number of columns
-
countRows
public long countRows()Description copied from interface:Structure2DOnly need to implement if the structure may contain more than Integer.MAX_VALUE elements.- Specified by:
countRowsin interfaceStructure2D- Returns:
- The number of rows
-
divide
- Specified by:
dividein interfaceScalarOperation.Division<Scalar<Quaternion>, Quaternion>- Specified by:
dividein interfaceSelfDeclaringScalar<Quaternion>- Returns:
this / scalarDivisor.
-
divide
Will calculatethis * reciprocal(arg)which is not the same asreciprocal(arg) * this.- Specified by:
dividein interfaceScalarOperation.Division<Scalar<Quaternion>, Quaternion>- Specified by:
dividein interfaceSelfDeclaringScalar<Quaternion>- Returns:
this / scalarDivisor.
-
doubleValue
public double doubleValue()- Specified by:
doubleValuein interfaceNumberDefinition
-
doubleValue
public double doubleValue(int index) - Specified by:
doubleValuein interfaceAccess1D<Double>- Specified by:
doubleValuein interfaceAccess2D<Double>
-
doubleValue
public double doubleValue(int row, int col) Description copied from interface:Access2DExtracts one element of this matrix as a double.- Specified by:
doubleValuein interfaceAccess2D<Double>- Parameters:
row- A row index.col- A column index.- Returns:
- One matrix element
-
enforce
- Specified by:
enforcein interfaceNumberContext.Enforceable<Quaternion>
-
equals
-
floatValue
public float floatValue()- Specified by:
floatValuein interfaceNumberDefinition
-
get
- Specified by:
getin interfaceAccessScalar<Quaternion>
-
get
-
get
-
getColDim
public int getColDim()- Specified by:
getColDimin interfaceStructure2D- Returns:
- The number of columns
-
getDeterminant
public double getDeterminant()The fourth power of the norm of a quaternion is the determinant of the corresponding matrix. -
getPureVersor
- Returns:
- A normalised Quaternion with the real/scalar part "removed".
-
getRowDim
public int getRowDim()- Specified by:
getRowDimin interfaceStructure2D- Returns:
- The number of rows
-
getVectorLength
public double getVectorLength() -
hashCode
-
intValue
public int intValue()- Specified by:
intValuein interfaceNumberDefinition
-
invert
Description copied from interface:Group.MultiplicativeThe multiplicative inverse.- Specified by:
invertin interfaceGroup.Multiplicative<Scalar<Quaternion>>- Specified by:
invertin interfaceSelfDeclaringScalar<Quaternion>- Returns:
IDENTITY / this.
-
isAbsolute
public boolean isAbsolute()- Specified by:
isAbsolutein interfaceScalar<Quaternion>- Returns:
- true if this is equal to its own norm, modulus or absolute value (non-negative real part and no imaginary part); otherwise false.
- See Also:
-
isPure
public boolean isPure() -
isReal
public boolean isReal() -
isSmall
public boolean isSmall(double comparedTo) - Specified by:
isSmallin interfaceNormedVectorSpace<Scalar<Quaternion>, Quaternion>- Parameters:
comparedTo- What to compare with- Returns:
- true if this is small compared to the magnitude of the input reference value.
-
isZero
public boolean isZero()Description copied from interface:ScalarTests if this scalar value is exactly zero.Each implementation should test for zero as exactly as possible based on what's achievable with that specific scalar type. The purpose is NOT to have similar behavior between different implementations, but rather to leverage the full precision and capabilities of each type.
For example:
- Primitive types (like
double) should use exact equality comparison - High-precision types (like
Quadruple) should check both base and remainder components - Arbitrary-precision types (like
BigDecimal) should use their built-in zero detection - Complex types should check both real and imaginary parts
This method should NOT use tolerance-based comparisons or approximate zero detection, as those are better handled by context-aware methods like
NormedVectorSpace.isSmall(double).- Specified by:
isZeroin interfaceScalar<Quaternion>- Returns:
- true if this scalar represents exactly zero, false otherwise
- See Also:
- Primitive types (like
-
longValue
public long longValue()- Specified by:
longValuein interfaceNumberDefinition
-
multiply
- Specified by:
multiplyin interfaceScalarOperation.Multiplication<Scalar<Quaternion>, Quaternion>- Specified by:
multiplyin interfaceSelfDeclaringScalar<Quaternion>- Returns:
this * scalarMultiplicand.
-
multiply
- Specified by:
multiplyin interfaceScalarOperation.Multiplication<Scalar<Quaternion>, Quaternion>- Specified by:
multiplyin interfaceSelfDeclaringScalar<Quaternion>- Returns:
this * multiplicand.
-
negate
Description copied from interface:Group.AdditiveThe additive inverse of this.- Specified by:
negatein interfaceGroup.Additive<Scalar<Quaternion>>- Specified by:
negatein interfaceSelfDeclaringScalar<Quaternion>- Returns:
-this.
-
norm
public double norm()Description copied from interface:NormedVectorSpacethis == this.signum().multiply(this.norm())- Specified by:
normin interfaceNormedVectorSpace<Scalar<Quaternion>, Quaternion>- Returns:
- The norm
-
power
Description copied from interface:Operation.MultiplicationMultiply by itselfpowertimes.- Specified by:
powerin interfaceOperation.Multiplication<Scalar<Quaternion>>- Specified by:
powerin interfaceSelfDeclaringScalar<Quaternion>
-
scalar
public double scalar() -
signum
Description copied from interface:NormedVectorSpacethis == this.signum().multiply(this.norm())- Specified by:
signumin interfaceNormedVectorSpace<Scalar<Quaternion>, Quaternion>- Specified by:
signumin interfaceSelfDeclaringScalar<Quaternion>- Returns:
- A unit "vector"
-
subtract
- Specified by:
subtractin interfaceScalarOperation.Subtraction<Scalar<Quaternion>, Quaternion>- Specified by:
subtractin interfaceSelfDeclaringScalar<Quaternion>- Returns:
this - scalarSubtrahend.
-
subtract
- Specified by:
subtractin interfaceScalarOperation.Subtraction<Scalar<Quaternion>, Quaternion>- Specified by:
subtractin interfaceSelfDeclaringScalar<Quaternion>- Returns:
this - scalarSubtrahend.
-
supplyTo
- Specified by:
supplyToin interfaceAccess2D.Collectable<Double,Mutate2D>
-
toBigDecimal
- Specified by:
toBigDecimalin interfaceScalar<Quaternion>
-
toComplexMatrix
-
toMultiplicationMatrix
-
toMultiplicationVector
-
toRotationMatrix
-
toString
-
toString
- Specified by:
toStringin interfaceScalar<Quaternion>
-
transform
- Specified by:
transformin interfaceTransformation2D<Double>
-
unit
public double[] unit() -
vector
-
versor
-
calculateSumOfSquaresAll
private double calculateSumOfSquaresAll() -
calculateSumOfSquaresVector
private double calculateSumOfSquaresVector() -
toRotationMatrixVersor
MatrixStore<Double> toRotationMatrixVersor() -
transformVersor
-