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>{
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§
Sourcefn from_array(data: [F; 4]) -> Self
fn from_array(data: [F; 4]) -> Self
Create a quaternion from an array of Float
The order must be [i, j, k, r]
Sourcefn of_rotation3<M>(rotation: &M) -> Selfwhere
M: SqMatrix<V3, F, 3, 9>,
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
Sourcefn into_array(self) -> [F; 4]
fn into_array(self) -> [F; 4]
Create an array Float for the fquaternion in order i, j, k, r
Sourcefn as_rijk(&self) -> (F, F, F, F)
fn as_rijk(&self) -> (F, F, F, F)
Break out into r, i, j, k
Sourcefn mix(self, other: &Self, t: F) -> Self
fn mix(self, other: &Self, t: F) -> Self
Create a linear combination of this Quaternion and another using parameter t
from zero to one
Sourcefn dot(self, other: &Self) -> F
fn dot(self, other: &Self) -> F
Return the dot product of two quaternions; basically used for length
Sourcefn set_rotation3<M>(&self, m: &mut M)where
M: SqMatrix<V3, F, 3, 9>,
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
Sourcefn set_rotation4<M>(&self, m: &mut M)where
M: SqMatrix<V4, F, 4, 16>,
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§
Sourcefn of_axis_angle(axis: &V3, angle: F) -> Self
fn of_axis_angle(axis: &V3, angle: F) -> Self
Create a unit quaternion for a rotation of an angle about an axis
Sourcefn look_at(dirn: &V3, up: &V3) -> Self
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)
Sourcefn rotation_of_vec_to_vec(a: &V3, b: &V3) -> Self
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
Sourcefn weighted_average_pair(&self, w_a: F, qb: &Self, w_b: F) -> Self
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
Sourcefn weighted_average_many<I: Iterator<Item = (F, Self)>>(value_iter: I) -> Self
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
Sourcefn as_axis_angle(&self) -> (V3, F)
fn as_axis_angle(&self) -> (V3, F)
Find the axis and angle of rotation for a (non-unit) quaternion
Sourcefn distance_sq(&self, other: &Self) -> F
fn distance_sq(&self, other: &Self) -> F
Return the square of the distance between this quaternion and another
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.