Package util
Class Quaternion
java.lang.Object
util.Quaternion
-
Field Summary
-
Constructor Summary
ConstructorDescriptionCreates an identity quaternion: all components are zero exceptx0
, which is set to 1.Quaternion
(double[] angles) Creates a quaternion from Tait-Bryan angles, applying the rotations in x-z-y extrinsic order or y-z'-x" intrinsic order.Quaternion
(double w, double x, double y, double z) Creates a quaternion with the specified components.Quaternion
(Matrix3D matrix) -
Method Summary
Modifier and TypeMethodDescriptionboolean
fromDegreeAngles
(double[] angles) Sets the quaternion from the specified Tait-Bryan angles, applying the rotations in x-z-y extrinsic order or y-z'-x" intrinsic order.fromDegreeAngles
(double xAngle, double yAngle, double zAngle) Sets the quaternion from three angles in degreefromRadiansAngles
(double[] angles) Sets the quaternion from the specified Tait-Bryan angles, applying the rotations in x-z-y extrinsic order or y-z'-x" intrinsic order.fromRadiansAngles
(double xAngle, double yAngle, double zAngle) Sets the quaternion from the specified Tait-Bryan angles, applying the rotations in x-z-y extrinsic order or y-z'-x" intrinsic order.fromRotationMatrix
(Matrix3D matrix) Sets the quaternion from a rotation matrix with the specified elements.double
getW()
Returns the w (real) component.double
getX()
Returns the x component.double
getY()
Returns the y component.double
getZ()
Returns the z component.int
hashCode()
boolean
Compares with the identity quaternion, without distinguishing -0 from 0.void
Sets all components to zero exceptw
, which is set to 1.double
norm()
Returns the norm, defined as the dot product of the quaternion with itself.set
(double w, double x, double y, double z) Sets all 4 components to specified values.set
(Quaternion q) Copies all 4 components from another quaternion.slerp
(Quaternion q1, Quaternion q2, float t) Interpolates between the specified quaternions and stores the result in the current instance.Subtracts the argument and returns difference as a new instance.double[]
toDegreesAngles
(double[] angles) Converts to equivalent Tait-Bryan angles in degreedouble[]
toRadiansAngles
(double[] angles) Converts to equivalent Tait-Bryan angles, to be applied in x-z-y intrinsic order or y-z'-x" extrinsic order, for instance byfromRadiansAngles(double[])
(double[])}.Converts to an equivalent rotation matrix.toString()
Helper function to print the values of the quaternion
-
Field Details
-
w
protected double wThe real component (x0). -
x
protected double xThe 1st imaginary component (x1). -
y
protected double yThe 2nd imaginary component (x2). -
z
protected double zThe 3rd imaginary component (x3).
-
-
Constructor Details
-
Quaternion
public Quaternion()Creates an identity quaternion: all components are zero exceptx0
, which is set to 1. -
Quaternion
public Quaternion(double w, double x, double y, double z) Creates a quaternion with the specified components.- Parameters:
w
- the x0 componentx
- the x1 componenty
- the x2 componentz
- the x3 component
-
Quaternion
public Quaternion(double[] angles) Creates a quaternion from Tait-Bryan angles, applying the rotations in x-z-y extrinsic order or y-z'-x" intrinsic order.- Parameters:
angles
- an array of Tait-Bryan angles (in degree, exactly 3 elements, the X angle inangles[0]
, the Y angle inangles[1]
, and the Z angle inangles[2]
, not null, unaffected)
-
Quaternion
-
-
Method Details
-
getW
public double getW()Returns the w (real) component.- Returns:
- the value of the
w
component
-
getX
public double getX()Returns the x component.- Returns:
- the value of the
x
component
-
getY
public double getY()Returns the y component.- Returns:
- the value of the
y
component
-
getZ
public double getZ()Returns the z component.- Returns:
- the value of the
z
component
-
set
Sets all 4 components to specified values.- Parameters:
w
- the w (real) componentx
- the x componenty
- the y componentz
- the z component- Returns:
- the (modified) current instance
-
set
Copies all 4 components from another quaternion.- Parameters:
q
- the quaternion to copy (not null, unaffected)- Returns:
- the (modified) current instance
-
makeIdentityQuaternion
public void makeIdentityQuaternion()Sets all components to zero exceptw
, which is set to 1. -
isIdentity
public boolean isIdentity()Compares with the identity quaternion, without distinguishing -0 from 0. The current instance is unaffected.- Returns:
- true if the current quaternion equals the identity, otherwise false
-
fromRadiansAngles
Sets the quaternion from the specified Tait-Bryan angles, applying the rotations in x-z-y extrinsic order or y-z'-x" intrinsic order.- Parameters:
angles
- an array of Tait-Bryan angles (in radians, exactly 3 elements, the X angle inangles[0]
, the Y angle inangles[1]
, and the Z angle inangles[2]
, not null, unaffected)- Returns:
- the (modified) current instance (for chaining)
- Throws:
IllegalArgumentException
- ifangles.length != 3
-
fromDegreeAngles
Sets the quaternion from the specified Tait-Bryan angles, applying the rotations in x-z-y extrinsic order or y-z'-x" intrinsic order.- Parameters:
angles
- an array of Tait-Bryan angles (in degree, exactly 3 elements, the X angle inangles[0]
, the Y angle inangles[1]
, and the Z angle inangles[2]
, not null, unaffected)- Returns:
- the (modified) current instance (for chaining)
- Throws:
IllegalArgumentException
- ifangles.length != 3
-
fromRadiansAngles
Sets the quaternion from the specified Tait-Bryan angles, applying the rotations in x-z-y extrinsic order or y-z'-x" intrinsic order.- Parameters:
xAngle
- the X angle (in radians)yAngle
- the Y angle (in radians)zAngle
- the Z angle (in radians)- Returns:
- the (modified) current instance (for chaining)
- See Also:
-
fromDegreeAngles
Sets the quaternion from three angles in degree- Parameters:
xAngle
- the X angle (in degree)yAngle
- the Y angle (in degree)zAngle
- the Z angle (in degree)- Returns:
- the (modified) current instance (for chaining)
-
toRadiansAngles
public double[] toRadiansAngles(double[] angles) Converts to equivalent Tait-Bryan angles, to be applied in x-z-y intrinsic order or y-z'-x" extrinsic order, for instance byfromRadiansAngles(double[])
(double[])}. The current instance is unaffected.- Parameters:
angles
- storage for the result, or null for a new float[3]- Returns:
- an array of 3 angles (in radians, either
angles
or a new float[3], the X angle in angles[0], the Y angle in angles[1], and the Z angle in angles[2]) - Throws:
IllegalArgumentException
- ifangles.length != 3
- See Also:
-
toDegreesAngles
public double[] toDegreesAngles(double[] angles) Converts to equivalent Tait-Bryan angles in degree- Parameters:
angles
- storage for the result, or null for a new float[3]- Returns:
- an array of 3 angles (in degree)
-
fromRotationMatrix
Sets the quaternion from a rotation matrix with the specified elements.- Parameters:
matrix
- a Matrix3D object- Returns:
- the (modified) current instance (for chaining)
-
toRotationMatrix
Converts to an equivalent rotation matrix. The current instance is unaffected.Note: the result is created from a normalized version..
- Returns:
result
, configured as a 3x3 rotation matrix
-
norm
public double norm()Returns the norm, defined as the dot product of the quaternion with itself. The current instance is unaffected.- Returns:
- the sum of the squared components (not negative)
-
subtract
Subtracts the argument and returns difference as a new instance. The current instance is unaffected.- Parameters:
q
- the quaternion to subtract (not null, unaffected)- Returns:
- a new Quaternion
-
slerp
Interpolates between the specified quaternions and stores the result in the current instance.- Parameters:
q1
- the desired value when interp=0 (not null, unaffected)q2
- the desired value when interp=1 (not null, may be modified)t
- the fractional change amount- Returns:
- the (modified) current instance (for chaining)
-
toString
Helper function to print the values of the quaternion -
equals
-
hashCode
public int hashCode()
-