Quaternion
struct · ferroui-media3d · v0.5.0
struct Quaternion
A rotation in 3D space, with double-precision components (WPF's
System.Windows.Media.Media3D.Quaternion): (x, y, z) is the axis scaled by the sine of half
the angle, w the cosine of half the angle.
This is the quaternion of the 3D scene model, apart from the single-precision
ferroui_base::numerics::Quaternion of the numerics library. The default value is
Quaternion::IDENTITY, as in WPF.
Members
xyzwIDENTITYnewfrom_axis_angleis_identityis_normalizedaxisangleconjugateinvertnormalizeslerpslerp_with_pathparse
x
x: f64
The X component.
y
y: f64
The Y component.
z
z: f64
The Z component.
w
w: f64
The W component.
IDENTITY
const IDENTITY: Quaternion
The rotation by no angle (WPF's Quaternion.Identity): (0, 0, 0, 1).
new
const fn new(x: f64, y: f64, z: f64, w: f64) -> Self
A quaternion with the given components.
from_axis_angle
fn from_axis_angle(axis_of_rotation: Vector3D, angle_in_degrees: f64) -> Result<Self, QuaternionError>
The rotation about the axis by the angle in degrees, counterclockwise when the axis points
at the viewer. The angle is taken modulo 360 before it is converted to radians, as WPF does;
QuaternionError::ZeroAxis when the axis is the zero vector.
is_identity
fn is_identity(self: &Self) -> bool
Whether this is the identity: (0, 0, 0, 1).
is_normalized
fn is_normalized(self: &Self) -> bool
Whether the quaternion has unit length, within ten machine epsilons of its squared norm.
axis
fn axis(self: &Self) -> Vector3D
The axis of the rotation, a unit vector; (0, 1, 0) when the axis is undetermined (the
identity, and every quaternion whose x, y and z are zero).
angle
fn angle(self: &Self) -> f64
The angle of the rotation in degrees, from 0 to 360, for a quaternion of any length.
conjugate
fn conjugate(self: &mut Self)
Replaces the quaternion by its conjugate: the axis reversed.
invert
fn invert(self: &mut Self)
Replaces the quaternion by its inverse: the conjugate divided by the squared norm. The zero
quaternion becomes NaN components, as in WPF.
normalize
fn normalize(self: &mut Self)
Scales the quaternion to unit length. When the squared norm overflows, the components are first divided by the largest of their magnitudes.
slerp
fn slerp(from: Quaternion, to: Quaternion, t: f64) -> Quaternion
The spherical linear interpolation from from to to at t (0 is from, 1 is to),
along the shorter arc.
slerp_with_path
fn slerp_with_path(from: Quaternion, to: Quaternion, t: f64, use_shortest_path: bool) -> Quaternion
The spherical linear interpolation from from to to at t (WPF's Slerp with
useShortestPath): along the shorter arc when use_shortest_path is true (to is negated
when the two are more than 90 degrees apart in four dimensions), else along the arc between
the quaternions as given.
The inputs need not have unit length: the direction is interpolated between the unit
quaternions, and the length of the result is interpolated geometrically between the lengths
of the inputs. Quaternions closer than a cosine of 1 - 1e-6 are interpolated linearly;
opposite quaternions turn about an arbitrary perpendicular.
parse
fn parse(text: &str) -> Result<Self, FormatError>
Parses the text form: "Identity", or "x,y,z,w" (commas, white space or both between the
numbers) in the invariant culture.
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafeBorrow<T>BorrowMut<T>CloneToUninitInto<U>From<T>TryInto<U>TryFrom<U>AnyToOwnedToStringPropertyValueAnyValueClassDefaultsErasedDestructorIntoEitherMarkupTypedCloneCopyDebugStructuralPartialEqPartialEqDefaultAddSubMulFromStrDisplay
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.