pub struct Quat<Unit: Copy = (), Space: Copy = ()> {
pub x: f32,
pub y: f32,
pub z: f32,
pub w: f32,
/* private fields */
}Expand description
Quaternion with type-level unit and coordinate space
Fields§
§x: f32§y: f32§z: f32§w: f32Implementations§
Source§impl<Unit: Copy, Space: Copy> Quat<Unit, Space>
impl<Unit: Copy, Space: Copy> Quat<Unit, Space>
pub const IDENTITY: Self
pub const ZERO: Self
pub const fn new(x: f32, y: f32, z: f32, w: f32) -> Self
Sourcepub const fn from_vec4(v: Vec4<Unit, Space>) -> Self
pub const fn from_vec4(v: Vec4<Unit, Space>) -> Self
Creates a quaternion from a Vec4 (x, y, z, w components).
Sourcepub const fn xyz(self) -> Vec3<Unit, Space>
pub const fn xyz(self) -> Vec3<Unit, Space>
Returns the vector part (x, y, z) of the quaternion.
Sourcepub fn from_axis_angle_radians(axis: Vec3<Unit, Space>, angle: Radians) -> Self
pub fn from_axis_angle_radians(axis: Vec3<Unit, Space>, angle: Radians) -> Self
Creates a quaternion from an axis and an angle (typed radians).
Sourcepub fn from_unit_axis_angle_radians(
axis: UnitVec3<Unit, Space>,
angle: Radians,
) -> Self
pub fn from_unit_axis_angle_radians( axis: UnitVec3<Unit, Space>, angle: Radians, ) -> Self
Creates a quaternion from a unit axis and a typed radians angle.
This is the “invariant-preserving” variant: the type system guarantees the axis is normalized.
Sourcepub fn from_unit_axis_angle_deg(
axis: UnitVec3<Unit, Space>,
angle: Degrees,
) -> Self
pub fn from_unit_axis_angle_deg( axis: UnitVec3<Unit, Space>, angle: Degrees, ) -> Self
Creates a quaternion from a unit axis and a typed degrees angle.
Sourcepub fn from_axis_angle_deg(axis: Vec3<Unit, Space>, angle: Degrees) -> Self
pub fn from_axis_angle_deg(axis: Vec3<Unit, Space>, angle: Degrees) -> Self
Creates a quaternion from an axis and an angle (typed degrees).
Sourcepub fn from_euler_angles_radians(
pitch: Radians,
yaw: Radians,
roll: Radians,
) -> Self
pub fn from_euler_angles_radians( pitch: Radians, yaw: Radians, roll: Radians, ) -> Self
Creates a quaternion from Euler angles (pitch, yaw, roll) in radians. Matches the yaw -> pitch -> roll order.
Sourcepub fn from_euler_angles_deg(
pitch: Degrees,
yaw: Degrees,
roll: Degrees,
) -> Self
pub fn from_euler_angles_deg( pitch: Degrees, yaw: Degrees, roll: Degrees, ) -> Self
Creates a quaternion from Euler angles (pitch, yaw, roll) in typed degrees.
Sourcepub const fn length_squared(self) -> f32
pub const fn length_squared(self) -> f32
Calculates the squared length (magnitude) of the quaternion.
Sourcepub fn normalize(self) -> Self
pub fn normalize(self) -> Self
Normalizes the quaternion.
If the length is zero, returns Quat::zero().
Sourcepub fn try_normalize(self) -> Option<Self>
pub fn try_normalize(self) -> Option<Self>
Normalizes the quaternion, returning None if the length is zero.
Sourcepub fn inverse(self) -> Option<Self>
pub fn inverse(self) -> Option<Self>
Calculates the inverse of the quaternion.
Returns None if the quaternion’s length is zero (cannot be inverted).
Sourcepub fn try_inverse(self) -> Option<Self>
pub fn try_inverse(self) -> Option<Self>
Alias for Quat::inverse.
Sourcepub fn checked_div_scalar(self, rhs: f32) -> Option<Self>
pub fn checked_div_scalar(self, rhs: f32) -> Option<Self>
Divides this quaternion by a scalar, returning None for invalid divisors.
Returns None if rhs is zero (including -0.0) or non-finite (NaN, ±inf).
Sourcepub fn to_axis_angle(self) -> (Vec3<Unit, Space>, f32)
pub fn to_axis_angle(self) -> (Vec3<Unit, Space>, f32)
Converts the quaternion to an axis and angle (in radians). The returned axis is normalized. If the quaternion is identity, returns (Vec3::X, 0.0) or similar, as angle is 0.
Sourcepub fn to_axis_angle_radians(self) -> (Vec3<Unit, Space>, Radians)
pub fn to_axis_angle_radians(self) -> (Vec3<Unit, Space>, Radians)
Converts the quaternion to an axis and typed angle (radians).
Sourcepub fn to_axis_angle_deg(self) -> (Vec3<Unit, Space>, Degrees)
pub fn to_axis_angle_deg(self) -> (Vec3<Unit, Space>, Degrees)
Converts the quaternion to an axis and typed angle (degrees).
Sourcepub fn pitch_radians(self) -> Radians
pub fn pitch_radians(self) -> Radians
Pitch as a typed radians angle.
Sourcepub fn yaw_radians(self) -> Radians
pub fn yaw_radians(self) -> Radians
Yaw as a typed radians angle.
Sourcepub fn roll_radians(self) -> Radians
pub fn roll_radians(self) -> Radians
Roll as a typed radians angle.
Sourcepub fn nlerp(self, b: Self, t: f32) -> Self
pub fn nlerp(self, b: Self, t: f32) -> Self
Normalized linear interpolation between two quaternions.
Sourcepub fn slerp(self, b: Self, t: f32) -> Self
pub fn slerp(self, b: Self, t: f32) -> Self
Spherical linear interpolation between two quaternions. Handles inputs that are not normalized and ensures the shortest path.
Sourcepub fn slerp_approx(self, b: Self, t: f32) -> Self
pub fn slerp_approx(self, b: Self, t: f32) -> Self
Approximate spherical linear interpolation.
Sourcepub fn nquad(p: Self, a: Self, b: Self, q: Self, t: f32) -> Self
pub fn nquad(p: Self, a: Self, b: Self, q: Self, t: f32) -> Self
Normalized quadratic interpolation.
Sourcepub fn squad(p: Self, a: Self, b: Self, q: Self, t: f32) -> Self
pub fn squad(p: Self, a: Self, b: Self, q: Self, t: f32) -> Self
Spherical quadratic interpolation.
Sourcepub fn squad_approx(p: Self, a: Self, b: Self, q: Self, t: f32) -> Self
pub fn squad_approx(p: Self, a: Self, b: Self, q: Self, t: f32) -> Self
Approximate spherical quadratic interpolation.
Sourcepub fn is_normalized(&self) -> bool
pub fn is_normalized(&self) -> bool
Returns true if the quaternion is normalized (length is approximately 1).
Sourcepub fn angle_between(self, other: Self) -> f32
pub fn angle_between(self, other: Self) -> f32
Returns the angle (in radians) between self and another quaternion.
Sourcepub fn angle_between_radians(self, other: Self) -> Radians
pub fn angle_between_radians(self, other: Self) -> Radians
Angle between two quaternions as typed radians.
Sourcepub fn rotate_vec3(&self, v: &mut Vec3<Unit, Space>)
pub fn rotate_vec3(&self, v: &mut Vec3<Unit, Space>)
Rotates a Vec3 in-place by this quaternion.
Trait Implementations§
Source§impl<Unit: Copy, Space: Copy> AddAssign for Quat<Unit, Space>
impl<Unit: Copy, Space: Copy> AddAssign for Quat<Unit, Space>
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreSource§impl<'de, Unit: Copy, Space: Copy> Deserialize<'de> for Quat<Unit, Space>
impl<'de, Unit: Copy, Space: Copy> Deserialize<'de> for Quat<Unit, Space>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<Unit: Copy, Space: Copy> DivAssign<f32> for Quat<Unit, Space>
impl<Unit: Copy, Space: Copy> DivAssign<f32> for Quat<Unit, Space>
Source§fn div_assign(&mut self, rhs: f32)
fn div_assign(&mut self, rhs: f32)
/= operation. Read moreSource§impl<Unit: Copy, Space: Copy> From<Quaternion<f32>> for Quat<Unit, Space>
impl<Unit: Copy, Space: Copy> From<Quaternion<f32>> for Quat<Unit, Space>
Source§fn from(q: Quaternion<f32>) -> Self
fn from(q: Quaternion<f32>) -> Self
Source§impl<Unit: Copy, Space: Copy> IntoMint for Quat<Unit, Space>
impl<Unit: Copy, Space: Copy> IntoMint for Quat<Unit, Space>
Source§type MintType = Quaternion<f32>
type MintType = Quaternion<f32>
Source§impl<Unit: Copy, Space: Copy> MulAssign<f32> for Quat<Unit, Space>
impl<Unit: Copy, Space: Copy> MulAssign<f32> for Quat<Unit, Space>
Source§fn mul_assign(&mut self, rhs: f32)
fn mul_assign(&mut self, rhs: f32)
*= operation. Read moreSource§impl<Unit: Copy, Space: Copy> MulAssign for Quat<Unit, Space>
impl<Unit: Copy, Space: Copy> MulAssign for Quat<Unit, Space>
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*= operation. Read moreSource§impl<Unit: Copy, Space: Copy> SubAssign for Quat<Unit, Space>
impl<Unit: Copy, Space: Copy> SubAssign for Quat<Unit, Space>
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read more