pub struct Quaternion {
pub w: f32,
pub x: f32,
pub y: f32,
pub z: f32,
}Expand description
A quaternion using Hamilton (not JPL) transformation conventions. The most common operations
usedful for representing orientations and rotations are defined, including for operations
with Vec3.
Fields§
§w: f32§x: f32§y: f32§z: f32Implementations§
Source§impl Quaternion
impl Quaternion
pub const fn new_identity() -> Self
pub fn new(w: f32, x: f32, y: f32, z: f32) -> Self
Sourcepub fn from_slice(slice: &[f32]) -> Result<Self, BufError>
pub fn from_slice(slice: &[f32]) -> Result<Self, BufError>
Construct from the first 4 values in a slice: &[w, x, y, z].
Sourcepub fn from_axis_angle(axis: Vec3, angle: f32) -> Self
pub fn from_axis_angle(axis: Vec3, angle: f32) -> Self
Create a rotation quaternion from an axis and angle.
Sourcepub fn from_unit_vecs(v0: Vec3, v1: Vec3) -> Self
pub fn from_unit_vecs(v0: Vec3, v1: Vec3) -> Self
Create the quaternion that creates the shortest (great circle) rotation from vec0 to vec1.
Sourcepub fn from_euler(euler: &EulerAngle) -> Self
pub fn from_euler(euler: &EulerAngle) -> Self
Convert Euler angles to a quaternion. https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles
Sourcepub fn to_euler(&self) -> EulerAngle
pub fn to_euler(&self) -> EulerAngle
Convert this quaternion to Tait-Bryon (Euler) angles. We use this reference: http://marc-b-reynolds.github.io/math/2017/04/18/TaitEuler.html. Most sources online provide us with results that do not behave how we expect.
Sourcepub fn to_axes(&self) -> (f32, f32, f32)
pub fn to_axes(&self) -> (f32, f32, f32)
Convert an attitude to rotations around individual axes. Assumes X is left, Z is Z_VEC, and Y is Y_VEC.
Sourcepub fn slerp(&self, end: Quaternion, amount: f32) -> Quaternion
pub fn slerp(&self, end: Quaternion, amount: f32) -> Quaternion
Performs Spherical Linear Interpolation between this and another quaternion. A high
amount will make the result more towards end. An amount of 0 will result in
this quaternion.
Ref: https://github.com/bitshifter/glam-rs/blob/main/src/$f/scalar/quat.rs#L567
Alternative implementation to examine: https://github.com/MartinWeigel/Quaternion/blob/master/Quaternion.c
Sourcepub fn to_matrix3(&self) -> Mat3
pub fn to_matrix3(&self) -> Mat3
Converts a Quaternion to a rotation matrix
Source§impl Quaternion
impl Quaternion
Sourcepub fn to_normalized(self) -> Self
pub fn to_normalized(self) -> Self
Returns the normalized version of the vector.
pub fn inverse(self) -> Self
Sourcepub fn rotate_vec(self, vec: Vec3) -> Vec3
pub fn rotate_vec(self, vec: Vec3) -> Vec3
Rotate a vector using this quaternion. Note that our multiplication Q * v operation is effectively quaternion multiplication, with a quaternion created by a vec with w=0. Uses the X_VEC hand rule.
Trait Implementations§
Source§impl Add for Quaternion
impl Add for Quaternion
Source§impl Clone for Quaternion
impl Clone for Quaternion
Source§fn clone(&self) -> Quaternion
fn clone(&self) -> Quaternion
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Quaternion
impl Debug for Quaternion
Source§impl Default for Quaternion
impl Default for Quaternion
Source§impl Display for Quaternion
Available on crate feature std only.
impl Display for Quaternion
std only.Source§impl Div<f32> for Quaternion
impl Div<f32> for Quaternion
Source§impl Div for Quaternion
impl Div for Quaternion
Source§impl DivAssign<f32> for Quaternion
impl DivAssign<f32> for Quaternion
Source§fn div_assign(&mut self, rhs: f32)
fn div_assign(&mut self, rhs: f32)
/= operation. Read moreSource§impl From<Quaternion> for Quaternion
impl From<Quaternion> for Quaternion
Source§fn from(other: Quaternion) -> Self
fn from(other: Quaternion) -> Self
Source§impl From<Quaternion> for Quaternion
impl From<Quaternion> for Quaternion
Source§fn from(other: Quaternion) -> Self
fn from(other: Quaternion) -> Self
Source§impl Mul<Vec3> for Quaternion
impl Mul<Vec3> for Quaternion
Source§fn mul(self, rhs: Vec3) -> Self::Output
fn mul(self, rhs: Vec3) -> Self::Output
Returns the multiplication of a Quaternion with a vector. This is a normal Quaternion multiplication where the vector is treated as a Quaternion with a W element value of zero. The Quaternion is post- multiplied by the vector.
Source§type Output = Quaternion
type Output = Quaternion
* operator.Source§impl Mul<f32> for Quaternion
impl Mul<f32> for Quaternion
Source§impl Mul for Quaternion
impl Mul for Quaternion
Source§impl MulAssign<f32> for Quaternion
impl MulAssign<f32> for Quaternion
Source§fn mul_assign(&mut self, rhs: f32)
fn mul_assign(&mut self, rhs: f32)
*= operation. Read more