pub struct Quaternion {
pub w: f64,
pub x: f64,
pub y: f64,
pub z: f64,
}Expand description
A quaternion w + xi + yj + zk.
Fields§
§w: f64Scalar part.
x: f64i coefficient.
y: f64j coefficient.
z: f64k coefficient.
Implementations§
Source§impl Quaternion
impl Quaternion
Sourcepub fn from_axis_angle(axis: Direction, angle: f64) -> Self
pub fn from_axis_angle(axis: Direction, angle: f64) -> Self
The rotation of angle radians about axis, right-handed.
Sourcepub fn between(
from: Direction,
to: Direction,
tol: Tolerances,
) -> OgeomResult<Self>
pub fn between( from: Direction, to: Direction, tol: Tolerances, ) -> OgeomResult<Self>
The shortest rotation taking from to to.
§Errors
OgeomError::Construction if the two are
antiparallel: infinitely many shortest rotations exist and picking one
arbitrarily would make the result depend on unobservable rounding.
Sourcepub fn from_matrix(m: &Matrix3, tol: Tolerances) -> OgeomResult<Self>
pub fn from_matrix(m: &Matrix3, tol: Tolerances) -> OgeomResult<Self>
From a rotation matrix.
Uses Shepperd’s method: pick the largest of the four possible divisors so
the division is never by something near zero. The naive w-first
formulation loses precision for rotations near π, where w → 0.
§Errors
OgeomError::Construction if m is not
orthonormal with determinant +1.
Sourcepub fn square_norm(self) -> f64
pub fn square_norm(self) -> f64
Squared norm.
Sourcepub fn normalized(self, tol: Tolerances) -> OgeomResult<Self>
pub fn normalized(self, tol: Tolerances) -> OgeomResult<Self>
This quaternion scaled to unit norm.
§Errors
OgeomError::Construction if the norm is
below tol.confusion() or any component is non-finite.
Sourcepub const fn conjugate(self) -> Self
pub const fn conjugate(self) -> Self
The conjugate. For a unit quaternion this is the inverse rotation.
Sourcepub fn rotate(self, v: Vector) -> Vector
pub fn rotate(self, v: Vector) -> Vector
Apply this rotation to a vector. Assumes unit norm.
Evaluated as v + 2w(u × v) + 2(u × (u × v)) with u the vector part,
which costs fewer operations than building the matrix and avoids the
intermediate rounding of a full quaternion sandwich product.
Sourcepub fn to_axis_angle(self, tol: Tolerances) -> OgeomResult<(Direction, f64)>
pub fn to_axis_angle(self, tol: Tolerances) -> OgeomResult<(Direction, f64)>
The rotation axis and angle. Assumes unit norm; angle is in [0, π].
§Errors
OgeomError::Construction if the rotation
is the identity, where the axis is undefined.
Sourcepub fn slerp(self, other: Self, t: f64, tol: Tolerances) -> OgeomResult<Self>
pub fn slerp(self, other: Self, t: f64, tol: Tolerances) -> OgeomResult<Self>
Spherical linear interpolation, t = 0 giving self.
Takes the shorter of the two arcs, and falls back to normalized linear
interpolation when the two are nearly coincident, where the sin in the
denominator of the spherical form goes to zero.
§Errors
OgeomError::Construction if either
operand cannot be normalized.
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 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for Quaternion
Source§impl Debug for Quaternion
impl Debug for Quaternion
Source§impl Default for Quaternion
impl Default for Quaternion
Source§impl Mul for Quaternion
impl Mul for Quaternion
Source§impl Mul<f64> for Quaternion
impl Mul<f64> for Quaternion
Source§impl Neg for Quaternion
impl Neg for Quaternion
Source§impl PartialEq for Quaternion
impl PartialEq for Quaternion
Source§fn eq(&self, other: &Quaternion) -> bool
fn eq(&self, other: &Quaternion) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for Quaternion
Auto Trait Implementations§
impl Freeze for Quaternion
impl RefUnwindSafe for Quaternion
impl Send for Quaternion
impl Sync for Quaternion
impl Unpin for Quaternion
impl UnsafeUnpin for Quaternion
impl UnwindSafe for Quaternion
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ClosedNeg for Twhere
T: Neg<Output = T>,
impl<T> Scalar for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.