pub struct Quaternion<T = Scalar> {
pub w: T,
pub x: T,
pub y: T,
pub z: T,
}Expand description
A quaternion w + x i + y j + z k.
Fields§
§w: T§x: T§y: T§z: TImplementations§
Source§impl<T: Number> Quaternion<T>
impl<T: Number> Quaternion<T>
pub fn new(w: T, x: T, y: T, z: T) -> Self
pub fn identity() -> Self
Sourcepub fn is_identity(&self) -> bool
pub fn is_identity(&self) -> bool
Whether it is exactly the identity: every component sharp, 1 and
three 0s — no rotation at all, rather than one too small to tell.
Sourcepub fn components(&self) -> [T; 4]
pub fn components(&self) -> [T; 4]
Its components [w, x, y, z].
Sourcepub fn map<U: Number>(&self, f: impl Fn(T) -> U) -> Quaternion<U>
pub fn map<U: Number>(&self, f: impl Fn(T) -> U) -> Quaternion<U>
Every component mapped by f.
pub fn mul(&self, o: &Self) -> Self
pub fn conj(&self) -> Self
pub fn scale(&self, s: T) -> Self
pub fn add(&self, o: &Self) -> Self
pub fn dot(&self, o: &Self) -> T
pub fn norm_sq(&self) -> T
Sourcepub fn normalized(&self) -> GeopResult<Self>
pub fn normalized(&self) -> GeopResult<Self>
The unit quaternion of the same rotation; fails for one that could be zero, which stands for no rotation at all.
Sourcepub fn from_euler(degrees: [T; 3]) -> GeopResult<Self>
pub fn from_euler(degrees: [T; 3]) -> GeopResult<Self>
Turning by degrees about x, then y, then z — the world’s axes.
Sourcepub fn from_rotation_columns(columns: [Vector3<T>; 3]) -> GeopResult<Self>
pub fn from_rotation_columns(columns: [Vector3<T>; 3]) -> GeopResult<Self>
The rotation whose matrix has the columns columns — where x, y
and z turn to, orthonormal and right-handed: the inverse of
Quaternion::rotation_columns, up to sign. Of the four ways to
read it off the matrix (Shepperd’s), the one dividing by the largest
of the trace and the diagonal: a free choice, and the
well-conditioned one.
Sourcepub fn rotation_columns(&self) -> GeopResult<[Vector3<T>; 3]>
pub fn rotation_columns(&self) -> GeopResult<[Vector3<T>; 3]>
The rotation it stands for, as a matrix’s columns — where x, y
and z turn to. It need not be unit: dividing by its norm squared
makes the rotation of any non-zero quaternion, smoothly.
Trait Implementations§
Source§impl<T: Clone> Clone for Quaternion<T>
impl<T: Clone> Clone for Quaternion<T>
Source§fn clone(&self) -> Quaternion<T>
fn clone(&self) -> Quaternion<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more