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::angular::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_unchecked(m: [[f64; 3]; 3]) -> Self

Creates a rotation matrix from raw row-major data without validation.

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

m must be an orthogonal matrix with det = +1 (a proper rotation). No validation is performed. Passing an invalid matrix produces a mathematically incoherent Rotation3 whose composition and inversion will silently propagate garbage values, and Rotation3 * Direction<F> will manufacture a Direction whose norm is not 1.

Source

pub fn try_from_matrix(m: [[f64; 3]; 3]) -> Option<Self>

Creates a rotation matrix from raw row-major data, validating orthogonality.

Returns None if m is not a proper rotation matrix (i.e., Mᵀ·M is not close to the identity within tolerance 1e-7, or det(M) is not close to +1).

§Arguments
  • m: A 3x3 array in row-major order where m[row][col].
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 fn apply_vec<F1, F2, U>(&self, v: Vector<F1, U>) -> Vector<F2, U>
where F1: ReferenceFrame, F2: ReferenceFrame, U: Unit,

Applies this rotation to a typed Vector, changing its reference frame.

Rotates the vector’s components and re-tags the result with frame F2. The unit U is unchanged. This is a zero-overhead operation: the matrix multiplication uses the same path as Self::apply_array, with a frame tag change at compile time.

§Example
use affn::{Rotation3, cartesian::Displacement};
use affn::frames::ReferenceFrame;
use qtty::unit::Kilometer;
use std::f64::consts::FRAC_PI_2;

#[derive(Debug, Copy, Clone)] struct FrameA;
#[derive(Debug, Copy, Clone)] struct FrameB;
impl ReferenceFrame for FrameA { fn frame_name() -> &'static str { "A" } }
impl ReferenceFrame for FrameB { fn frame_name() -> &'static str { "B" } }

let rot = Rotation3::rz(qtty::angular::Radians::new(FRAC_PI_2));
let v = Displacement::<FrameA, Kilometer>::new(1.0, 0.0, 0.0);
let rotated: Displacement<FrameB, Kilometer> = rot.apply_vec(v);
assert!((rotated.x().value() - 0.0).abs() < 1e-10);
assert!((rotated.y().value() - 1.0).abs() < 1e-10);
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 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 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Rotation3

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 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<F: ReferenceFrame> Mul<&Direction<F>> for Rotation3

Source§

type Output = <Rotation3 as Mul<Direction<F>>>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Direction<F>) -> <Self as Mul<&Direction<F>>>::Output

Performs the * operation. Read more
Source§

impl<F: ReferenceFrame> Mul<&Direction<F>> for &Rotation3

Source§

type Output = <Rotation3 as Mul<Direction<F>>>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Direction<F>) -> <Self as Mul<&Direction<F>>>::Output

Performs the * operation. Read more
Source§

impl<C, F, U> Mul<&Position<C, F, U>> for Rotation3

Source§

type Output = <Rotation3 as Mul<Position<C, F, U>>>::Output

The resulting type after applying the * operator.
Source§

fn mul( self, rhs: &Position<C, F, U>, ) -> <Self as Mul<&Position<C, F, U>>>::Output

Performs the * operation. Read more
Source§

impl<C, F, U> Mul<&Position<C, F, U>> for &Rotation3

Source§

type Output = <Rotation3 as Mul<Position<C, F, U>>>::Output

The resulting type after applying the * operator.
Source§

fn mul( self, rhs: &Position<C, F, U>, ) -> <Self as Mul<&Position<C, F, U>>>::Output

Performs the * operation. Read more
Source§

impl Mul<&Rotation3> for Rotation3

Source§

type Output = <Rotation3 as Mul>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Rotation3) -> <Self as Mul<&Rotation3>>::Output

Performs the * operation. Read more
Source§

impl Mul<&Rotation3> for &Rotation3

Source§

type Output = <Rotation3 as Mul>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Rotation3) -> <Self as Mul<&Rotation3>>::Output

Performs the * operation. Read more
Source§

impl<F, U> Mul<&Vector<F, U>> for Rotation3
where F: ReferenceFrame, U: Unit,

Source§

type Output = <Rotation3 as Mul<Vector<F, U>>>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Vector<F, U>) -> <Self as Mul<&Vector<F, U>>>::Output

Performs the * operation. Read more
Source§

impl<F, U> Mul<&Vector<F, U>> for &Rotation3
where F: ReferenceFrame, U: Unit,

Source§

type Output = <Rotation3 as Mul<Vector<F, U>>>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Vector<F, U>) -> <Self as Mul<&Vector<F, U>>>::Output

Performs the * operation. Read more
Source§

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

Source§

type Output = <Rotation3 as Mul<XYZ<Quantity<U>>>>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &XYZ<Quantity<U>>) -> <Self as Mul<&XYZ<Quantity<U>>>>::Output

Performs the * operation. Read more
Source§

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

Source§

type Output = <Rotation3 as Mul<XYZ<Quantity<U>>>>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &XYZ<Quantity<U>>) -> <Self as Mul<&XYZ<Quantity<U>>>>::Output

Performs the * operation. Read more
Source§

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

Source§

type Output = <Rotation3 as Mul<[Quantity<U>; 3]>>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &[Quantity<U>; 3]) -> <Self as Mul<&[Quantity<U>; 3]>>::Output

Performs the * operation. Read more
Source§

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

Source§

type Output = <Rotation3 as Mul<[Quantity<U>; 3]>>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &[Quantity<U>; 3]) -> <Self as Mul<&[Quantity<U>; 3]>>::Output

Performs the * operation. Read more
Source§

impl Mul<&[f64; 3]> for Rotation3

Source§

type Output = <Rotation3 as Mul<[f64; 3]>>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &[f64; 3]) -> <Self as Mul<&[f64; 3]>>::Output

Performs the * operation. Read more
Source§

impl Mul<&[f64; 3]> for &Rotation3

Source§

type Output = <Rotation3 as Mul<[f64; 3]>>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &[f64; 3]) -> <Self as Mul<&[f64; 3]>>::Output

Performs the * operation. Read more
Source§

impl<F: ReferenceFrame> Mul<Direction<F>> for Rotation3

Rotation3 * Direction<F> — rotates a unit direction, preserving frame.

Translations do not apply to directions; only rotation changes their orientation. The result is guaranteed to remain a unit vector because rotation preserves norms.

Source§

type Output = Direction<F>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Direction<F>) -> Direction<F>

Performs the * operation. Read more
Source§

impl<F: ReferenceFrame> Mul<Direction<F>> for &Rotation3

Source§

type Output = <Rotation3 as Mul<Direction<F>>>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Direction<F>) -> <Self as Mul<Direction<F>>>::Output

Performs the * operation. Read more
Source§

impl<C, F, U> Mul<Position<C, F, U>> for Rotation3

Source§

type Output = Position<C, F, U>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Position<C, F, U>) -> Position<C, F, U>

Performs the * operation. Read more
Source§

impl<C, F, U> Mul<Position<C, F, U>> for &Rotation3

Source§

type Output = <Rotation3 as Mul<Position<C, F, U>>>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Position<C, F, U>) -> <Self as Mul<Position<C, F, U>>>::Output

Performs the * operation. Read more
Source§

impl Mul<Rotation3> for &Rotation3

Source§

type Output = <Rotation3 as Mul>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Rotation3) -> <Self as Mul<Rotation3>>::Output

Performs the * operation. Read more
Source§

impl<F, U> Mul<Vector<F, U>> for Rotation3
where F: ReferenceFrame, U: Unit,

Rotation3 * Vector<F, U> — rotates a free vector, preserving frame and unit.

Translations do not apply to free vectors (they are translation-invariant), so this is only implemented for Rotation3.

Source§

type Output = Vector<F, U>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vector<F, U>) -> Vector<F, U>

Performs the * operation. Read more
Source§

impl<F, U> Mul<Vector<F, U>> for &Rotation3
where F: ReferenceFrame, U: Unit,

Source§

type Output = <Rotation3 as Mul<Vector<F, U>>>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vector<F, U>) -> <Self as Mul<Vector<F, U>>>::Output

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<U: Unit> Mul<XYZ<Quantity<U>>> for &Rotation3

Source§

type Output = <Rotation3 as Mul<XYZ<Quantity<U>>>>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: XYZ<Quantity<U>>) -> <Self as Mul<XYZ<Quantity<U>>>>::Output

Performs the * operation. 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<U: Unit> Mul<[Quantity<U>; 3]> for &Rotation3

Source§

type Output = <Rotation3 as Mul<[Quantity<U>; 3]>>::Output

The resulting type after applying the * operator.
Source§

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

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 Mul<[f64; 3]> for &Rotation3

Source§

type Output = <Rotation3 as Mul<[f64; 3]>>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: [f64; 3]) -> <Self as Mul<[f64; 3]>>::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 (const: unstable) · 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 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<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.