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