Struct num_quaternion::Quaternion

source ·
pub struct Quaternion<T> {
    pub w: T,
    pub x: T,
    pub y: T,
    pub z: T,
}
Expand description

Quaternion type.

We follow the naming conventions from Wikipedia for quaternions. You can generate quaternions using the new function:

// 1 + 2i + 3j + 4k
let q = Quaternion::new(1.0f32, 2.0, 3.0, 4.0);

Alternatively, you can construct quaternions directly with the member data fields:

let q = Q32 { w: 1.0, x: 2.0, y: 3.0, z: 4.0 };

This is exactly equivalent to the first method. The latter example uses the shorthand Q32 for Quaternion<f32>. For your convenience, there are also the member constants ONE, I, J, and K for the mathematical values $1$, $i$, $j$, and $k$, respectively.

Quaternions support the usual arithmetic operations of addition, subtraction, multiplication, and division. You can compute the norm with norm and its square with norm_sqr. Quaternion conjugation is done by the member function conj. You can normalize a quaternion by calling normalize, which returns a UnitQuaternion.

To work with rotations, please use UnitQuaternions.

§Examples

Basic usage:

let q1 = Quaternion::new(1.0f32, 0.0, 0.0, 0.0);
let q2 = Quaternion::new(0.0, 1.0, 0.0, 0.0);
let q3 = q1 + q2;
assert_eq!(q3, Quaternion::new(1.0, 1.0, 0.0, 0.0));

§Fields

  • w: Real part of the quaternion.
  • x: The coefficient of $i$.
  • y: The coefficient of $j$.
  • z: The coefficient of $k$.

Fields§

§w: T

Real part of the quaternion.

§x: T

The coefficient of $i$.

§y: T

The coefficient of $j$.

§z: T

The coefficient of $k$.

Implementations§

source§

impl<T> Quaternion<T>

source

pub const fn new(w: T, x: T, y: T, z: T) -> Self

Create a new quaternion $a + bi + cj + dk$.

source§

impl<T> Quaternion<T>
where T: ConstZero,

source

pub const ZERO: Self = _

A constant zero Quaternion.

source§

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

source

pub const ONE: Self = _

A constant Quaternion of value $1$.

See also Quaternion::one.

source

pub const I: Self = _

A constant Quaternion of value $i$.

See also Quaternion::i.

source

pub const J: Self = _

A constant Quaternion of value $j$.

See also Quaternion::j.

source

pub const K: Self = _

A constant Quaternion of value $k$.

See also Quaternion::k.

source§

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

source

pub fn i() -> Self

Returns the imaginary unit $i$.

See also Quaternion::I.

source

pub fn j() -> Self

Returns the imaginary unit $j$.

See also Quaternion::J.

source

pub fn k() -> Self

Returns the imaginary unit $k$.

See also Quaternion::K.

source§

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

source

pub fn nan() -> Self

Returns a quaternion filled with NAN values.

source§

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

source

pub fn norm_sqr(&self) -> T

Returns the square of the norm.

The result is $w^2 + x^2 + y^2 + z^2$ with some rounding errors. The rounding error is at most 2 ulps.

This is guaranteed to be more efficient than norm. Furthermore, T only needs to support addition and multiplication and therefore, this function works for more types than norm.

source§

impl<T> Quaternion<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> Quaternion<T>
where for<'a> &'a Self: Inv<Output = Quaternion<T>>,

source

pub fn inv(&self) -> Self

Returns the multiplicative inverse 1/self.

source§

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

source

pub fn norm(self) -> T

Calculates |self|.

The result is $\sqrt{w^2+x^2+y^2+z^2}$ with some possible rounding errors. The total relative rounding error is at most two ulps.

If any of the components of the input quaternion is NaN, then NaN is returned. Otherwise, if any of the components is infinite, then a positive infinite value is returned.

source

pub fn fast_norm(self) -> T

Calculates |self| without branching.

This function returns the same result as norm, if |self|² is a normal floating point number (i. e. there is no overflow nor underflow), or if self is zero. In these cases the maximum relative error of the result is guaranteed to be less than two ulps. In all other cases, there’s no guarantee on the precision of the result:

  • If |self|² overflows, then $\infty$ is returned.
  • If |self|² underflows to zero, then zero will be returned.
  • If |self|² is a subnormal number (very small floating point value with reduced relative precision), then the result is the square root of that.

In other words, this function can be imprecise for very large and very small floating point numbers, but it is generally faster than norm, because it does not do any branching. So if you are interested in maximum speed of your code, feel free to use this function. If you need to be precise results for the whole range of the floating point type T, stay with norm.

source

pub fn normalize(self) -> Option<UnitQuaternion<T>>

Normalizes the quaternion to length $1$.

The sign of the real part will be the same as the sign of the input. If the input quaternion

  • is zero, or
  • has infinite length, or
  • has a NaN value, then None will be returned.
source§

impl<T> Quaternion<T>
where T: Add<T, Output = T> + Mul<T, Output = T>,

source

pub fn dot(self, other: Self) -> T

Computes the dot product of two quaternions interpreted as 4D real vectors.

source§

impl<T> Quaternion<T>
where T: Num + Clone,

source

pub fn powu(&self, n: u32) -> Self

Raises self to an unsigned integer power n, i. e. $q^n$.

source§

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

source

pub fn powi(&self, n: i32) -> Self

Raises self to a signed integer power n, i. e. $q^n$

For $n=0$ the result is exactly $1$.

source§

impl<T> Quaternion<T>
where T: Float + FloatConst,

source

pub fn exp(self) -> Self

Given a quaternion $q$, returns $e^q$, where $e$ is the base of the natural logarithm.

This method computes the exponential of a quaternion, handling various edge cases to ensure numerical stability and correctness:

  1. Negative Real Part: If the real part is sufficiently negative, such that $e^{\Re q}$ is approximately zero, the method returns zero. This is done even if the imaginary part contains infinite or NaN values.

  2. NaN Input: If any component of the input quaternion is NaN, the method returns a quaternion filled with NaN values.

  3. Large Imaginary Norm: If the norm of the imaginary part is too large, the method may return a NaN quaternion or a quaternion with the correct magnitude but inaccurate direction.

  4. Infinite Result: If $e^{\Re q}$ results in +∞, the method computes the direction and returns an infinite quaternion in that direction, ensuring that ∞ * 0 values are mapped to zero instead of NaN.

  5. Finite Norm: For finite norms, the method ensures a very small relative error in all components, depending on the accuracy of the underlying floating point function implementations.

source

pub fn ln(self) -> Self

Computes the natural logarithm of a quaternion.

The function implements the following guarantees for extreme input values:

  • The function is continuous onto the branch cut taking into account the sign of the coefficient of $i$.
  • For all quaternions $q$ it holds q.conj().ln() == q.ln().conj().
  • The signs of the coefficients of the imaginary parts of the outputs are equal to the signs of the respective coefficients of the inputs. This also holds for signs of zeros, but not for NaNs.
  • If $q = -0 + 0i$, the result is $-\infty+\pi i$. (The coefficients of $j$ and $k$ are zero with the signs copied.)
  • If $q = +0$, the result is $-\infty$.
  • If the input has a NaN value, then the result is NaN in all components.
  • Otherwise, if $q = w + xi + yj + zk$ where at least one of $w, x, y, z$ is infinite, then the real part of the result is $+\infty$ and the imaginary part is the imaginary part of the logarithm of $f(w) + f(x)i + f(y)j + f(z)k$ where
    • $f(+\infty) := 1$,
    • $f(-\infty) :=-1$, and
    • $f(s) := 0$ for finite values of $s$.
source

pub fn sqrt(self) -> Self

Given the input quaternion $c$, this function returns the quaternion $q$ which satisfies $q^2 = c$ and has a real part with a positive sign.

For extreme values, the following guarantees are implemented:

  • If any coefficient in $c$ is NaN, then the result is NaN in all components.
  • Otherwise, for any input $c$, the expression c.sqrt().conj() is exactly equivalent to c.conj().sqrt(), including the signs of zeros and infinities, if any.
  • For any input $c$, c.sqrt().w always has a positive sign.
  • For any input $c$, the signs of the three output imaginary parts are the same as the input imaginary parts in their respective order, except in the case of a NaN input.
  • For negative real inputs $c$, the result is $\pm\sqrt{-c} i$, where the sign is determined by the sign of the input’s coefficient of $i$.
  • If there is at least one infinite coefficient in the imaginary part, then the result will have the same infinite imaginary coefficients and the real part is $+\infty$. All other coefficients of the result are $0$ with the sign of the respective input.
  • If the real part is $-\infty$ and the imaginary part is finite, then the result is $\pm\infty i$ with the sign of the coefficient of $i$ from the input.

Trait Implementations§

source§

impl<T> Add<&Quaternion<T>> for &Quaternion<T>
where Quaternion<T>: Add<Quaternion<T>> + Clone,

§

type Output = <Quaternion<T> as Add>::Output

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<&Quaternion<T>> for &UnitQuaternion<T>

§

type Output = <UnitQuaternion<T> as Add<Quaternion<T>>>::Output

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<&Quaternion<T>> for Quaternion<T>
where Self: Add<Quaternion<T>>, Quaternion<T>: Clone,

§

type Output = <Quaternion<T> as Add>::Output

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<&Quaternion<T>> for UnitQuaternion<T>
where Self: Add<Quaternion<T>>, Quaternion<T>: Clone,

§

type Output = <UnitQuaternion<T> as Add<Quaternion<T>>>::Output

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 &Quaternion<T>
where Quaternion<T>: Add<T> + Clone, T: Clone,

§

type Output = <Quaternion<T> as Add<T>>::Output

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl<T> Add<&T> for Quaternion<T>
where Self: Add<T>, T: Clone,

§

type Output = <Quaternion<T> as Add<T>>::Output

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>

§

type Output = <Quaternion<T> as Add<UnitQuaternion<T>>>::Output

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl<T> Add<&UnitQuaternion<T>> for Quaternion<T>
where Self: Add<UnitQuaternion<T>>, UnitQuaternion<T>: Clone,

§

type Output = <Quaternion<T> as Add<UnitQuaternion<T>>>::Output

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl<T> Add<Quaternion<T>> for &Quaternion<T>
where Quaternion<T>: Add<Quaternion<T>> + Clone,

§

type Output = <Quaternion<T> as Add>::Output

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<Quaternion<T>> for &UnitQuaternion<T>

§

type Output = <UnitQuaternion<T> as Add<Quaternion<T>>>::Output

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<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 Add<Quaternion<f32>> for f32

§

type Output = Quaternion<f32>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Add<Quaternion<f64>> for f64

§

type Output = Quaternion<f64>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Add<Quaternion<i128>> for i128

§

type Output = Quaternion<i128>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Add<Quaternion<i16>> for i16

§

type Output = Quaternion<i16>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Add<Quaternion<i32>> for i32

§

type Output = Quaternion<i32>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Add<Quaternion<i64>> for i64

§

type Output = Quaternion<i64>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Add<Quaternion<i8>> for i8

§

type Output = Quaternion<i8>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Add<Quaternion<isize>> for isize

§

type Output = Quaternion<isize>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Add<Quaternion<u128>> for u128

§

type Output = Quaternion<u128>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Add<Quaternion<u16>> for u16

§

type Output = Quaternion<u16>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Add<Quaternion<u32>> for u32

§

type Output = Quaternion<u32>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Add<Quaternion<u64>> for u64

§

type Output = Quaternion<u64>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Add<Quaternion<u8>> for u8

§

type Output = Quaternion<u8>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Add<Quaternion<usize>> for usize

§

type Output = Quaternion<usize>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl<T> Add<T> for &Quaternion<T>
where Quaternion<T>: Add<T> + Clone,

§

type Output = <Quaternion<T> as Add<T>>::Output

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl<T> Add<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: T) -> Self::Output

Performs the + operation. Read more
source§

impl<T> Add<UnitQuaternion<T>> for &Quaternion<T>

§

type Output = <Quaternion<T> as Add<UnitQuaternion<T>>>::Output

The resulting type after applying the + operator.
source§

fn add(self, rhs: UnitQuaternion<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<T> Add 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: Quaternion<T>) -> Self::Output

Performs the + operation. Read more
source§

impl<T, S> AddAssign<S> for Quaternion<T>
where Self: Add<S, Output = Self> + Clone,

source§

fn add_assign(&mut self, other: S)

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 Quaternion<T>

source§

fn clone(&self) -> Quaternion<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 Quaternion<T>
where T: ConstZero + ConstOne + Num + Clone,

source§

const ONE: Self = Self::ONE

The multiplicative identity element of Self, 1.
source§

impl<T> ConstZero for Quaternion<T>
where T: ConstZero,

source§

const ZERO: Self = Self::ZERO

The additive identity element of Self, 0.
source§

impl<T: Debug> Debug for Quaternion<T>

source§

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

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

impl<T: Default> Default for Quaternion<T>

source§

fn default() -> Quaternion<T>

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

impl<'de, T> Deserialize<'de> for Quaternion<T>
where T: Deserialize<'de>,

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<T> Div<&Quaternion<T>> for &Quaternion<T>
where Quaternion<T>: Div<Quaternion<T>> + Clone,

§

type Output = <Quaternion<T> as Div>::Output

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<&Quaternion<T>> for &UnitQuaternion<T>

§

type Output = <UnitQuaternion<T> as Div<Quaternion<T>>>::Output

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<&Quaternion<T>> for Quaternion<T>
where Self: Div<Quaternion<T>>, Quaternion<T>: Clone,

§

type Output = <Quaternion<T> as Div>::Output

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<&Quaternion<T>> for UnitQuaternion<T>
where Self: Div<Quaternion<T>>, Quaternion<T>: Clone,

§

type Output = <UnitQuaternion<T> as Div<Quaternion<T>>>::Output

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 &Quaternion<T>
where Quaternion<T>: Div<T> + Clone, T: Clone,

§

type Output = <Quaternion<T> as Div<T>>::Output

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl<T> Div<&T> for Quaternion<T>
where Self: Div<T>, T: Clone,

§

type Output = <Quaternion<T> as Div<T>>::Output

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>

§

type Output = <Quaternion<T> as Div<UnitQuaternion<T>>>::Output

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl<T> Div<&UnitQuaternion<T>> for Quaternion<T>
where Self: Div<UnitQuaternion<T>>, UnitQuaternion<T>: Clone,

§

type Output = <Quaternion<T> as Div<UnitQuaternion<T>>>::Output

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl<T> Div<Quaternion<T>> for &Quaternion<T>
where Quaternion<T>: Div<Quaternion<T>> + Clone,

§

type Output = <Quaternion<T> as Div>::Output

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<Quaternion<T>> for &UnitQuaternion<T>

§

type Output = <UnitQuaternion<T> as Div<Quaternion<T>>>::Output

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<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 Div<Quaternion<f32>> for f32

§

type Output = Quaternion<f32>

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl Div<Quaternion<f64>> for f64

§

type Output = Quaternion<f64>

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl<T> Div<T> for &Quaternion<T>
where Quaternion<T>: Div<T> + Clone,

§

type Output = <Quaternion<T> as Div<T>>::Output

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

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

§

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>

§

type Output = <Quaternion<T> as Div<UnitQuaternion<T>>>::Output

The resulting type after applying the / operator.
source§

fn div(self, rhs: UnitQuaternion<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<T> Div for Quaternion<T>
where T: Num + Clone + Neg<Output = 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, S> DivAssign<S> for Quaternion<T>
where Self: Div<S, Output = Self> + Clone,

source§

fn div_assign(&mut self, other: S)

Performs the /= operation. Read more
source§

impl<'a, T> From<&'a T> for Quaternion<T>
where T: Clone + Zero,

source§

fn from(a: &T) -> Self

Converts to this type from the input type.
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<T> for Quaternion<T>
where T: Zero,

source§

fn from(a: 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 Quaternion<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 &Quaternion<T>
where T: Clone + Neg<Output = T> + Num,

§

type Output = Quaternion<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 Quaternion<T>
where for<'a> &'a Self: Inv<Output = Quaternion<T>>,

§

type Output = Quaternion<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 &Quaternion<T>
where Quaternion<T>: Mul<Quaternion<T>> + Clone,

§

type Output = <Quaternion<T> as Mul>::Output

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<&Quaternion<T>> for &UnitQuaternion<T>

§

type Output = <UnitQuaternion<T> as Mul<Quaternion<T>>>::Output

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<&Quaternion<T>> for Quaternion<T>
where Self: Mul<Quaternion<T>>, Quaternion<T>: Clone,

§

type Output = <Quaternion<T> as Mul>::Output

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<&Quaternion<T>> for UnitQuaternion<T>
where Self: Mul<Quaternion<T>>, Quaternion<T>: Clone,

§

type Output = <UnitQuaternion<T> as Mul<Quaternion<T>>>::Output

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 &Quaternion<T>
where Quaternion<T>: Mul<T> + Clone, T: Clone,

§

type Output = <Quaternion<T> as Mul<T>>::Output

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl<T> Mul<&T> for Quaternion<T>
where Self: Mul<T>, T: Clone,

§

type Output = <Quaternion<T> as Mul<T>>::Output

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>

§

type Output = <Quaternion<T> as Mul<UnitQuaternion<T>>>::Output

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl<T> Mul<&UnitQuaternion<T>> for Quaternion<T>
where Self: Mul<UnitQuaternion<T>>, UnitQuaternion<T>: Clone,

§

type Output = <Quaternion<T> as Mul<UnitQuaternion<T>>>::Output

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl<T> Mul<Quaternion<T>> for &Quaternion<T>
where Quaternion<T>: Mul<Quaternion<T>> + Clone,

§

type Output = <Quaternion<T> as Mul>::Output

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<Quaternion<T>> for &UnitQuaternion<T>

§

type Output = <UnitQuaternion<T> as Mul<Quaternion<T>>>::Output

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<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 Mul<Quaternion<f32>> for f32

§

type Output = Quaternion<f32>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<Quaternion<f64>> for f64

§

type Output = Quaternion<f64>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<Quaternion<i128>> for i128

§

type Output = Quaternion<i128>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<Quaternion<i16>> for i16

§

type Output = Quaternion<i16>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<Quaternion<i32>> for i32

§

type Output = Quaternion<i32>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<Quaternion<i64>> for i64

§

type Output = Quaternion<i64>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<Quaternion<i8>> for i8

§

type Output = Quaternion<i8>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<Quaternion<isize>> for isize

§

type Output = Quaternion<isize>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<Quaternion<u128>> for u128

§

type Output = Quaternion<u128>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<Quaternion<u16>> for u16

§

type Output = Quaternion<u16>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<Quaternion<u32>> for u32

§

type Output = Quaternion<u32>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<Quaternion<u64>> for u64

§

type Output = Quaternion<u64>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<Quaternion<u8>> for u8

§

type Output = Quaternion<u8>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<Quaternion<usize>> for usize

§

type Output = Quaternion<usize>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl<T> Mul<T> for &Quaternion<T>
where Quaternion<T>: Mul<T> + Clone,

§

type Output = <Quaternion<T> as Mul<T>>::Output

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

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

§

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>

§

type Output = <Quaternion<T> as Mul<UnitQuaternion<T>>>::Output

The resulting type after applying the * operator.
source§

fn mul(self, rhs: UnitQuaternion<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<T> Mul for Quaternion<T>
where T: Add<T, Output = T> + Sub<T, Output = T> + Mul<T, Output = T> + Clone,

§

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, S> MulAssign<S> for Quaternion<T>
where Self: Mul<S, Output = Self> + Clone,

source§

fn mul_assign(&mut self, other: S)

Performs the *= operation. Read more
source§

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

§

type Output = Quaternion<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 Quaternion<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 Quaternion<T>

source§

fn eq(&self, other: &Quaternion<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> Serialize for Quaternion<T>
where T: Serialize,

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<T> Sub<&Quaternion<T>> for &Quaternion<T>
where Quaternion<T>: Sub<Quaternion<T>> + Clone,

§

type Output = <Quaternion<T> as Sub>::Output

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<&Quaternion<T>> for &UnitQuaternion<T>

§

type Output = <UnitQuaternion<T> as Sub<Quaternion<T>>>::Output

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<&Quaternion<T>> for Quaternion<T>
where Self: Sub<Quaternion<T>>, Quaternion<T>: Clone,

§

type Output = <Quaternion<T> as Sub>::Output

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<&Quaternion<T>> for UnitQuaternion<T>
where Self: Sub<Quaternion<T>>, Quaternion<T>: Clone,

§

type Output = <UnitQuaternion<T> as Sub<Quaternion<T>>>::Output

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 &Quaternion<T>
where Quaternion<T>: Sub<T> + Clone, T: Clone,

§

type Output = <Quaternion<T> as Sub<T>>::Output

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl<T> Sub<&T> for Quaternion<T>
where Self: Sub<T>, T: Clone,

§

type Output = <Quaternion<T> as Sub<T>>::Output

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>

§

type Output = <Quaternion<T> as Sub<UnitQuaternion<T>>>::Output

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl<T> Sub<&UnitQuaternion<T>> for Quaternion<T>
where Self: Sub<UnitQuaternion<T>>, UnitQuaternion<T>: Clone,

§

type Output = <Quaternion<T> as Sub<UnitQuaternion<T>>>::Output

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl<T> Sub<Quaternion<T>> for &Quaternion<T>
where Quaternion<T>: Sub<Quaternion<T>> + Clone,

§

type Output = <Quaternion<T> as Sub>::Output

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<Quaternion<T>> for &UnitQuaternion<T>

§

type Output = <UnitQuaternion<T> as Sub<Quaternion<T>>>::Output

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<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 Sub<Quaternion<f32>> for f32

§

type Output = Quaternion<f32>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub<Quaternion<f64>> for f64

§

type Output = Quaternion<f64>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub<Quaternion<i128>> for i128

§

type Output = Quaternion<i128>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub<Quaternion<i16>> for i16

§

type Output = Quaternion<i16>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub<Quaternion<i32>> for i32

§

type Output = Quaternion<i32>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub<Quaternion<i64>> for i64

§

type Output = Quaternion<i64>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub<Quaternion<i8>> for i8

§

type Output = Quaternion<i8>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub<Quaternion<isize>> for isize

§

type Output = Quaternion<isize>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub<Quaternion<u128>> for u128

§

type Output = Quaternion<u128>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub<Quaternion<u16>> for u16

§

type Output = Quaternion<u16>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub<Quaternion<u32>> for u32

§

type Output = Quaternion<u32>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub<Quaternion<u64>> for u64

§

type Output = Quaternion<u64>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub<Quaternion<u8>> for u8

§

type Output = Quaternion<u8>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub<Quaternion<usize>> for usize

§

type Output = Quaternion<usize>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl<T> Sub<T> for &Quaternion<T>
where Quaternion<T>: Sub<T> + Clone,

§

type Output = <Quaternion<T> as Sub<T>>::Output

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl<T> Sub<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: T) -> Self::Output

Performs the - operation. Read more
source§

impl<T> Sub<UnitQuaternion<T>> for &Quaternion<T>

§

type Output = <Quaternion<T> as Sub<UnitQuaternion<T>>>::Output

The resulting type after applying the - operator.
source§

fn sub(self, rhs: UnitQuaternion<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<T> Sub 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: Quaternion<T>) -> Self::Output

Performs the - operation. Read more
source§

impl<T, S> SubAssign<S> for Quaternion<T>
where Self: Sub<S, Output = Self> + Clone,

source§

fn sub_assign(&mut self, other: S)

Performs the -= operation. Read more
source§

impl<T> Zero for Quaternion<T>
where T: Zero,

source§

fn zero() -> Self

Returns the additive identity element of Self, 0. Read more
source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
source§

impl<T: Copy> Copy for Quaternion<T>

source§

impl<T: Eq> Eq for Quaternion<T>

source§

impl<T> StructuralPartialEq for Quaternion<T>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for Quaternion<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> CloneToUninit for T
where T: Copy,

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> CloneToUninit for T
where T: Clone,

source§

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

§

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.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,