Rotation

class Rotation(quat: Quat)

Represents a rotation in three-dimensional space.

This class uses an internal unit quaternion (Quat) for robust and unambiguous representation of rotations, avoiding issues like gimbal lock inherent in Euler angles for complex interpolations.

It provides constructors from various representations like Euler angles (EulerAngles), axis-angle, and quaternions. Properties allow accessing the rotation as a quaternion, axis-angle (angle in radians), or converting to Euler angles. Operations include composition, inversion, and spherical linear interpolation (Slerp).

Parameters

quat

The initial quaternion to create the rotation from. It does not need to be a unit quaternion, as it will be normalized internally.

Constructors

Link copied to clipboard
constructor(quat: Quat)
constructor(eulerAngles: EulerAngles)

Creates a Rotation from Euler angles specified in a EulerAngles object. Assumes EulerAngles angles (pitch, yaw, roll) are in degrees and correspond to a specific Euler rotation sequence (e.g., intrinsic ZYX for roll, new Y for yaw, newest X for pitch) handled by EulerAngles.toQuat().

constructor(angle: Float, axis: Vector3)

Creates a Rotation from an angle (in radians) and an axis of rotation. The axis vector will be normalized if it's not already a unit vector by the Quat constructor.

Types

Link copied to clipboard
object Companion

Companion object providing utilities for rotation operations.

Properties

Link copied to clipboard
val angle: Float

The angle of rotation in degrees, in the range [0, 180].

Link copied to clipboard

The normalized axis of rotation. For an identity rotation (zero angle), a default axis (e.g., Z-axis) may be returned.

Link copied to clipboard

Gets the euler angle representation of this rotation as a EulerAngles object.

Link copied to clipboard

The inverse of this rotation. For a unit quaternion, this is its conjugate.

Link copied to clipboard
val isIdentity: Boolean

A boolean value that indicates whether this rotation is effectively an identity rotation (no rotation). Checks if the scalar part w of the internal quaternion is close to +/-1 and the vector part (x,y,z) is close to zero, within EPSILON(1e-6f) and EPSILON_SQ(1e-12f) tolerances.

Link copied to clipboard

The internal unit quaternion that represents this rotation.

Functions

Link copied to clipboard
operator fun times(other: Rotation): Rotation

Combines this rotation with another rotation other. The result this * other represents applying the rotation other first, then applying this rotation. The resulting quaternion is normalized to counteract potential floating-point drift.