pub struct Quaternion(/* private fields */);
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>) -> Self
pub fn from_two_vectors<C>(u: Vector3d<C>, v: Vector3d<C>) -> Self
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) -> Self
Available on crate feature vector
only.
pub fn axis_angle<C>(v: Vector3d<C>, theta: C) -> Self
vector
only.Compute a quaternion for the given axis vector and angle.
Sourcepub fn rotate<C>(self, v: Vector3d<C>) -> F32x3
Available on crate feature vector
only.
pub fn rotate<C>(self, v: Vector3d<C>) -> F32x3
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 duplicate 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 Quaternion
Available on crate feature vector
only.
impl<C> From<Vector3d<C>> for Quaternion
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
Source§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 Quaternion
Available on crate feature vector
only.
impl<C> Mul<Vector3d<C>> for Quaternion
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§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 Freeze for Quaternion
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