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
impl Rotation3
Sourcepub const fn from_matrix(m: [[f64; 3]; 3]) -> Self
pub const fn from_matrix(m: [[f64; 3]; 3]) -> Self
Sourcepub fn from_axis_angle(axis: [f64; 3], angle: Radians) -> Self
pub fn from_axis_angle(axis: [f64; 3], angle: Radians) -> Self
Sourcepub fn from_euler_xyz(x: Radians, y: Radians, z: Radians) -> Self
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.
Sourcepub fn from_euler_zxz(z1: Radians, x: Radians, z2: Radians) -> Self
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.
Sourcepub fn rx(angle: Radians) -> Self
pub fn rx(angle: Radians) -> Self
Creates a rotation around the X axis from a typed Radians angle.
Sourcepub fn ry(angle: Radians) -> Self
pub fn ry(angle: Radians) -> Self
Creates a rotation around the Y axis from a typed Radians angle.
Sourcepub fn rz(angle: Radians) -> Self
pub fn rz(angle: Radians) -> Self
Creates a rotation around the Z axis from a typed Radians angle.
Sourcepub fn transpose(&self) -> Self
pub fn transpose(&self) -> Self
Returns the transpose (inverse) of this rotation.
For rotation matrices, transpose equals inverse.
Sourcepub fn compose(&self, other: &Self) -> Self
pub fn compose(&self, other: &Self) -> Self
Composes two rotations: self * other.
The result applies other first, then self.
Sourcepub fn apply_array(&self, v: [f64; 3]) -> [f64; 3]
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.
Sourcepub const fn as_matrix(&self) -> &[[f64; 3]; 3]
pub const fn as_matrix(&self) -> &[[f64; 3]; 3]
Returns the underlying matrix as a row-major array.
Sourcepub fn fused_rx_rz(a: Radians, b: Radians) -> Self
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).
Sourcepub fn fused_rz_rx(a: Radians, b: Radians) -> Self
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).
Sourcepub fn fused_rx_rz_rx(a: Radians, b: Radians, c: Radians) -> Self
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).
Sourcepub fn fused_rz_ry_rz(a: Radians, b: Radians, c: Radians) -> Self
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).
Sourcepub fn fused_rx_rz_rx_rz(a: Radians, b: Radians, c: Radians, d: Radians) -> Self
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§
impl Copy for Rotation3
impl StructuralPartialEq for Rotation3
Auto Trait Implementations§
impl Freeze for Rotation3
impl RefUnwindSafe for Rotation3
impl Send for Rotation3
impl Sync for Rotation3
impl Unpin for Rotation3
impl UnsafeUnpin for Rotation3
impl UnwindSafe for Rotation3
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,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§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).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.