Struct cgmath::Quaternion [] [src]

pub struct Quaternion<S> {
    pub s: S,
    pub v: Vector3<S>,
}

A quaternion in scalar/vector form.

Fields

s
v

Methods

impl<S: BaseFloat> Quaternion<S>

fn new(w: S, xi: S, yj: S, zk: S) -> Quaternion<S>

Construct a new quaternion from one scalar component and three imaginary components

fn from_sv(s: S, v: Vector3<S>) -> Quaternion<S>

Construct a new quaternion from a scalar and a vector

fn zero() -> Quaternion<S>

The additive identity, ie: q = 0 + 0i + 0j + 0i

fn identity() -> Quaternion<S>

The multiplicative identity, ie: q = 1 + 0i + 0j + 0i

fn mul_s(&self, value: S) -> Quaternion<S>

The result of multiplying the quaternion a scalar

fn div_s(&self, value: S) -> Quaternion<S>

The result of dividing the quaternion a scalar

fn mul_v(&self, vec: &Vector3<S>) -> Vector3<S>

The result of multiplying the quaternion by a vector

fn add_q(&self, other: &Quaternion<S>) -> Quaternion<S>

The sum of this quaternion and other

fn sub_q(&self, other: &Quaternion<S>) -> Quaternion<S>

The difference between this quaternion and other

fn mul_q(&self, other: &Quaternion<S>) -> Quaternion<S>

The result of multipliplying the quaternion by other

fn mul_self_s(&mut self, s: S)

Multiply this quaternion by a scalar, in-place.

fn div_self_s(&mut self, s: S)

Divide this quaternion by a scalar, in-place.

fn add_self_q(&mut self, q: &Quaternion<S>)

Add this quaternion by another, in-place.

fn sub_self_q(&mut self, q: &Quaternion<S>)

Subtract another quaternion from this one, in-place.

fn mul_self_q(&mut self, q: &Quaternion<S>)

Multiply this quaternion by another, in-place.

fn dot(&self, q: &Quaternion<S>) -> S

The dot product of the quaternion and q.

fn conjugate(&self) -> Quaternion<S>

The conjugate of the quaternion.

fn magnitude2(&self) -> S

The squared magnitude of the quaternion. This is useful for magnitude comparisons where the exact magnitude does not need to be calculated.

fn magnitude(&self) -> S

The magnitude of the quaternion

Performance notes

For instances where the exact magnitude of the quaternion does not need to be known, for example for quaternion-quaternion magnitude comparisons, it is advisable to use the magnitude2 method instead.

fn normalize(&self) -> Quaternion<S>

Normalize this quaternion, returning the new quaternion.

fn nlerp(&self, other: &Quaternion<S>, amount: S) -> Quaternion<S>

Do a normalized linear interpolation with other, by amount.

impl<S: BaseFloat> Quaternion<S>

fn slerp(&self, other: &Quaternion<S>, amount: S) -> Quaternion<S>

Spherical Linear Intoperlation

Return the spherical linear interpolation between the quaternion and other. Both quaternions should be normalized first.

Performance notes

The acos operation used in slerp is an expensive operation, so unless your quarternions are far away from each other it's generally more advisable to use nlerp when you know your rotations are going to be small.

fn to_euler(&self) -> (Rad<S>, Rad<S>, Rad<S>)

Convert a Quaternion to Eular angles This is a polar singularity aware conversion

Based on: - Maths - Conversion Quaternion to Euler

Trait Implementations

impl<S: BaseFloat> From<Matrix3<S>> for Quaternion<S>

fn from(mat: Matrix3<S>) -> Quaternion<S>

impl<S: Copy + BaseFloat> Array1<S> for Quaternion<S>

fn map<F>(&mut self, op: F) -> Quaternion<S> where F: FnMut(S) -> S

fn ptr<'a>(&'a self) -> &'a Element

fn mut_ptr<'a>(&'a mut self) -> &'a mut Element

fn swap_elems(&mut self, i: usize, j: usize)

fn replace_elem(&mut self, i: usize, src: Element) -> Element

impl<S: BaseFloat> Index<usize> for Quaternion<S>

type Output = S

fn index<'a>(&'a self, i: usize) -> &'a S

impl<S: BaseFloat> IndexMut<usize> for Quaternion<S>

fn index_mut<'a>(&'a mut self, i: usize) -> &'a mut S

impl<S: BaseFloat> ApproxEq<S> for Quaternion<S>

fn approx_eq_eps(&self, other: &Quaternion<S>, epsilon: &S) -> bool

fn approx_epsilon(_hack: Option<Self>) -> T

fn approx_eq(&self, other: &Self) -> bool

impl<S: BaseFloat> Neg for Quaternion<S>

type Output = Quaternion<S>

fn neg(self) -> Quaternion<S>

impl<S: BaseFloat> Debug for Quaternion<S>

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

impl<S: BaseFloat + 'static> Rotation<S, Vector3<S>, Point3<S>> for Quaternion<S>

fn identity() -> Quaternion<S>

fn look_at(dir: &Vector3<S>, up: &Vector3<S>) -> Quaternion<S>

fn between_vectors(a: &Vector3<S>, b: &Vector3<S>) -> Quaternion<S>

fn rotate_vector(&self, vec: &Vector3<S>) -> Vector3<S>

fn concat(&self, other: &Quaternion<S>) -> Quaternion<S>

fn concat_self(&mut self, other: &Quaternion<S>)

fn invert(&self) -> Quaternion<S>

fn invert_self(&mut self)

fn rotate_point(&self, point: &P) -> P

fn rotate_ray(&self, ray: &Ray<S, P, V>) -> Ray<S, P, V>

impl<S: BaseFloat> Rotation3<S> for Quaternion<S> where S: 'static

fn from_axis_angle(axis: &Vector3<S>, angle: Rad<S>) -> Quaternion<S>

fn from_euler(x: Rad<S>, y: Rad<S>, z: Rad<S>) -> Quaternion<S>

fn from_angle_x(theta: Rad<S>) -> Self

fn from_angle_y(theta: Rad<S>) -> Self

fn from_angle_z(theta: Rad<S>) -> Self

impl<S: BaseFloat + Rand> Rand for Quaternion<S>

fn rand<R: Rng>(rng: &mut R) -> Quaternion<S>

impl<S: BaseFloat + 'static> From<Basis3<S>> for Quaternion<S>

fn from(b: Basis3<S>) -> Quaternion<S>

Derived Implementations

impl<S: Decodable> Decodable for Quaternion<S>

fn decode<__D: Decoder>(__arg_0: &mut __D) -> Result<Quaternion<S>, __D::Error>

impl<S: Encodable> Encodable for Quaternion<S>

fn encode<__S: Encoder>(&self, __arg_0: &mut __S) -> Result<(), __S::Error>

impl<S: PartialEq> PartialEq for Quaternion<S>

fn eq(&self, __arg_0: &Quaternion<S>) -> bool

fn ne(&self, __arg_0: &Quaternion<S>) -> bool

impl<S: Clone> Clone for Quaternion<S>

fn clone(&self) -> Quaternion<S>

fn clone_from(&mut self, source: &Self)

impl<S: Copy> Copy for Quaternion<S>