Trait geo_nd::Quaternion

source ·
pub trait Quaternion<F, V3, V4>: Clone + Copy + Debug + Display + Default + AsRef<[F; 4]> + AsMut<[F; 4]> + AsRef<[F]> + AsMut<[F]> + Index<usize, Output = F> + IndexMut<usize> + Neg<Output = Self> + Add<Self, Output = Self> + AddAssign<Self> + Sub<Self, Output = Self> + SubAssign<Self> + Mul<F, Output = Self> + MulAssign<F> + Div<F, Output = Self> + DivAssign<F> + Mul<Self, Output = Self> + MulAssign<Self> + Div<Self, Output = Self> + DivAssign<Self>where
    V3: Vector<F, 3>,
    V4: Vector<F, 4>,
    F: Float,{
Show 28 methods // Required methods fn from_array(data: [F; 4]) -> Self; fn of_rijk(r: F, i: F, j: F, k: F) -> Self; fn unit() -> Self; fn of_rotation3<M>(rotation: &M) -> Self where M: SqMatrix<V3, F, 3, 9>; fn into_array(self) -> [F; 4]; fn as_rijk(&self) -> (F, F, F, F); fn set_zero(&mut self); fn mix(self, other: &Self, t: F) -> Self; fn dot(self, other: &Self) -> F; fn set_rotation3<M>(&self, m: &mut M) where M: SqMatrix<V3, F, 3, 9>; fn set_rotation4<M>(&self, m: &mut M) where M: SqMatrix<V4, F, 4, 16>; // Provided methods fn conjugate(self) -> Self { ... } fn of_axis_angle(axis: &V3, angle: F) -> Self { ... } fn rotate_x(self, angle: F) -> Self { ... } fn rotate_y(self, angle: F) -> Self { ... } fn rotate_z(self, angle: F) -> Self { ... } fn look_at(dirn: &V3, up: &V3) -> Self { ... } fn rotation_of_vec_to_vec(a: &V3, b: &V3) -> Self { ... } fn weighted_average_pair(&self, w_a: F, qb: &Self, w_b: F) -> Self { ... } fn weighted_average_many<I: Iterator<Item = (F, Self)>>( value_iter: I ) -> Self { ... } fn as_axis_angle(&self) -> (V3, F) { ... } fn length_sq(&self) -> F { ... } fn length(&self) -> F { ... } fn distance_sq(&self, other: &Self) -> F { ... } fn distance(&self, other: &Self) -> F { ... } fn normalize(self) -> Self { ... } fn apply3(self, other: &V3) -> V3 { ... } fn apply4(self, other: &V4) -> V4 { ... }
}
Expand description

The Quaternion trait describes a 4-dimensional vector of Float type.

Such Quaternions support basic arithmetic using addition and subtraction, and they provide quaternion multiplication and division.

They also support basic arithmetic to all components of the Quaternion for addition, subtraction, multiplication and division by a scalar Float value type that they are comprised of. Hence a q:Quaternion<F> may be scaled by a s:F using q * s.

The Quaternion can be indexed only by a usize; that is individual components of the vector can be accessed, but ranges may not.

Required Methods§

source

fn from_array(data: [F; 4]) -> Self

Create a quaternion from an array of Float

The order must be [i, j, k, r]

source

fn of_rijk(r: F, i: F, j: F, k: F) -> Self

Create from r, i, j, k

source

fn unit() -> Self

Create a quaternion whose elements are all zero

source

fn of_rotation3<M>(rotation: &M) -> Selfwhere M: SqMatrix<V3, F, 3, 9>,

Find the unit quaternion of a Matrix3 assuming it is purely a rotation

source

fn into_array(self) -> [F; 4]

Create an array Float for the fquaternion in order i, j, k, r

source

fn as_rijk(&self) -> (F, F, F, F)

Break out into r, i, j, k

source

fn set_zero(&mut self)

Set the quaternion to be all zeros

source

fn mix(self, other: &Self, t: F) -> Self

Create a linear combination of this Quaternion and another using parameter t from zero to one

source

fn dot(self, other: &Self) -> F

Return the dot product of two quaternions; basically used for length

source

fn set_rotation3<M>(&self, m: &mut M)where M: SqMatrix<V3, F, 3, 9>,

Set a Matrix3 to be the rotation matrix corresponding to the unit quaternion

source

fn set_rotation4<M>(&self, m: &mut M)where M: SqMatrix<V4, F, 4, 16>,

Set a Matrix4 to be the rotation matrix corresponding to the unit quaternion

Provided Methods§

source

fn conjugate(self) -> Self

Create the conjugate of a quaternion

source

fn of_axis_angle(axis: &V3, angle: F) -> Self

Create a unit quaternion for a rotation of an angle about an axis

source

fn rotate_x(self, angle: F) -> Self

Apply a rotation about the X-axis to this quaternion

source

fn rotate_y(self, angle: F) -> Self

Apply a rotation about the Y-axis to this quaternion

source

fn rotate_z(self, angle: F) -> Self

Apply a rotation about the Z-axis to this quaternion

source

fn look_at(dirn: &V3, up: &V3) -> Self

Create a quaternion that maps a unit V3 of dirn to (0,0,-1) and a unit V3 of up (if perpendicular to dirn) to (0,1,0)

source

fn rotation_of_vec_to_vec(a: &V3, b: &V3) -> Self

Get a quaternion that is a rotation of one vector to another

The vectors must be unit vectors

source

fn weighted_average_pair(&self, w_a: F, qb: &Self, w_b: F) -> Self

Calculate the weighted average of two unit quaternions

w_a + w_b must be 1.

See http://www.acsu.buffalo.edu/~johnc/ave_quat07.pdf Averaging Quaternions by F. Landis Markley

source

fn weighted_average_many<I: Iterator<Item = (F, Self)>>(value_iter: I) -> Self

Calculate the weighted average of many unit quaternions

weights need not add up to 1

This is an approximation compared to the Landis Markley paper

source

fn as_axis_angle(&self) -> (V3, F)

Find the axis and angle of rotation for a (non-unit) quaternion

source

fn length_sq(&self) -> F

Return the square of the length of the quaternion

source

fn length(&self) -> F

Return the length of the quaternion

source

fn distance_sq(&self, other: &Self) -> F

Return the square of the distance between this quaternion and another

source

fn distance(&self, other: &Self) -> F

Return the distance between this quaternion and another

source

fn normalize(self) -> Self

Normalize the quaternion; if its length is close to zero, then set it to be zero

source

fn apply3(self, other: &V3) -> V3

Apply the quaternion to a V3

source

fn apply4(self, other: &V4) -> V4

Apply the quaternion to a V4

Implementors§

source§

impl<F, V3, V4> Quaternion<F, V3, V4> for QArray<F, V3, V4>where F: Float, V3: Vector<F, 3>, V4: Vector<F, 4>,