math::rotation
math::rotation
Section titled “math::rotation”The rotation module provides 3D rotation utilities: ZYX Euler-angle
conversion, matrix application, composition, and inverse. All angles are in
radians and matrices are 3x3 Mat<number> values.
Import
Section titled “Import”use std::math::rotationConvention
Section titled “Convention”ZYX Euler convention: R = Rz(alpha) * Ry(beta) * Rx(gamma). Alpha is yaw
(Z), beta is pitch (Y), gamma is roll (X).
Functions
Section titled “Functions”rotation::euler_to_matrix(alpha, beta, gamma) -> Mat<number>
Section titled “rotation::euler_to_matrix(alpha, beta, gamma) -> Mat<number>”Build a 3x3 rotation matrix from ZYX Euler angles.
use std::math::rotation
let identity = rotation::euler_to_matrix(0.0, 0.0, 0.0)rotation::matrix_to_euler(m) -> Array<number>
Section titled “rotation::matrix_to_euler(m) -> Array<number>”Extract [alpha, beta, gamma] ZYX Euler angles from a 3x3 rotation matrix.
Handles gimbal lock when beta is near +/- pi/2.
let m = rotation::euler_to_matrix(0.1, 0.2, 0.3)let angles = rotation::matrix_to_euler(m)// angles ~ [0.1, 0.2, 0.3]rotation::rotation_apply(rot, points) -> Mat<number>
Section titled “rotation::rotation_apply(rot, points) -> Mat<number>”Apply a rotation matrix to a set of points (Nx3 matrix, each row is a
point). Returns an Nx3 matrix of rotated points.
rotation::rotation_inverse(rot) -> Mat<number>
Section titled “rotation::rotation_inverse(rot) -> Mat<number>”Inverse of a rotation matrix. For orthogonal rotation matrices, the inverse equals the transpose.
rotation::rotation_compose(r1, r2) -> Mat<number>
Section titled “rotation::rotation_compose(r1, r2) -> Mat<number>”Compose two rotations. The result applies r2 first, then r1.
rotation::rotation_from_rows(rows) -> Mat<number>
Section titled “rotation::rotation_from_rows(rows) -> Mat<number>”Construct a Mat<number> from an array of row arrays (e.g.
[[1,0,0], [0,1,0], [0,0,1]]).
rotation::normalize_euler(angles) -> Array<number>
Section titled “rotation::normalize_euler(angles) -> Array<number>”Wrap each angle to [-pi, pi].
let wrapped = rotation::normalize_euler([7.0, -7.0, 0.0])See Also
Section titled “See Also”- math::linalg — vector operations
- math::interpolation — grid interpolation
- physics — physics primitives that consume rotation matrices