Package civitas.celestis.math.complex
Class Quaternion
java.lang.Object
civitas.celestis.util.tuple.Double4
civitas.celestis.math.complex.Quaternion
- All Implemented Interfaces:
BaseTuple<Double>,DoubleTuple,Serializable
A complex number with three imaginary parts. Quaternions are used to
describe the rotational motion of three-dimensional vectors.
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionQuaternion(double[] components) Creates a new quaternion.Quaternion(double w, double x, double y, double z) Creates a new quaternion.Quaternion(double s, Double3 v) Creates a new quaternion.Creates a new quaternion. -
Method Summary
Modifier and TypeMethodDescriptionadd(double s) Adds a scalar to this quaternion, then returns the resulting quaternion.add(Quaternion q) Adds another quaternion to this quaternion, then returns the resulting quaternion.Returns the conjugate of this quaternion.divide(double s) Divides this quaternion by a scalar, then returns the resulting quaternion.doubledot(Quaternion q) Returns the dot product between this quaternion and the provided quaternionq.inverse()Returns the inverse of this quaternion.multiply(double s) Multiplies this quaternion by a scalar, then returns the resulting quaternion.Multiplies this quaternion by the provided quaternionq.negate()Negates this quaternion, then returns the negated quaternion.doublenorm()Returns the Euclidean norm (the magnitude) of this quaternion.doublenorm2()Returns the squared Euclidean norm (the squared magnitude) of this quaternion.Normalizes this quaternion to have a Euclidean norm (magnitude) of1.Normalizes this quaternion to have a Euclidean norm (magnitude) of1.Normalizes this quaternion to have a Euclidean norm (magnitude) of1.doublescalar()Returns the scalar part of this quaternion.scale(double s) Scales the rotation of this quaternion, then returns the resulting quaternion.subtract(double s) Subtracts this quaternion by a scalar, then returns the resulting quaternion.Subtracts this quaternion by another quaternion, then returns the resulting quaternion.vector()Returns the vector part of this quaternion.Methods inherited from class civitas.celestis.util.tuple.Double4
array, boxed, contains, containsAll, equals, get, hashCode, isFinite, isInfinite, isNaN, isZero, list, map, mapToObj, size, stream, toString, w, x, y, zMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface civitas.celestis.util.tuple.DoubleTuple
doubleArray
-
Field Details
-
IDENTITY
The identity quaternion. This will produce no rotation.
-
-
Constructor Details
-
Quaternion
public Quaternion(double w, double x, double y, double z) Creates a new quaternion.- Parameters:
w- The W component of this quaternionx- The X component of this quaterniony- The Y component of this quaternionz- The Z component of this quaternion
-
Quaternion
Creates a new quaternion.- Parameters:
s- The scalar part of this quaternionv- The vector part of this quaternion
-
Quaternion
public Quaternion(@Nonnull double[] components) Creates a new quaternion.- Parameters:
components- An array containing the component of this quaternion in WXYZ order- Throws:
IllegalArgumentException- When the provided array's length is not4
-
Quaternion
Creates a new quaternion.- Parameters:
t- The tuple of which to copy component values from- Throws:
IllegalArgumentException- When the provided tuplet's size is not4
-
-
Method Details
-
norm
public double norm()Returns the Euclidean norm (the magnitude) of this quaternion.- Returns:
- The Euclidean norm of this quaternion
-
norm2
public double norm2()Returns the squared Euclidean norm (the squared magnitude) of this quaternion.- Returns:
- The squared Euclidean norm of this quaternion
-
scalar
public double scalar()Returns the scalar part of this quaternion.- Returns:
- The scalar part of this quaternion
-
vector
Returns the vector part of this quaternion.- Returns:
- The vector part of this quaternion
-
add
Adds a scalar to this quaternion, then returns the resulting quaternion.- Parameters:
s- The scalar of which to add to this quaternion- Returns:
- The resulting quaternion
-
subtract
Subtracts this quaternion by a scalar, then returns the resulting quaternion.- Parameters:
s- The scalar of which to subtract this quaternion by- Returns:
- The resulting quaternion
-
scale
Scales the rotation of this quaternion, then returns the resulting quaternion. This will only work properly if this quaternion is a rotation quaternion. (a quaternion with a Euclidean norm of1)- Parameters:
s- The scale factor to apply to the rotation- Returns:
- The scaled quaternion
-
multiply
Multiplies this quaternion by a scalar, then returns the resulting quaternion.- Parameters:
s- The scalar of which to multiply this quaternion by- Returns:
- The resulting quaternion
-
divide
Divides this quaternion by a scalar, then returns the resulting quaternion.- Parameters:
s- The scalar of which to divide this quaternion by- Returns:
- The resulting quaternion
- Throws:
ArithmeticException- When the denominatorsis zero
-
add
Adds another quaternion to this quaternion, then returns the resulting quaternion.- Parameters:
q- The quaternion of which to add to this quaternion- Returns:
- The resulting quaternion
-
subtract
Subtracts this quaternion by another quaternion, then returns the resulting quaternion.- Parameters:
q- The quaternion of which to subtract from this quaternion- Returns:
- The resulting quaternion
-
multiply
Multiplies this quaternion by the provided quaternionq.- Parameters:
q- The quaternion of which to multiply this quaternion by- Returns:
- The quaternion left-product of the two quaternions
-
dot
Returns the dot product between this quaternion and the provided quaternionq.- Parameters:
q- The quaternion of which to get the dot product between- Returns:
- The dot product of the two quaternions
-
conjugate
Returns the conjugate of this quaternion.- Returns:
- The conjugate of this quaternion
-
inverse
Returns the inverse of this quaternion.- Returns:
- The inverse of this quaternion
- Throws:
ArithmeticException- When the squared Euclidean norm (the squared magnitude) of this quaternion is zero
-
negate
Negates this quaternion, then returns the negated quaternion.- Returns:
- The negation of this quaternion
-
normalize
Normalizes this quaternion to have a Euclidean norm (magnitude) of1.- Returns:
- The normalized quaternion of this quaternion
- Throws:
ArithmeticException- When the Euclidean norm of this quaternion is zero
-
normalizeOrIdentity
Normalizes this quaternion to have a Euclidean norm (magnitude) of1. If this quaternion has no direction (the Euclidean norm is zero), this will the identity quaternion. (IDENTITY)- Returns:
- The normalized quaternion of this quaternion if successful,
the identity quaternionotherwise
-
normalizeOrDefault
Normalizes this quaternion to have a Euclidean norm (magnitude) of1. If this quaternion has no direction (the Euclidean norm is zero), this will return the provided fallback valueqinstead of throwing an exception.- Parameters:
q- The fallback value to default to when normalization is impossible- Returns:
- The normalized quaternion of this quaternion if successful, the fallback value otherwise
-