Direction Cosine Matrix To Rodrigues — Robotics/Orientation 3D
Robotics/Orientation_3D/Direction_Cosine_Matrix_To_Rodrigues · 1 input / 1 output port(s) at insert · exports to Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text
Description#
The block's own DESCRIPTION_HTML, rendered verbatim — the same text the config dialog's info panel and the library navigator show. Fix a wrong sentence in the block's .cpp (R-D9), never here.
Direction Cosine Matrix To Rodrigues
Robotics / Orientation 3D
Converts a [3,3] direction cosine matrix D into the [3,1] Rodrigues vector r of the same rotation – the Gibbs vector r = tan(θ/2)·n̂. It is the inverse of Rodrigues To Direction Cosine Matrix, and it is a closed form with no square root and no trigonometry:
- den = 1 + D00 + D11 + D22
- r0 = (D12 − D21) / den
- r1 = (D20 − D02) / den
- r2 = (D01 − D10) / den
D is the passive matrix – the one that re-expresses a fixed vector in the rotated frame. That is the transpose of the active matrix Quaternion To Rotation Matrix produces; feeding one where the other belongs negates every component of the answer.
Ports
- D – the direction cosine matrix, [3,3]. The size is fixed.
- r – the Rodrigues vector, a [3,1] column. Its size is fixed and does not follow the input's.
Parameters
- Sampling Time (s) – zero or less inherits the solver's rate; a positive value runs the block at that period.
Code export
All ten targets: Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog and PLC Structured Text. There is no tunable parameter, because the block has no parameter at all – the matrix arrives on a port.
Every backend takes one reciprocal of den and scales the three numerators by it. Three independent divisions would be arithmetically equivalent and would round differently.
On the three HDL targets the block is offered as simulation-only: a Q16.16 datapath has no division, so the reciprocal and the three scalings go through real arithmetic and only the ports quantize.
Simulink bridge
Both directions, onto
aerolibtransform2/Direction Cosine Matrix to Rodrigues in the Aerospace
Blockset. Its two dialog parameters do not cross and are listed as ignored:
action and tolerance select what the Simulink block does when the
matrix is not orthonormal – warn, error, or (the default) nothing. This block validates
nothing and always evaluates the formula, so there is no ICore configuration behind them.
The block's name is drawn on two lines, so the real library path carries an
embedded newline between to and Rodrigues; the flattened
one-line spelling resolves to nothing. And the block defines no SampleTime
parameter, so the rate stays on this side and a block configured with an explicit positive
rate reports that the rate did not cross.
The Simulink block returns the Rodrigues vector as a row; this one returns a column, as every vector port in this family does.
Notes
- Algebraic, with no state: the output depends only on the current input.
- den vanishes at a half turn. 1 + trace(D) = 4cos²(θ/2), so it goes to zero as θ approaches 180° – where the Gibbs vector genuinely is infinite, its coordinates having no point there. The six software targets answer infinity or NaN; the three fixed-point targets answer zero, because fixed point has neither. Nothing is logged. Use a quaternion if the rotation can reach a half turn.
- This block always evaluates the closed form above, for any matrix it is given. That
matters when comparing it with MATLAB:
dcm2rodgoes throughdcm2quat, which selects the largest of four square roots, and the two agree exactly only where that selection lands on the trace – on a genuine rotation of under about 120°. Outside it MATLAB may answer NaN where this block answers an ordinary quotient. - Orthonormality is not checked. The formula is evaluated on whatever arrives; a matrix that is not a rotation gives a number rather than a diagnostic.
- Deliberately no state space – the map is a rational function of the input.
Code facts#
| Fact | Value |
|---|---|
| registered type | Robotics/Orientation_3D/Direction_Cosine_Matrix_To_Rodrigues |
| family | Robotics/Orientation_3D |
| solver environment class | ICoreBlock_0_Robotics_1_Orientation_3D_2_Direction_Cosine_Matrix_To_Rodrigues |
| source | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Robotics/Orientation_3D/Direction_Cosine_Matrix_To_Rodrigues/ICoreBlock_0_Robotics_1_Orientation_3D_2_Direction_Cosine_Matrix_To_Rodrigues.cpp |
| header | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Robotics/Orientation_3D/Direction_Cosine_Matrix_To_Rodrigues/ICoreBlock_0_Robotics_1_Orientation_3D_2_Direction_Cosine_Matrix_To_Rodrigues.h |
| default size on canvas | 140 × 84 px |
| ports at insert | 1 in, 1 out |
| code generators implemented | Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text |
Ports#
| # | Direction | Signal type | Description label |
|---|---|---|---|
| 1 | in | ICoreDouble | D |
| 2 | out | ICoreDouble | r |
Ports the constructor creates. A block whose port list changes with its configuration adds or removes ports at load time; the count above is the one a freshly inserted block has.
Configuration variables#
No config variable beyond the Sampling Time (s) every block carries.
Every block also carries Sampling Time (s) from ICoreBlockSolverEnvironment: zero or less inherits the solver's rate, a positive value runs the block at that period.
Simulink bridge#
| support | Support::Both |
| Simulink path | aerolibtransform2/Direction Cosine Matrix to\nRodrigues |
| port-count rule | PortsParam::None |
SampleTime parameter | no — the counterpart defines none; the rate stays on the ICore side |
Caveat (shown to the user): MEASURED 2026-09-10: the Simulink block carries two dialog parameters, 'action' (None/Warning/Error) and 'tolerance', which decide what it does when the matrix is not orthonormal. Neither crosses: this block validates nothing and always evaluates the closed form, so there is no ICore configuration behind them. Note also that MATLAB's dcm2rod goes through dcm2quat's four-branch selection, so the two agree exactly only on a genuine rotation of under about 120 degrees. It returns the Rodrigues vector as a row where this block returns a column, and it defines no SampleTime parameter: an ICore rate set explicitly stays on this side
Catalog contract: src/ICoreBlocks/ICoreCoder/ICoreCommandSystem/SimulinkBridge/ICoreSimulinkBlockCatalog.h
Description vs code#
The checker has a blind spot here — it could not resolve something (a grouped port bullet, a computed config name), which is reported and never counted as a pass. A reader has to settle it:
B0every stimulus in the sample errored — cross-checks skipped
The verdict above is
tools/docs/check_block_descriptions.py(P7.1), which compares LISTS. It cannot read a sentence: "stateless" on a block with a state, an initial-value semantic the recursion does not implement, a "not synthesizable" caveat the HDL banner contradicts. That is the agent audit (P7.3) on BLOCK_DESCRIPTION_AUDIT.md, and this tool's green is not a substitute for one.
File banner (developer view)#
The top comment of the block's .cpp — the maths, the realization and the export strategy, addressed to whoever changes it. It must not contradict the description above (P7.5).
Direction Cosine Matrix To Rodrigues — a [3,3] passive DCM to its [3,1] Gibbs vector den = 1 + D(0,0) + D(1,1) + D(2,2) r(0) = (D(1,2) - D(2,1)) / den r(1) = (D(2,0) - D(0,2)) / den r(2) = (D(0,1) - D(1,0)) / den
Three differences and one shared reciprocal: no square root, no trigonometry, no branch.
MEASURED against aerolibtransform2/Direction Cosine Matrix to Rodrigues (R2026a, 2026-09-10): on D built from r = [0.37 -0.62 0.21] the Simulink block returns that vector back, and the closed form above agrees with it to 1.11e-16.
⚠ 1 + trace(D) IS 4*cos^2(theta/2), so it vanishes at a half turn - where the Gibbs vector genuinely is infinite. The six software targets answer infinity or NaN there and the three fixed-point ones answer zero, the same split Quaternion Inverse has at the zero quaternion.
⚠ MATLAB'S dcm2rod IS NOT THIS FORMULA ON AN ARBITRARY MATRIX. It goes through dcm2quat, which picks whichever of four square roots is largest; on a genuine rotation of under about 120 degrees that branch reduces to exactly the expression above, and outside it the two disagree - measured, MATLAB answers NaN for matrices whose trace leaves [-1, 3], where this block answers an ordinary quotient. The rig is banded so the two are compared where they are the same function, and the description says which one this block computes.
⚠ SIMULATION-ONLY on the three HDL targets: Q16.16 has no division.
Sample results#
No stimulus produced a sampled output in this rig — Invalid input size at Direction Cosine Matrix To Rodrigues block: ICore Blocks/Home/Direction Cosine Matrix To Rodrigues. That is a fact about the single-block rig, not a verdict on the block: an offline batch fit, a block whose output only appears at onSolverFinish, or one that needs a driven environment cannot be exercised alone.
Category unsampled · sample time 0.1 · 60 steps · commit b286d2937 · produced by docsSample --out <folder> --blocks Rodrigues_To_Direction_Cosine_Matrix Direction_Cosine_Matrix_To_Rodrigues Rodrigues_To_Quaternion Quaternion_To_Rodrigues Rodrigues_To_Rotation_Angles Rotation_Angles_To_Rodrigues --steps 60
Sample data: docs/generated/samples/Robotics__Orientation_3D__Direction_Cosine_Matrix_To_Rodrigues.json