alloy::math

Struct Quaternion

source
pub struct Quaternion(/* private fields */);
Expand description

Represents a quaternion in 4D space.

Implementations§

source§

impl Quaternion

source

pub const ZERO: Quaternion = _

The zero quaternion.

source

pub const UNIT: Quaternion = _

The identity quaternion.

source

pub const fn new(w: f32, i: f32, j: f32, k: f32) -> Self

Creates a new quaternion with the given components.

§Parameters
  • w - The real component of the quaternion.
  • i - The i imaginary component of the quaternion.
  • j - The j imaginary component of the quaternion.
  • k - The k imaginary component of the quaternion.
source

pub const fn identity() -> Self

Returns the unit/identity quaternion.

source

pub const fn from_vector4(vec: Vector4) -> Self

Creates a new quaternion from a 4D vector.

§Parameters
  • vec - The vector to create the quaternion from.
source

pub const fn from_vec4(vec: &Vec4) -> Self

Creates a new quaternion from a 4D vector.

§Parameters
  • vec - The vector to create the quaternion from.
source

pub fn from_angle_axis<A: Angle>(angle: A, axis: &Vec3) -> Self

Creates a quaternion from an angle (in radians) and an axis vector (x, y, z)

§Parameters
  • angle - The angle of rotation.
  • axis - The axis of rotation.
source

pub fn from_yaw<A: Angle>(angle: A) -> Self

Creates a quaternion from a yaw angle.

§Parameters
  • angle - The yaw angle.
source

pub fn from_pitch<A: Angle>(angle: A) -> Self

Creates a quaternion from a pitch angle.

§Parameters
  • angle - The pitch angle.
source

pub fn from_roll<A: Angle>(angle: A) -> Self

Creates a quaternion from a roll angle.

§Parameters
  • angle - The roll angle.
source

pub fn from_euler_angles<A: Angle>(yaw: A, pitch: A, roll: A) -> Self

Creates a new quaternion from a set of Euler angles.

§Parameters
  • yaw - The yaw angle.
  • pitch - The pitch angle.
  • roll - The roll angle.
source

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

Creates a new quaternion from a 4x4 matrix encoding a rotation.

§Parameters
  • matrix - The rotation matrix to convert.
source§

impl Quaternion

source

pub const fn as_vec4(&self) -> &Vec4

Converts the quaternion to a 4D vector.

source

pub fn as_mut_vec4(&mut self) -> &mut Vec4

Converts the quaternion to a mutable 4D vector.

source

pub const fn as_slice(&self) -> &[f32]

Returns this quaternion as a slice of f32.

source

pub fn as_mut_slice(&mut self) -> &mut [f32]

Returns this quaternion as a mutable slice of f32.

source

pub const fn as_ptr(&self) -> *const f32

Returns this vector as a ptr of f32.

source

pub fn as_mut_ptr(&mut self) -> *mut f32

Returns this vector as a mutable ptr of f32.

source

pub fn to_matrix4(&self) -> Matrix4

Returns the rotation matrix representation of the quaternion.

source§

impl Quaternion

Properties

source

pub fn conjugate(&self) -> Self

Returns the conjugate of the quaternion.

source

pub fn inverse(&self) -> Self

Returns the inverse of the quaternion.

source

pub fn norm(&self) -> f32

Returns the norm of the quaternion.

source

pub fn normalized(&self) -> Self

Returns the normalized quaternion.

source

pub fn yaw<A: Angle>(&self) -> A

Returns the yaw angle of the quaternion.

source

pub fn pitch<A: Angle>(&self) -> A

Returns the pitch angle of the quaternion.

source

pub fn roll<A: Angle>(&self) -> A

Returns the roll angle of the quaternion.

source

pub fn euler_angles<A: Angle>(&self) -> (A, A, A)

Returns the euler angles of the quaternion in (yaw, pitch, roll) order.

source

pub fn angle_axis<A: Angle>(&self) -> (A, Vector3)

Returns the angle (in radians) and axis (x, y, z) of the quaternion

source

pub const fn w(&self) -> f32

Returns the real component of the quaternion.

source

pub fn w_mut(&mut self) -> &mut f32

Retrieves a mutable reference to the real component of the quaternion.

source

pub const fn i(&self) -> f32

Returns the i imaginary component of the quaternion.

source

pub fn i_mut(&mut self) -> &mut f32

Retrieves a mutable reference to the i imaginary component of the quaternion.

source

pub const fn j(&self) -> f32

Returns the j imaginary component of the quaternion.

source

pub fn j_mut(&mut self) -> &mut f32

Retrieves a mutable reference to the j imaginary component of the quaternion.

source

pub const fn k(&self) -> f32

Returns the k imaginary component of the quaternion.

source

pub fn k_mut(&mut self) -> &mut f32

Retrieves a mutable reference to the k imaginary component of the quaternion.

source

pub const fn wi(&self) -> &Vec2

Returns the first two components of the quaternion.

source

pub fn wi_mut(&mut self) -> &mut Vec2

Returns a mutable reference to the first two components of the quaternion.

source

pub const fn ij(&self) -> &Vec2

Returns the middle two components of the quaternion.

source

pub fn ij_mut(&mut self) -> &mut Vec2

Returns a mutable reference to the middle two components of the quaternion.

source

pub const fn jk(&self) -> &Vec2

Returns the last two components of the quaternion.

source

pub fn jk_mut(&mut self) -> &mut Vec2

Returns a mutable reference to the last two components of the quaternion.

source

pub const fn wij(&self) -> &Vec3

Returns the first three components of the quaternion.

source

pub fn wij_mut(&mut self) -> &mut Vec3

Returns a mutable reference to the first three components of the quaternion.

source

pub const fn ijk(&self) -> &Vec3

Returns the last three components of the quaternion.

source

pub fn ijk_mut(&mut self) -> &mut Vec3

Returns a mutable reference to the last three components of the quaternion.

source§

impl Quaternion

source

pub fn normalize(&mut self)

Normalizes the quaternion.

source

pub fn set_w(&mut self, w: f32)

Sets the real component of the quaternion.

source

pub fn set_i(&mut self, i: f32)

Sets the i imaginary component of the quaternion.

source

pub fn set_j(&mut self, j: f32)

Sets the j imaginary component of the quaternion.

source

pub fn set_k(&mut self, k: f32)

Sets the k imaginary component of the quaternion.

source§

impl Quaternion

source

pub fn rotate(&self, other: &Self) -> Self

Rotates the quaternion by another quaternion.

§Parameters
  • other - The quaternion to rotate by.
source

pub fn rotate_by_angle_axis<A: Angle>(&self, angle: A, axis: &Vec3) -> Self

Rotates the quaternion by an angle (in radians) and an axis vector (x, y, z).

§Parameters
  • angle - The angle of rotation.
  • axis - The axis of rotation.
source

pub fn rotate_by_yaw<A: Angle>(&self, angle: A) -> Self

Rotates the quaternion by a yaw angle.

§Parameters
  • angle - The yaw angle.
source

pub fn rotate_by_pitch<A: Angle>(&self, angle: A) -> Self

Rotates the quaternion by a pitch angle.

§Parameters
  • angle - The pitch angle.
source

pub fn rotate_by_roll<A: Angle>(&self, angle: A) -> Self

Rotates the quaternion by a roll angle.

§Parameters
  • angle - The roll angle.
source

pub fn rotate_by_euler_angles<A: Angle>( &self, yaw: A, pitch: A, roll: A, ) -> Self

Rotates the quaternion by a set of Euler angles.

§Parameters
  • yaw - The yaw angle.
  • pitch - The pitch angle.
  • roll - The roll angle.
source

pub fn rotate_by_mat4(&self, matrix: &Mat4) -> Self

Rotates the quaternion by a 4x4 matrix encoding a rotation.

§Parameters
  • matrix - The rotation matrix to rotate by.
source

pub fn rotate_vec3(&self, vec: &Vec3) -> Vector3

Rotates a 3D vector by the angle represented by the quaternion.

source

pub fn rotate_vec4(&self, vec: &Vec4) -> Vector4

Rotates a 3D vector by the angle represented by the quaternion.

§Parameters
  • vec - The vector to rotate.

Trait Implementations§

source§

impl Add<f32> for &Quaternion

source§

type Output = Quaternion

The resulting type after applying the + operator.
source§

fn add(self, rhs: f32) -> Quaternion

Performs the + operation. Read more
source§

impl Add for &Quaternion

source§

type Output = Quaternion

The resulting type after applying the + operator.
source§

fn add(self, rhs: &Quaternion) -> Quaternion

Performs the + operation. Read more
source§

impl Add for Quaternion

source§

type Output = Quaternion

The resulting type after applying the + operator.
source§

fn add(self, rhs: Quaternion) -> Quaternion

Performs the + operation. Read more
source§

impl AddAssign<&Quaternion> for Quaternion

source§

fn add_assign(&mut self, rhs: &Quaternion)

Performs the += operation. Read more
source§

impl AddAssign<f32> for Quaternion

source§

fn add_assign(&mut self, rhs: f32)

Performs the += operation. Read more
source§

impl AlmostEq for Quaternion

source§

fn almost_eq(&self, other: &Self) -> bool

Tests whether self is almost equal to other Read more
source§

impl Clone for Quaternion

source§

fn clone(&self) -> Quaternion

Returns a copy 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 Debug for Quaternion

source§

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

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

impl Default for Quaternion

source§

fn default() -> Self

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

impl Display for Quaternion

source§

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

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

impl Div<f32> for &Quaternion

source§

type Output = Quaternion

The resulting type after applying the / operator.
source§

fn div(self, rhs: f32) -> Quaternion

Performs the / operation. Read more
source§

impl DivAssign<f32> for Quaternion

source§

fn div_assign(&mut self, rhs: f32)

Performs the /= operation. Read more
source§

impl Dot<Quaternion> for Vec4

source§

type Output = f32

The output of this operation. Read more
source§

fn dot(&self, other: &Quaternion) -> Self::Output

Performs the dot-product between two values, and returns the output value. Read more
source§

impl Dot<Vec4> for Quaternion

source§

type Output = f32

The output of this operation. Read more
source§

fn dot(&self, other: &Vec4) -> Self::Output

Performs the dot-product between two values, and returns the output value. Read more
source§

impl Dot for Quaternion

source§

type Output = f32

The output of this operation. Read more
source§

fn dot(&self, other: &Self) -> Self::Output

Performs the dot-product between two values, and returns the output value. Read more
source§

impl From<&Vec4> for Quaternion

source§

fn from(vec: &Vec4) -> Self

Converts to this type from the input type.
source§

impl From<Vector4> for Quaternion

source§

fn from(vec: Vector4) -> Self

Converts to this type from the input type.
source§

impl Lerp for Quaternion

source§

type Output = Quaternion

The output of this operation.
source§

fn lerp(&self, other: &Self, alpha: f32) -> Self::Output

Interpolates between two different states Read more
source§

impl Mul<&Quaternion> for Quaternion

source§

type Output = Quaternion

The resulting type after applying the * operator.
source§

fn mul(self, rhs: &Quaternion) -> Quaternion

Performs the * operation. Read more
source§

impl Mul<&Quaternion> for f32

source§

type Output = Quaternion

The resulting type after applying the * operator.
source§

fn mul(self, rhs: &Quaternion) -> Quaternion

Performs the * operation. Read more
source§

impl Mul<Quaternion> for &Quaternion

source§

type Output = Quaternion

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Quaternion) -> Quaternion

Performs the * operation. Read more
source§

impl Mul<f32> for &Quaternion

source§

type Output = Quaternion

The resulting type after applying the * operator.
source§

fn mul(self, rhs: f32) -> Quaternion

Performs the * operation. Read more
source§

impl Mul for &Quaternion

source§

type Output = Quaternion

The resulting type after applying the * operator.
source§

fn mul(self, rhs: &Quaternion) -> Quaternion

Performs the * operation. Read more
source§

impl Mul for Quaternion

source§

type Output = Quaternion

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Quaternion) -> Quaternion

Performs the * operation. Read more
source§

impl MulAssign<&Quaternion> for Quaternion

source§

fn mul_assign(&mut self, rhs: &Quaternion)

Performs the *= operation. Read more
source§

impl MulAssign<f32> for Quaternion

source§

fn mul_assign(&mut self, rhs: f32)

Performs the *= operation. Read more
source§

impl MulAssign for Quaternion

source§

fn mul_assign(&mut self, rhs: Quaternion)

Performs the *= operation. Read more
source§

impl Near for Quaternion

source§

fn near(&self, other: &Self, tolerance: &f32) -> bool

Tests whether self is “near” other relative top the specified tolerance Read more
source§

impl PartialEq for Quaternion

source§

fn eq(&self, other: &Quaternion) -> 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 PartialOrd for Quaternion

source§

fn partial_cmp(&self, other: &Quaternion) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Sub<f32> for &Quaternion

source§

type Output = Quaternion

The resulting type after applying the - operator.
source§

fn sub(self, rhs: f32) -> Quaternion

Performs the - operation. Read more
source§

impl Sub for &Quaternion

source§

type Output = Quaternion

The resulting type after applying the - operator.
source§

fn sub(self, rhs: &Quaternion) -> Quaternion

Performs the - operation. Read more
source§

impl SubAssign<f32> for Quaternion

source§

fn sub_assign(&mut self, rhs: f32)

Performs the -= operation. Read more
source§

impl Copy for Quaternion

source§

impl StructuralPartialEq for Quaternion

Auto Trait Implementations§

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryDot<U> for T
where T: Dot<U>,

source§

type Error = Infallible

The error to return on failure.
source§

type Output = <T as Dot<U>>::Output

The type to output on success.
source§

fn try_dot( &self, rhs: &U, ) -> Result<<T as TryDot<U>>::Output, <T as TryDot<U>>::Error>

Attempts to perform a [dot-product] between two possibly different-sized sequences of values. Read more
source§

unsafe fn dot_unchecked(&self, rhs: &U) -> <T as TryDot<U>>::Output

Performs an unguarded [dot-product] between two possibly different-sized sequences of values. 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.