Struct micromath::Quaternion
source · pub struct Quaternion(/* private fields */);
Available on crate feature
quaternion
only.Expand description
Quaternions are a number system that extends the complex numbers which can be used for efficiently computing spatial rotations.
They’re computed as the quotient of two directed lines in a three-dimensional space, or equivalently as the quotient of two vectors.
For given real numbers a
, b
, c
, and d
, they take the form:
a + bi + cj + dk
where i
, j
, and k
are the fundamental quaternion units:
i² = j² = k² = i*j*k = -1
Quaternion multiplication is non-commutative:
x | 1 | i | j | k |
---|---|---|---|---|
1 | 1 | i | j | k |
i | i | -1 | k | -j |
j | j | -k | -1 | i |
k | k | j | -i | -1 |
Implementations§
source§impl Quaternion
impl Quaternion
sourcepub fn from_two_vectors<C>(u: Vector3d<C>, v: Vector3d<C>) -> Selfwhere
C: Component + Into<f32>,
pub fn from_two_vectors<C>(u: Vector3d<C>, v: Vector3d<C>) -> Selfwhere C: Component + Into<f32>,
Get the quaternion that represents the smallest rotation between two vectors.
sourcepub fn inv(self) -> Self
pub fn inv(self) -> Self
Compute the inverse of this quaternion.
Panics if Quaternion::norm
is zero.
sourcepub fn axis_angle<C>(v: Vector3d<C>, theta: C) -> Selfwhere
C: Component + Into<f32>,
Available on crate feature vector
only.
pub fn axis_angle<C>(v: Vector3d<C>, theta: C) -> Selfwhere C: Component + Into<f32>,
vector
only.Compute a quaternion for the given axis vector and angle.
sourcepub fn rotate<C>(self, v: Vector3d<C>) -> F32x3where
C: Component + Into<f32>,
Available on crate feature vector
only.
pub fn rotate<C>(self, v: Vector3d<C>) -> F32x3where C: Component + Into<f32>,
vector
only.Rotate a 3D vector using this quaternion, assumes the quaternion is of unit length.
Trait Implementations§
source§impl Add for Quaternion
impl Add for Quaternion
source§impl AddAssign for Quaternion
impl AddAssign for Quaternion
source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Performs the
+=
operation. Read moresource§impl Clone for Quaternion
impl Clone for Quaternion
source§fn clone(&self) -> Quaternion
fn clone(&self) -> Quaternion
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for Quaternion
impl Debug for Quaternion
source§impl Default for Quaternion
impl Default for Quaternion
source§impl<C> From<Vector3d<C>> for Quaternionwhere
C: Component + Into<f32>,
Available on crate feature vector
only.
impl<C> From<Vector3d<C>> for Quaternionwhere C: Component + Into<f32>,
Available on crate feature
vector
only.source§fn from(v: Vector3d<C>) -> Quaternion
fn from(v: Vector3d<C>) -> Quaternion
Converts to this type from the input type.
source§impl Mul<Quaternion> for f32
impl Mul<Quaternion> for f32
§type Output = Quaternion
type Output = Quaternion
The resulting type after applying the
*
operator.source§fn mul(self, q: Quaternion) -> Quaternion
fn mul(self, q: Quaternion) -> Quaternion
Performs the
*
operation. Read moresource§impl<C> Mul<Vector3d<C>> for Quaternionwhere
C: Component + Into<f32>,
Available on crate feature vector
only.
impl<C> Mul<Vector3d<C>> for Quaternionwhere C: Component + Into<f32>,
Available on crate feature
vector
only.source§impl Mul<f32> for Quaternion
impl Mul<f32> for Quaternion
source§impl Mul for Quaternion
impl Mul for Quaternion
source§impl MulAssign<f32> for Quaternion
impl MulAssign<f32> for Quaternion
source§fn mul_assign(&mut self, k: f32)
fn mul_assign(&mut self, k: f32)
Performs the
*=
operation. Read moresource§impl PartialEq for Quaternion
impl PartialEq for Quaternion
source§fn eq(&self, other: &Quaternion) -> bool
fn eq(&self, other: &Quaternion) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl Sub for Quaternion
impl Sub for Quaternion
source§impl SubAssign for Quaternion
impl SubAssign for Quaternion
source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
Performs the
-=
operation. Read moreimpl Copy for Quaternion
impl StructuralPartialEq for Quaternion
Auto Trait Implementations§
impl RefUnwindSafe for Quaternion
impl Send for Quaternion
impl Sync for Quaternion
impl Unpin for Quaternion
impl UnwindSafe for Quaternion
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more