testrot
Overview
testrot (code/tests/testrot.c, authored by John Hughes Clarke in July 1994) is an interactive command-line verification utility for testing 3D rigid-body Euler angle coordinate transformations implemented in DCM_rthand.h (DCM_rotate and DCM_unrotate in liblocal.a).
In multibeam sonar ray-tracing and lever-arm motion compensation (such as RTlite, DelayEditor, and swathed), 3D vectorsβsuch as GPS-to-transducer lever-arm offsets $(x_0, y_0, z_0)$ or unit beam pointing vectorsβmust be rotated accurately between the vessel/sonar reference frame (SONAR) and the local level geographic reference frame (GEO) using instantaneous roll ($r$), pitch ($p$), and heading/yaw ($h$). testrot allows the user to interactively enter any 3D vector (x0, y0, z0) and attitude triplet (roll, pitch, heading) and transform it either forward (GEO -> SONAR via DCM_rotate) or inverse (SONAR -> GEO via DCM_unrotate).
Syntax & CLI Options
testrot [-v] [-roll <deg>]
| Option | Description | Default |
|---|---|---|
-v | Increment verbose flag (verbose_flag++). | 0 |
-roll <deg> | Optional initial roll value parsed on CLI (overridden by interactive scanf prompt). | Interactive |
Interactive Prompts & Direction Cosine Matrix (DCM) Math
1. Interactive Loop (yetagain:)
At each iteration, testrot prompts on stdin for:
- Starting 3D Vector:
input x, y z of starting vector(scanf("%lf %lf %lf", &x0, &y0, &z0)), stored inlocation vectin. - Transformation Direction (
foreback):1: Rotatefrom GEO to SONAR(DCM_rotate(vectin, rpy, &vectout)).2: Rotatefrom SONAR to GEO(DCM_unrotate(vectin, rpy, &vectout)).0:exit(exit(0)).
- Rigid Frame Attitude:
input roll, pitch heading of rigid frame(in degrees, stored inattitude rpy={roll, pitch, yaw}).
2. Right-Handed Direction Cosine Matrix (DCM_rthand.h)
In the OMG right-handed vessel coordinate convention ($+X$ forward/North, $+Y$ starboard/East, $+Z$ down), with $\phi = \text{roll}$, $\theta = \text{pitch}$, and $\psi = \text{heading}$ (in radians), the forward rotation matrix $\mathbf{R} = \mathbf{R}_z(\psi)\,\mathbf{R}_y(\theta)\,\mathbf{R}_x(\phi)$ documented in testrot.c (lines 196β217) is:
Because $\mathbf{R} \in \text{SO}(3)$ is orthogonal ($\mathbf{R}^{-1} = \mathbf{R}^\top$, $\det\mathbf{R} = +1$), the Euclidean norm of any lever-arm vector is strictly invariant under rotation:
\[\Vert\mathbf{v}_1\Vert = \sqrt{x_1^2 + y_1^2 + z_1^2} = \sqrt{x_0^2 + y_0^2 + z_0^2} = \Vert\mathbf{v}_0\Vert\](A secondary code block at label again: in testrot.c lines 171β250 explicitly checks this norm preservation by computing perc_diff = (1.0 - final_length / orig_length) * 100.0 and applying DCM_rotate followed immediately by DCM_unrotate to confirm round-trip identity).
Example Interactive Session
$ testrot
input x, y z of starting vector
0.0 0.0 10.0
entered 0.000000 0.000000 10.000000
do you want to rotate:
from GEO to SONAR (1)
from SONAR to GEO (2)
exit (0)
2
input roll, pitch heading of rigid frame
10.0 0.0 90.0
10.000000 0.000000 90.000000
rot back -1.736482 0.000000 9.848078
To analyze coupled roll/pitch cross-talk caused by VRU yaw mounting misalignment, see twistVRU.