Struct num_quaternion::UnitQuaternion

source ·
pub struct UnitQuaternion<T>(/* private fields */);
Expand description

A quaternion with norm $1$.

Unit quaternions form a non-commutative group that can be conveniently used for rotating 3D vectors. A 3D vector can be interpreted as a pure quaternion (a quaternion with real part zero). Such a pure quaternion $v$ can be rotated in 3D space by computing $q^{-1}\cdot v\cdot q$ for a unit quaternion $q$. The resulting product is again a pure quaternion which is $v$ rotated around the axis given by the imaginary part of $q$. The angle of rotation is double the angle between $1$ and $q$ interpreted as 4D vectors.

Multiplying two unit quaternions yields again unit quaternion in theory. However, due to limited machine precision, rounding errors accumulate in practice and the resulting norm may deviate from $1$ more and more. Thus, when you multiply a unit quaternions many times, then you need to adjust the norm. This can be done by calling the function adjust_norm().

See also Quaternion.

Implementations§

source§

impl<T> UnitQuaternion<T>
where T: Float,

source

pub fn from_euler_angles(roll: T, pitch: T, yaw: T) -> Self

Creates a new Quaternion from roll, pitch and yaw angles.

source

pub fn from_rotation_vector(v: &[T; 3]) -> Self

Returns a quaternion from a vector which is parallel to the rotation axis and whose norm is the rotation angle.

source§

impl<T> UnitQuaternion<T>
where T: ConstZero + ConstOne,

source

pub const ONE: Self = _

A constant UnitQuaternion of value $1$.

See also UnitQuaternion::one(), Quaternion::ONE.

source

pub const I: Self = _

A constant UnitQuaternion of value $i$.

See also UnitQuaternion::i(), Quaternion::I.

source

pub const J: Self = _

A constant UnitQuaternion of value $j$.

See also UnitQuaternion::j(), Quaternion::J.

source

pub const K: Self = _

A constant UnitQuaternion of value $k$.

See also UnitQuaternion::k(), Quaternion::K.

source§

impl<T> UnitQuaternion<T>
where T: Zero + One,

source

pub fn i() -> Self

Returns the imaginary unit $i$.

See also UnitQuaternion::I, Quaternion::i().

source

pub fn j() -> Self

Returns the imaginary unit $j$.

See also UnitQuaternion::J, Quaternion::j().

source

pub fn k() -> Self

Returns the imaginary unit $k$.

See also UnitQuaternion::K, Quaternion::k().

source§

impl<T> UnitQuaternion<T>

source

pub fn into_quaternion(self) -> Quaternion<T>

Returns the inner quaternion.

source

pub fn as_quaternion(&self) -> &Quaternion<T>

Returns a reference to the inner quaternion.

source§

impl<T> UnitQuaternion<T>
where T: Clone + Neg<Output = T>,

source

pub fn conj(&self) -> Self

Returns the conjugate quaternion. i.e. the imaginary part is negated.

source§

impl<T> UnitQuaternion<T>
where T: Clone + Neg<Output = T>,

source

pub fn inv(&self) -> Self

Returns the multiplicative inverse 1/self.

This is the same as the conjugate of self.

source§

impl<T> UnitQuaternion<T>
where T: Float,

source

pub fn adjust_norm(self) -> Self

Renormalizes self.

By many multiplications of unit quaternions, round off errors can lead to norms which are deviating from $1$. This function fix that inaccuracy.

source§

impl<T> UnitQuaternion<T>
where T: Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Clone,

source

pub fn rotate_vector(self, vector: [T; 3]) -> [T; 3]

Rotates a vector using a quaternion.

Given a unit quaternion $q$ and a pure quaternion $v$ (i. e. a quaternion with real part zero), the mapping $v \mapsto q^*vq$ is a 3D rotation in the space of pure quaternions. This function performs this 3D rotation efficiently.

Trait Implementations§

source§

impl<T> Add<Quaternion<T>> for UnitQuaternion<T>
where Quaternion<T>: Add<Output = Quaternion<T>>,

§

type Output = Quaternion<T>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl<T> Add<T> for UnitQuaternion<T>
where Quaternion<T>: Add<T, Output = Quaternion<T>>,

§

type Output = Quaternion<T>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl<T> Add<UnitQuaternion<T>> for Quaternion<T>
where T: Add<T, Output = T>,

§

type Output = Quaternion<T>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Add<UnitQuaternion<f32>> for f32

§

type Output = Quaternion<f32>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Add<UnitQuaternion<f64>> for f64

§

type Output = Quaternion<f64>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl<T> Add for UnitQuaternion<T>
where Quaternion<T>: Add<Output = Quaternion<T>>,

§

type Output = Quaternion<T>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl<T> Borrow<Quaternion<T>> for UnitQuaternion<T>

source§

fn borrow(&self) -> &Quaternion<T>

Immutably borrows from an owned value. Read more
source§

impl<T: Clone> Clone for UnitQuaternion<T>

source§

fn clone(&self) -> UnitQuaternion<T>

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<T> ConstOne for UnitQuaternion<T>
where T: ConstZero + ConstOne + Num + Clone,

source§

const ONE: Self = Self::ONE

The multiplicative identity element of Self, 1.
source§

impl<T: Debug> Debug for UnitQuaternion<T>

source§

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

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

impl<T> Default for UnitQuaternion<T>
where T: Num + Clone,

source§

fn default() -> Self

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

impl<T> Div<Quaternion<T>> for UnitQuaternion<T>
where Quaternion<T>: Div<Output = Quaternion<T>>,

§

type Output = Quaternion<T>

The resulting type after applying the / operator.
source§

fn div(self, rhs: Quaternion<T>) -> Self::Output

Performs the / operation. Read more
source§

impl<T> Div<T> for UnitQuaternion<T>
where Quaternion<T>: Div<T, Output = Quaternion<T>>,

§

type Output = Quaternion<T>

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl<T> Div<UnitQuaternion<T>> for Quaternion<T>
where Quaternion<T>: Mul<Output = Quaternion<T>>, T: Neg<Output = T> + Clone,

§

type Output = Quaternion<T>

The resulting type after applying the / operator.
source§

fn div(self, rhs: UnitQuaternion<T>) -> Self::Output

Performs the / operation. Read more
source§

impl Div<UnitQuaternion<f32>> for f32

§

type Output = Quaternion<f32>

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl Div<UnitQuaternion<f64>> for f64

§

type Output = Quaternion<f64>

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl<T> Div for UnitQuaternion<T>
where Quaternion<T>: Mul<Output = Quaternion<T>>, T: Clone + Neg<Output = T>,

§

type Output = UnitQuaternion<T>

The resulting type after applying the / operator.
source§

fn div(self, rhs: UnitQuaternion<T>) -> Self::Output

Performs the / operation. Read more
source§

impl<'a, T> From<&'a UnitQuaternion<T>> for &'a Quaternion<T>

source§

fn from(q: &'a UnitQuaternion<T>) -> Self

Converts to this type from the input type.
source§

impl<T> From<UnitQuaternion<T>> for Quaternion<T>

source§

fn from(q: UnitQuaternion<T>) -> Self

Converts to this type from the input type.
source§

impl<T: Hash> Hash for UnitQuaternion<T>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T> Inv for &UnitQuaternion<T>
where T: Clone + Neg<Output = T>,

§

type Output = UnitQuaternion<T>

The result after applying the operator.
source§

fn inv(self) -> Self::Output

Returns the multiplicative inverse of self. Read more
source§

impl<T> Inv for UnitQuaternion<T>
where T: Clone + Neg<Output = T>,

§

type Output = UnitQuaternion<T>

The result after applying the operator.
source§

fn inv(self) -> Self::Output

Returns the multiplicative inverse of self. Read more
source§

impl<T> Mul<Quaternion<T>> for UnitQuaternion<T>
where Quaternion<T>: Mul<Output = Quaternion<T>>,

§

type Output = Quaternion<T>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl<T> Mul<T> for UnitQuaternion<T>
where Quaternion<T>: Mul<T, Output = Quaternion<T>>,

§

type Output = Quaternion<T>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl<T> Mul<UnitQuaternion<T>> for Quaternion<T>
where Quaternion<T>: Mul<Output = Quaternion<T>>,

§

type Output = Quaternion<T>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<UnitQuaternion<f32>> for f32

§

type Output = Quaternion<f32>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<UnitQuaternion<f64>> for f64

§

type Output = Quaternion<f64>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl<T> Mul for UnitQuaternion<T>
where Quaternion<T>: Mul<Output = Quaternion<T>>,

§

type Output = UnitQuaternion<T>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl<T> Neg for UnitQuaternion<T>
where T: Neg<Output = T>,

§

type Output = UnitQuaternion<T>

The resulting type after applying the - operator.
source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
source§

impl<T> One for UnitQuaternion<T>
where T: Num + Clone,

source§

fn one() -> Self

Returns the multiplicative identity element of Self, 1. Read more
source§

fn is_one(&self) -> bool

Returns true if self is equal to the multiplicative identity. Read more
source§

fn set_one(&mut self)

Sets self to the multiplicative identity element of Self, 1.
source§

impl<T: PartialEq> PartialEq for UnitQuaternion<T>

source§

fn eq(&self, other: &UnitQuaternion<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> Sub<Quaternion<T>> for UnitQuaternion<T>
where Quaternion<T>: Sub<Output = Quaternion<T>>,

§

type Output = Quaternion<T>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl<T> Sub<T> for UnitQuaternion<T>
where Quaternion<T>: Sub<T, Output = Quaternion<T>>,

§

type Output = Quaternion<T>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl<T> Sub<UnitQuaternion<T>> for Quaternion<T>
where T: Sub<T, Output = T>,

§

type Output = Quaternion<T>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub<UnitQuaternion<f32>> for f32

§

type Output = Quaternion<f32>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub<UnitQuaternion<f64>> for f64

§

type Output = Quaternion<f64>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl<T> Sub for UnitQuaternion<T>
where Quaternion<T>: Sub<Output = Quaternion<T>>,

§

type Output = Quaternion<T>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl<T: Copy> Copy for UnitQuaternion<T>

source§

impl<T: Eq> Eq for UnitQuaternion<T>

source§

impl<T> StructuralPartialEq for UnitQuaternion<T>

Auto Trait Implementations§

§

impl<T> Freeze for UnitQuaternion<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for UnitQuaternion<T>
where T: RefUnwindSafe,

§

impl<T> Send for UnitQuaternion<T>
where T: Send,

§

impl<T> Sync for UnitQuaternion<T>
where T: Sync,

§

impl<T> Unpin for UnitQuaternion<T>
where T: Unpin,

§

impl<T> UnwindSafe for UnitQuaternion<T>
where T: 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> 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,

§

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

§

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

§

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.