Skip to main content

Rotation3

Struct Rotation3 

Source
pub struct Rotation3 { /* private fields */ }
Expand description

A 3x3 rotation matrix for orientation transforms.

Internally stores row-major data as [[f64; 3]; 3]. This is a pure mathematical operator with no frame semantics— frame tagging is handled by the caller.

§Conventions

  • Right-handed coordinate system assumed.
  • Matrix applied as y = R * x (column vector convention).
  • Transpose of a rotation matrix is its inverse.

§Example

use affn::Rotation3;
use qtty::Radians;
use std::f64::consts::FRAC_PI_2;

// Rotate 90° around the Z axis
let rot = Rotation3::rz(Radians::new(FRAC_PI_2));
let x_axis = [1.0, 0.0, 0.0];
let rotated = rot.apply_array(x_axis);

// X-axis becomes Y-axis (within numerical tolerance)
assert!((rotated[0]).abs() < 1e-10);
assert!((rotated[1] - 1.0).abs() < 1e-10);
assert!((rotated[2]).abs() < 1e-10);

Implementations§

Source§

impl Rotation3

Source

pub const IDENTITY: Self

The identity rotation (no change in orientation).

Source

pub const fn from_matrix(m: [[f64; 3]; 3]) -> Self

Creates a rotation matrix from raw row-major data.

§Arguments
  • m: A 3x3 array in row-major order where m[row][col].
§Safety

The caller must ensure m is a valid rotation matrix (orthogonal, det = +1). No validation is performed.

Source

pub fn from_axis_angle(axis: [f64; 3], angle: Radians) -> Self

Creates a rotation from an axis-angle representation.

Uses Rodrigues’ rotation formula.

§Arguments
  • axis: The rotation axis (will be normalized if not unit length).
  • angle: The rotation angle (right-hand rule).
§Returns

A rotation matrix representing the given axis-angle rotation.

Source

pub fn from_euler_xyz(x: Radians, y: Radians, z: Radians) -> Self

Creates a rotation from Euler angles (XYZ convention).

Applies rotations in order: X, then Y, then Z. Internally uses a fused constructor to avoid intermediate matrices.

§Arguments
  • x: Rotation around X axis.
  • y: Rotation around Y axis.
  • z: Rotation around Z axis.
Source

pub fn from_euler_zxz(z1: Radians, x: Radians, z2: Radians) -> Self

Creates a rotation from Euler angles (ZXZ convention).

This is the classical astronomical convention used in precession. Applies rotations in order: first Z, then X, then Z. Internally uses a fused constructor to avoid intermediate matrices.

§Arguments
  • z1: First rotation around Z axis.
  • x: Rotation around X axis.
  • z2: Second rotation around Z axis.
Source

pub fn rx(angle: Radians) -> Self

Creates a rotation around the X axis from a typed Radians angle.

Source

pub fn ry(angle: Radians) -> Self

Creates a rotation around the Y axis from a typed Radians angle.

Source

pub fn rz(angle: Radians) -> Self

Creates a rotation around the Z axis from a typed Radians angle.

Source

pub fn transpose(&self) -> Self

Returns the transpose (inverse) of this rotation.

For rotation matrices, transpose equals inverse.

Source

pub fn inverse(&self) -> Self

Returns the inverse of this rotation.

Alias for transpose.

Source

pub fn compose(&self, other: &Self) -> Self

Composes two rotations: self * other.

The result applies other first, then self.

Source

pub fn apply_array(&self, v: [f64; 3]) -> [f64; 3]

Applies this rotation to a raw [f64; 3] array.

Computes R * v where v is treated as a column vector.

Source

pub fn apply_xyz(&self, xyz: XYZ<f64>) -> XYZ<f64>

Applies this rotation to an XYZ<f64>.

Source

pub const fn as_matrix(&self) -> &[[f64; 3]; 3]

Returns the underlying matrix as a row-major array.

Source

pub fn fused_rx_rz(a: Radians, b: Radians) -> Self

Constructs the rotation Rx(a) · Rz(b) directly.

Faster than Rotation3::rx(a) * Rotation3::rz(b) because it avoids the intermediate 3×3 matrix multiply and computes each element from trig products.

§Arguments
  • a: Angle for the X rotation (applied second / left factor).
  • b: Angle for the Z rotation (applied first / right factor).
Source

pub fn fused_rz_rx(a: Radians, b: Radians) -> Self

Constructs the rotation Rz(a) · Rx(b) directly.

Faster than Rotation3::rz(a) * Rotation3::rx(b) because it avoids the intermediate 3×3 matrix multiply.

§Arguments
  • a: Angle for the Z rotation (applied second / left factor).
  • b: Angle for the X rotation (applied first / right factor).
Source

pub fn fused_rx_rz_rx(a: Radians, b: Radians, c: Radians) -> Self

Constructs the rotation Rx(a) · Rz(b) · Rx(c) directly.

Used in nutation: N = Rx(ε+Δε) · Rz(Δψ) · Rx(−ε).

Computes the 9 elements from 3 sin/cos pairs and their products, avoiding 2 intermediate matrix multiplications.

§Arguments
  • a: Angle for the outer X rotation (left).
  • b: Angle for the Z rotation (middle).
  • c: Angle for the inner X rotation (right).
Source

pub fn fused_rz_ry_rz(a: Radians, b: Radians, c: Radians) -> Self

Constructs the rotation Rz(a) · Ry(b) · Rz(c) directly.

Used in Meeus precession: P = Rz(z) · Ry(−θ) · Rz(ζ).

§Arguments
  • a: Angle for the outer Z rotation (left).
  • b: Angle for the Y rotation (middle).
  • c: Angle for the inner Z rotation (right).
Source

pub fn fused_rx_rz_rx_rz(a: Radians, b: Radians, c: Radians, d: Radians) -> Self

Constructs the Fukushima-Williams rotation Rx(a) · Rz(b) · Rx(c) · Rz(d) directly.

This is the standard form for IAU 2006 precession and precession-nutation matrices. In the SOFA/ERFA convention (translated to standard rotations):

P = Rx(ε_A) · Rz(ψ̄) · Rx(−φ̄) · Rz(−γ̄)

This fused constructor computes all 9 matrix elements directly from 4 sin/cos pairs, avoiding 3 intermediate matrix multiplications. Provides a ~45% speedup over the sequential composition.

§Arguments
  • a: Angle for the outer X rotation (left, e.g., ε_A).
  • b: Angle for the first Z rotation (e.g., ψ̄).
  • c: Angle for the inner X rotation (e.g., −φ̄).
  • d: Angle for the innermost Z rotation (e.g., −γ̄).

Trait Implementations§

Source§

impl Clone for Rotation3

Source§

fn clone(&self) -> Rotation3

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Rotation3

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Rotation3

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<U: Unit> Mul<[Quantity<U>; 3]> for Rotation3

Source§

type Output = [Quantity<U>; 3]

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: [Quantity<U>; 3]) -> [Quantity<U>; 3]

Performs the * operation. Read more
Source§

impl Mul<[f64; 3]> for Rotation3

Applies a rotation to a raw [f64; 3] column vector: R * v.

Source§

type Output = [f64; 3]

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: [f64; 3]) -> [f64; 3]

Performs the * operation. Read more
Source§

impl<U: Unit> Mul<XYZ<Quantity<U>>> for Rotation3

Source§

type Output = XYZ<Quantity<U>>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: XYZ<Quantity<U>>) -> XYZ<Quantity<U>>

Performs the * operation. Read more
Source§

impl Mul for Rotation3

Source§

type Output = Rotation3

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl PartialEq for Rotation3

Source§

fn eq(&self, other: &Rotation3) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Rotation3

Source§

impl StructuralPartialEq for Rotation3

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,