orientation
Overview & Purpose
orientation provides the fundamental 3D Euler angle, vector rotation, $3 \times 3$ rotation matrix, and $4 \times 4$ matrix inversion mathematics used throughout the Ocean Mapping Group (OMG) codebase for vessel attitude compensation, lever-arm transformation, multibeam cone-cone intersection, and patch test calibration.
Key Data Structures, Constants & Macros
Core Structs
orientation: Represents 3D Euler attitude angles and optional 3D translational offsets:float roll: Roll angle in degrees.float pitch: Pitch angle in degrees.float heave: Heave in meters.float heading: Heading/yaw angle in degrees.double x,double y,double z: 3D Cartesian coordinates or lever-arm translations (meters).
vector_3D: 3D double-precision Cartesian vector (double x,double y,double z).rotation_matrix: $3 \times 3$ row-major rotation matrix with elements: \(\begin{bmatrix} a & b & c \\ d & e & f \\ g & h & i \end{bmatrix}\)matrix_4x4: $4 \times 4$ double-precision matrix with elementsa1..a4,b1..b4,c1..c4,d1..d4arranged as: \(\begin{bmatrix} a_1 & b_1 & c_1 & d_1 \\ a_2 & b_2 & c_2 & d_2 \\ a_3 & b_3 & c_3 & d_3 \\ a_4 & b_4 & c_4 & d_4 \end{bmatrix}\) Added (Jan 2013) to support 3D cone-cone intersection and quadric matrix inversion insonar_geometry.c(intersect_cones_travis).
Public Functions & Signatures
Direct Vector Rotations
void unrotate(vector_3D orig, orientation rotate, vector_3D *final)- Transforms a 3D vector
origfrom the rotated body/sensor frame into the local level/geographic reference frame using the compound Euler rotation matrix $R = R_z(\text{heading}) R_y(\text{pitch}) R_x(\text{roll})$:final->x = cosp*cosy*x + (sinr*sinp*cosy - cosr*siny)*y + (cosr*sinp*cosy + sinr*siny)*zfinal->y = cosp*siny*x + (sinr*sinp*siny + cosr*cosy)*y + (cosr*sinp*siny - sinr*cosy)*zfinal->z = -sinp*x + sinr*cosp*y + cosr*cosp*z
- Transforms a 3D vector
void rotate(vector_3D orig, orientation rotate, vector_3D *final)- Applies the inverse (transpose) rotation $R^T$ to transform a vector
origfrom the local level/geographic frame back into the rotated body/sensor frame.
- Applies the inverse (transpose) rotation $R^T$ to transform a vector
$3 \times 3$ Rotation Matrix Operations
void matrix_identity(rotation_matrix *matrix)- Sets
matrixto the $3 \times 3$ identity matrix ($a = e = i = 1.0$, all other elements $0.0$).
- Sets
void matrix_build(rotation_matrix *matrix, orientation *rotate)- Populates
matrixwith the $3 \times 3$ direction cosine matrix corresponding torotate->roll,rotate->pitch, androtate->heading.
- Populates
vector_3D matrix_rotate(rotation_matrix *matrix, vector_3D *vector)- Multiplies the $3 \times 3$
matrixbyvectorand returns the rotatedvector_3D.
- Multiplies the $3 \times 3$
rotation_matrix matrix_multiply(rotation_matrix *lmatrix, rotation_matrix *rmatrix)- Computes the $3 \times 3$ matrix product $K = L \cdot R$.
rotation_matrix matrix_transpose(rotation_matrix *m)- Returns the transpose $M^T$ of the $3 \times 3$ matrix
m(equivalent to the inverse for orthogonal rotation matrices).
- Returns the transpose $M^T$ of the $3 \times 3$ matrix
orientation matrix_solve_angles(rotation_matrix *m)- Extracts Euler angles (
roll,pitch,headingin degrees) from a $3 \times 3$ rotation matrix usingroll = atan(h/i),pitch = acos(i / cos(roll)), andheading = acos(a / cos(pitch)).
- Extracts Euler angles (
$4 \times 4$ Matrix Inversion & Determinants
int invert_4x4(matrix_4x4 in, matrix_4x4 *out)- Computes the inverse of
invia the classical adjoint method: $\text{out} = \frac{1}{\det(\text{in})} \text{adj}(\text{in})$.
- Computes the inverse of
int adjoint(matrix_4x4 in, matrix_4x4 *out)- Computes the transposed $4 \times 4$ cofactor matrix of
inusing 16 calls todet3x3.
- Computes the transposed $4 \times 4$ cofactor matrix of
double det4x4(matrix_4x4 m)/double det3x3(...)/double det2x2(double a, double b, double c, double d)- Recursive Laplace cofactor expansion determinants for $4 \times 4$, $3 \times 3$, and $2 \times 2$ matrices.
How It Fits Into the OMG Architecture
orientation is a core dependency of sonar_geometry (code/subr/sonar_geometry.c), grazing_angle, omg_target, newMergeAtt, swathed (SE) (SE_PATCHwin.c, SE_BDI_DP.c, applyBDI.c), jview (JV), xse2omg, and recalc_simrad, performing all lever-arm and beam vector coordinate transformations.