Skip to main content

Quat

Struct Quat 

Source
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: f32

Implementations§

Source§

impl<Unit: Copy, Space: Copy> Quat<Unit, Space>

Source

pub const IDENTITY: Self

Source

pub const ZERO: Self

Source

pub const fn new(x: f32, y: f32, z: f32, w: f32) -> Self

Source

pub const fn from_vec4(v: Vec4<Unit, Space>) -> Self

Creates a quaternion from a Vec4 (x, y, z, w components).

Source

pub const fn to_vec4(self) -> Vec4<Unit, Space>

Returns the quaternion as a Vec4.

Source

pub const fn xyz(self) -> Vec3<Unit, Space>

Returns the vector part (x, y, z) of the quaternion.

Source

pub fn from_axis_angle_radians(axis: Vec3<Unit, Space>, angle: Radians) -> Self

Creates a quaternion from an axis and an angle (typed radians).

Source

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.

Source

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.

Source

pub fn from_axis_angle_deg(axis: Vec3<Unit, Space>, angle: Degrees) -> Self

Creates a quaternion from an axis and an angle (typed degrees).

Source

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.

Source

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.

Source

pub const fn dot(self, rhs: Self) -> f32

Calculates the dot product of two quaternions.

Source

pub const fn length_squared(self) -> f32

Calculates the squared length (magnitude) of the quaternion.

Source

pub fn length(self) -> f32

Calculates the length (magnitude) of the quaternion.

Source

pub fn normalize(self) -> Self

Normalizes the quaternion. If the length is zero, returns Quat::zero().

Source

pub fn try_normalize(self) -> Option<Self>

Normalizes the quaternion, returning None if the length is zero.

Source

pub const fn conjugate(self) -> Self

Calculates the conjugate of the quaternion.

Source

pub fn inverse(self) -> Option<Self>

Calculates the inverse of the quaternion. Returns None if the quaternion’s length is zero (cannot be inverted).

Source

pub fn try_inverse(self) -> Option<Self>

Alias for Quat::inverse.

Source

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).

Source

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.

Source

pub fn to_axis_angle_radians(self) -> (Vec3<Unit, Space>, Radians)

Converts the quaternion to an axis and typed angle (radians).

Source

pub fn to_axis_angle_deg(self) -> (Vec3<Unit, Space>, Degrees)

Converts the quaternion to an axis and typed angle (degrees).

Source

pub fn pitch(self) -> f32

Calculates the pitch (rotation around the x-axis) in radians.

Source

pub fn pitch_radians(self) -> Radians

Pitch as a typed radians angle.

Source

pub fn yaw(self) -> f32

Calculates the yaw (rotation around the y-axis) in radians.

Source

pub fn yaw_radians(self) -> Radians

Yaw as a typed radians angle.

Source

pub fn roll(self) -> f32

Calculates the roll (rotation around the z-axis) in radians.

Source

pub fn roll_radians(self) -> Radians

Roll as a typed radians angle.

Source

pub fn from_mat4(m: &Mat4) -> Self

Creates a quaternion from a 4x4 rotation matrix.

Source

pub fn lerp(self, b: Self, t: f32) -> Self

Linear interpolation between two quaternions.

Source

pub fn nlerp(self, b: Self, t: f32) -> Self

Normalized linear interpolation between two quaternions.

Source

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.

Source

pub fn slerp_approx(self, b: Self, t: f32) -> Self

Approximate spherical linear interpolation.

Source

pub fn nquad(p: Self, a: Self, b: Self, q: Self, t: f32) -> Self

Normalized quadratic interpolation.

Source

pub fn squad(p: Self, a: Self, b: Self, q: Self, t: f32) -> Self

Spherical quadratic interpolation.

Source

pub fn squad_approx(p: Self, a: Self, b: Self, q: Self, t: f32) -> Self

Approximate spherical quadratic interpolation.

Source

pub fn from_mat3(m: &Mat3) -> Self

Creates a quaternion from a 3x3 rotation matrix.

Source

pub fn to_mat3(&self) -> Mat3<Unit, Space>

Converts the quaternion to a 3x3 rotation matrix.

Source

pub fn is_normalized(&self) -> bool

Returns true if the quaternion is normalized (length is approximately 1).

Source

pub fn angle_between(self, other: Self) -> f32

Returns the angle (in radians) between self and another quaternion.

Source

pub fn angle_between_radians(self, other: Self) -> Radians

Angle between two quaternions as typed radians.

Source

pub fn rotate_vec3(&self, v: &mut Vec3<Unit, Space>)

Rotates a Vec3 in-place by this quaternion.

Source

pub fn ln(self) -> Self

Returns the logarithm of the quaternion (for advanced interpolation).

Source

pub fn exp(self) -> Self

Returns the exponential of the quaternion (for advanced interpolation).

Trait Implementations§

Source§

impl<Unit: Copy, Space: Copy> Add for Quat<Unit, Space>

Source§

type Output = Quat<Unit, Space>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<Unit: Copy, Space: Copy> AddAssign for Quat<Unit, Space>

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl<Unit: Clone + Copy, Space: Clone + Copy> Clone for Quat<Unit, Space>

Source§

fn clone(&self) -> Quat<Unit, Space>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Unit: Debug + Copy, Space: Debug + Copy> Debug for Quat<Unit, Space>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Unit: Default + Copy, Space: Default + Copy> Default for Quat<Unit, Space>

Source§

fn default() -> Quat<Unit, Space>

Returns the “default value” for a type. Read more
Source§

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>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<Unit: Copy, Space: Copy> Div<f32> for Quat<Unit, Space>

Source§

type Output = Quat<Unit, Space>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: f32) -> Self::Output

Performs the / operation. Read more
Source§

impl<Unit: Copy, Space: Copy> DivAssign<f32> for Quat<Unit, Space>

Source§

fn div_assign(&mut self, rhs: f32)

Performs the /= operation. Read more
Source§

impl<Unit: Copy, Space: Copy> From<Quat<Unit, Space>> for Quaternion<f32>

Source§

fn from(q: Quat<Unit, Space>) -> Self

Converts to this type from the input type.
Source§

impl<Unit: Copy, Space: Copy> From<Quaternion<f32>> for Quat<Unit, Space>

Source§

fn from(q: Quaternion<f32>) -> Self

Converts to this type from the input type.
Source§

impl<Unit: Copy, Space: Copy> IntoMint for Quat<Unit, Space>

Source§

type MintType = Quaternion<f32>

The mint type that this type is associated with.
Source§

impl<Unit: Copy, Space: Copy> Mul<Quat<Unit, Space>> for f32

Source§

type Output = Quat<Unit, Space>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Quat<Unit, Space>) -> Self::Output

Performs the * operation. Read more
Source§

impl<Unit: Copy, Space: Copy> Mul<Vec3<Unit, Space>> for Quat<Unit, Space>

Source§

type Output = Vec3<Unit, Space>

The resulting type after applying the * operator.
Source§

fn mul(self, v: Vec3<Unit, Space>) -> Self::Output

Performs the * operation. Read more
Source§

impl<Unit: Copy, Space: Copy> Mul<f32> for Quat<Unit, Space>

Source§

type Output = Quat<Unit, Space>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f32) -> Self::Output

Performs the * operation. Read more
Source§

impl<Unit: Copy, Space: Copy> Mul for Quat<Unit, Space>

Source§

type Output = Quat<Unit, Space>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl<Unit: Copy, Space: Copy> MulAssign<f32> for Quat<Unit, Space>

Source§

fn mul_assign(&mut self, rhs: f32)

Performs the *= operation. Read more
Source§

impl<Unit: Copy, Space: Copy> MulAssign for Quat<Unit, Space>

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

impl<Unit: Copy, Space: Copy> Neg for Quat<Unit, Space>

Source§

type Output = Quat<Unit, Space>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<Unit: PartialEq + Copy, Space: PartialEq + Copy> PartialEq for Quat<Unit, Space>

Source§

fn eq(&self, other: &Quat<Unit, Space>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<Unit: Copy, Space: Copy> Serialize for Quat<Unit, Space>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<Unit: Copy, Space: Copy> Sub for Quat<Unit, Space>

Source§

type Output = Quat<Unit, Space>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<Unit: Copy, Space: Copy> SubAssign for Quat<Unit, Space>

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl<Unit: Copy + Copy, Space: Copy + Copy> Copy for Quat<Unit, Space>

Source§

impl<Unit: Copy, Space: Copy> StructuralPartialEq for Quat<Unit, Space>

Auto Trait Implementations§

§

impl<Unit, Space> Freeze for Quat<Unit, Space>

§

impl<Unit, Space> RefUnwindSafe for Quat<Unit, Space>
where Unit: RefUnwindSafe, Space: RefUnwindSafe,

§

impl<Unit, Space> Send for Quat<Unit, Space>
where Unit: Send, Space: Send,

§

impl<Unit, Space> Sync for Quat<Unit, Space>
where Unit: Sync, Space: Sync,

§

impl<Unit, Space> Unpin for Quat<Unit, Space>
where Unit: Unpin, Space: Unpin,

§

impl<Unit, Space> UnwindSafe for Quat<Unit, Space>
where Unit: UnwindSafe, Space: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,