[][src]Struct gramit::quaternion::Quaternion

#[repr(C)]
pub struct Quaternion {
    pub i: f32,
    pub j: f32,
    pub k: f32,
    pub r: f32,
}

Fields

i: f32j: f32k: f32r: f32

Methods

impl Quaternion[src]

pub fn new(i: f32, j: f32, k: f32, r: f32) -> Quaternion[src]

Construct a Quaternion with the given components.

pub fn real(r: f32) -> Quaternion[src]

Construct a Quaternion with only a real part.

pub fn vector(vec: Vec3) -> Quaternion[src]

Construct a Quaternion with only a vector part.

pub fn real_vector(r: f32, vec: Vec3) -> Quaternion[src]

Construct a Quaternion with the given real and vector parts.

pub fn vector_part(&self) -> Vec3[src]

Get the imaginary components of this Quaternion as a Vec3.

pub fn conjugate_by(&self, q: &Quaternion) -> Quaternion[src]

Conjugate this Quaternion by q.

pub fn conjugate_by_unit(&self, q: &Quaternion) -> Quaternion[src]

Conjugate this Quaternion by q, which is assumed to be of unit magnitude.

This function takes advantage of the fact that, for unit quaternions, the inverse is equal to the complex conjugate, and so omits several floating point operations in the calculation of q's inverse.

Usage Warning

This function does not check that q is of unit magnitude! Doing so would require the same operations that the unit-magnitude assumption avoids. The user should be sure that q is actually a unit quaternion, or simply use conjugate_by, which performs the full calculation for inverting q.

pub fn inverse(&self) -> Quaternion[src]

Get the multiplicative inverse of this Quaternion.

pub fn neg_vector(&self) -> Quaternion[src]

Get a Quaternion that is equal to this Quaternion with its vector part negated (i.e. the complex conjugate).

For a unit quaternion, this is equal to the inverse.

pub fn magnitude(&self) -> f32[src]

Get the magnitude of this Quaternion.

pub fn unit(&self) -> Quaternion[src]

Get the normalized (unit-magnitude) version of this Quaternion.

Trait Implementations

impl ApproxEq<Quaternion> for Quaternion[src]

fn within_threshold(self, rhs: Quaternion, threshold: Quaternion) -> bool[src]

Compare two Quaternions for approximate equality.

Uses a third Quaternion for element-wise thresholds.

impl From<f32> for Quaternion[src]

fn from(r: f32) -> Quaternion[src]

Converts an f32 into a Quaternion with only a real part.

This conversion is identical to that performed by Quaternion::real.

impl From<Vec3> for Quaternion[src]

fn from(vec: Vec3) -> Quaternion[src]

Converts a Vec3 into a Quaternion with only a vector part.

This conversion is identical to that performed by Quaternion::vector.

impl Clone for Quaternion[src]

impl Copy for Quaternion[src]

impl PartialEq<Quaternion> for Quaternion[src]

impl Debug for Quaternion[src]

impl Div<Quaternion> for Quaternion[src]

type Output = Quaternion

The resulting type after applying the / operator.

impl<'_> Div<&'_ Quaternion> for Quaternion[src]

type Output = Quaternion

The resulting type after applying the / operator.

impl<'_> Div<Quaternion> for &'_ Quaternion[src]

type Output = Quaternion

The resulting type after applying the / operator.

impl<'_, '_> Div<&'_ Quaternion> for &'_ Quaternion[src]

type Output = Quaternion

The resulting type after applying the / operator.

impl Sub<Quaternion> for Quaternion[src]

type Output = Quaternion

The resulting type after applying the - operator.

impl<'_> Sub<&'_ Quaternion> for Quaternion[src]

type Output = Quaternion

The resulting type after applying the - operator.

impl<'_> Sub<Quaternion> for &'_ Quaternion[src]

type Output = Quaternion

The resulting type after applying the - operator.

impl<'_, '_> Sub<&'_ Quaternion> for &'_ Quaternion[src]

type Output = Quaternion

The resulting type after applying the - operator.

impl Add<Quaternion> for Quaternion[src]

type Output = Quaternion

The resulting type after applying the + operator.

impl<'_> Add<&'_ Quaternion> for Quaternion[src]

type Output = Quaternion

The resulting type after applying the + operator.

impl<'_> Add<Quaternion> for &'_ Quaternion[src]

type Output = Quaternion

The resulting type after applying the + operator.

impl<'_, '_> Add<&'_ Quaternion> for &'_ Quaternion[src]

type Output = Quaternion

The resulting type after applying the + operator.

impl Mul<Quaternion> for Quaternion[src]

type Output = Quaternion

The resulting type after applying the * operator.

impl<'_> Mul<&'_ Quaternion> for Quaternion[src]

type Output = Quaternion

The resulting type after applying the * operator.

impl<'_> Mul<Quaternion> for &'_ Quaternion[src]

type Output = Quaternion

The resulting type after applying the * operator.

impl<'_, '_> Mul<&'_ Quaternion> for &'_ Quaternion[src]

type Output = Quaternion

The resulting type after applying the * operator.

impl Neg for Quaternion[src]

type Output = Quaternion

The resulting type after applying the - operator.

impl<'_> Neg for &'_ Quaternion[src]

type Output = Quaternion

The resulting type after applying the - operator.

impl AddAssign<Quaternion> for Quaternion[src]

impl<'_> AddAssign<&'_ Quaternion> for Quaternion[src]

impl SubAssign<Quaternion> for Quaternion[src]

impl<'_> SubAssign<&'_ Quaternion> for Quaternion[src]

impl MulAssign<Quaternion> for Quaternion[src]

impl<'_> MulAssign<&'_ Quaternion> for Quaternion[src]

impl DivAssign<Quaternion> for Quaternion[src]

impl<'_> DivAssign<&'_ Quaternion> for Quaternion[src]

impl StructuralPartialEq for Quaternion[src]

Auto Trait Implementations

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = !

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]