Package civitas.celestis.math.complex
Class Quaternions
java.lang.Object
civitas.celestis.math.complex.Quaternions
Contains utility methods related to quaternions.
-
Method Summary
Modifier and TypeMethodDescriptionstatic doubleangle(Quaternion q) Given a rotation quaternionq, this returns the angle of the rotation, in the context of axis/angle notation.static Vector3axis(Quaternion q) Given a rotation quaternionq, this returns the axis of the rotation.static Double4Given a rotation quaternionq, this returns an axis/angle pair denoting the rotation of the quaternion.static Double3Given a rotation quaternionq, this returns a tuple of doubles containing the pitch, yaw, and roll angles of the quaternion in pitch-yaw-roll order.static Quaternionfrom(double pitch, double yaw, double roll) Creates a new rotation quaternion from Euler angle representation.static QuaternionCreates a new quaternion from a 3x3 rotation matrix.static QuaternionCreates a new rotation quaternion from an axis/angle notation.static QuaternionCreates a new rotation quaternion from Euler angle representation.static QuaternionCreates a new rotation quaternion from an axis/angle notation.static Quaternionlerp(Quaternion s, Quaternion e, double t) Performs linear interpolation (LERP) between the starting valuesand the ending valuee.static Matrixmatrix(Quaternion q) Given a rotation quaternionq, this converts the rotation into a 3x3 rotation matrix.static doublepitch(Quaternion q) Given a rotation quaternionq, this returns the pitch of the rotation.static Quaternionrandom()Returns a random rotation quaternion.static doubleroll(Quaternion q) Given a rotation quaternionq, this returns the roll of this rotation.static Quaternionslerp(Quaternion start, Quaternion end, double t) Performs spherical linear interpolation (SLERP) between two quaternions.static doubleyaw(Quaternion q) Given a rotation quaternionq, this returns the yaw of the rotation.
-
Method Details
-
random
Returns a random rotation quaternion.- Returns:
- A random rotation quaternion
-
lerp
Performs linear interpolation (LERP) between the starting valuesand the ending valuee.- Parameters:
s- The starting valuee- The ending valuet- The interpolation parameter ([0, 1])- Returns:
- The interpolated value between the starting and ending values
sande
-
slerp
@Nonnull public static Quaternion slerp(@Nonnull Quaternion start, @Nonnull Quaternion end, double t) Performs spherical linear interpolation (SLERP) between two quaternions. This assumes that the input quaternions are already normalized.- Parameters:
start- The starting quaternionend- The end quaterniont- The interpolation parametert(0-1)- Returns:
- The interpolated quaternion
-
from
Creates a new rotation quaternion from Euler angle representation. This method uses the right-handed coordinate system.- Parameters:
pyr- A tuple of doubles containing the Euler angles in pitch-yaw-roll order- Returns:
- The constructed quaternion
-
from
Creates a new rotation quaternion from Euler angle representation. This method uses the right-handed coordinate system.- Parameters:
pitch- The pitch of the rotation in radians (rotation along X axis)yaw- The yaw of the rotation in radians (rotation along Y axis)roll- The roll of the rotation in radians (rotation along Z axis)- Returns:
- The constructed quaternion
-
eulerAngles
Given a rotation quaternionq, this returns a tuple of doubles containing the pitch, yaw, and roll angles of the quaternion in pitch-yaw-roll order.- Parameters:
q- The quaternion of which to get the Euler angles of- Returns:
- The Euler angles of the quaternion, denoted in radians
-
pitch
Given a rotation quaternionq, this returns the pitch of the rotation. Pitch is defined as rotation along the X axis, and follows a right-handed coordinate system.- Parameters:
q- The quaternion of which to get the pitch of- Returns:
- The pitch of the quaternion in radians
-
yaw
Given a rotation quaternionq, this returns the yaw of the rotation. Yaw is defined as rotation along the Y axis, and follows a right-handed coordinate system.- Parameters:
q- The quaternion of which to get the yaw of- Returns:
- The yaw of the quaternion in radians
-
roll
Given a rotation quaternionq, this returns the roll of this rotation. Roll is defined as rotation along the Z axis, and follows a right-handed coordinate system.- Parameters:
q- The quaternion of which to get the roll of- Returns:
- The roll of the quaternion in radians
-
from
Creates a new rotation quaternion from an axis/angle notation. This method uses the right-handed coordinate system.- Parameters:
axisAngle- The axis/angle representation of the rotation- Returns:
- The constructed quaternion
-
from
Creates a new rotation quaternion from an axis/angle notation. This method uses the right-handed coordinate system.- Parameters:
axis- The axis of rotation as a unit vectorangle- The angle of rotation in radians- Returns:
- The constructed quaternion
-
axisAngle
Given a rotation quaternionq, this returns an axis/angle pair denoting the rotation of the quaternion. Axis/angle notation follows the right-handed coordinate system. The W component represents the angle of rotation in radians, and the XYZ components represent the axis of rotation.- Parameters:
q- The quaternion of which to convert to axis/angle notation- Returns:
- The axis/angle representation of the quaternion
-
angle
Given a rotation quaternionq, this returns the angle of the rotation, in the context of axis/angle notation. Axis/angle notation follows the right-handed coordinate system.- Parameters:
q- The quaternion of which to get the angle of- Returns:
- The angle of rotation of the quaternion in radians
-
axis
Given a rotation quaternionq, this returns the axis of the rotation. If the quaternion represents no rotation (the Euclidean norm is nearly zero), this will return a fallback valueVector3.POSITIVE_Y.- Parameters:
q- The quaternion of which to get the axis of- Returns:
- The axis of rotation of the quaternion as a unit vector
-
from
Creates a new quaternion from a 3x3 rotation matrix.- Parameters:
m- The rotation matrix which represents the rotation- Returns:
- The constructed quaternion
- Throws:
IllegalArgumentException- When the matrix's dimensions is not 3x3
-
matrix
Given a rotation quaternionq, this converts the rotation into a 3x3 rotation matrix.- Parameters:
q- The quaternion of which to convert into a rotation matrix- Returns:
- The matrix representation of the provided quaternion
q
-