FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    GitHub ↗

    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.

    View source

    Members

    x

    x: f64
    

    The X component.

    Source

    y

    y: f64
    

    The Y component.

    Source

    z

    z: f64
    

    The Z component.

    Source

    w

    w: f64
    

    The W component.

    Source

    IDENTITY

    const IDENTITY: Quaternion
    

    The rotation by no angle (WPF's Quaternion.Identity): (0, 0, 0, 1).

    Source

    new

    const fn new(x: f64, y: f64, z: f64, w: f64) -> Self
    

    A quaternion with the given components.

    Source

    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.

    Source

    is_identity

    fn is_identity(self: &Self) -> bool
    

    Whether this is the identity: (0, 0, 0, 1).

    Source

    is_normalized

    fn is_normalized(self: &Self) -> bool
    

    Whether the quaternion has unit length, within ten machine epsilons of its squared norm.

    Source

    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).

    Source

    angle

    fn angle(self: &Self) -> f64
    

    The angle of the rotation in degrees, from 0 to 360, for a quaternion of any length.

    Source

    conjugate

    fn conjugate(self: &mut Self)
    

    Replaces the quaternion by its conjugate: the axis reversed.

    Source

    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.

    Source

    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.

    Source

    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.

    Source

    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.

    Source

    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.

    Source

    Trait implementations

    • Send
    • Sync
    • Freeze
    • UnsafeUnpin
    • Unpin
    • UnwindSafe
    • RefUnwindSafe
    • Borrow<T>
    • BorrowMut<T>
    • CloneToUninit
    • Into<U>
    • From<T>
    • TryInto<U>
    • TryFrom<U>
    • Any
    • ToOwned
    • ToString
    • PropertyValue
    • AnyValue
    • ClassDefaults
    • ErasedDestructor
    • IntoEither
    • MarkupTyped
    • Clone
    • Copy
    • Debug
    • StructuralPartialEq
    • PartialEq
    • Default
    • Add
    • Sub
    • Mul
    • FromStr
    • Display

    Availability

    Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.