Quaternion Inverse — Robotics/Orientation 3D
Robotics/Orientation_3D/Quaternion_Inverse · 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.
Quaternion Inverse
Robotics / Orientation 3D
The multiplicative inverse of a quaternion stored scalar-first as [w x y z]T – the conjugate divided by the squared norm:
- n = w² + x² + y² + z²
- q⁻¹ = [w/n −x/n −y/n −z/n]T
It is the quaternion that undoes q under the Hamilton product: q ⊗ q⁻¹ = [1 0 0 0]T, the identity rotation.
On a unit quaternion the inverse is the conjugate, because n = 1 – which is why rotation code reaches for Quaternion Conjugate instead and saves the division. Use this block when the input is not known to be unit.
Ports
- q – the quaternion to invert, a [4,1] column [w x y z]T. The size is fixed: a quaternion is four numbers.
- q^-1 – the inverse, also [4,1]. The port is labelled
q^-1on the block face, which is the same q⁻¹ the maths above calls it.
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 quaternion arrives on a port.
Every backend takes one reciprocal of n and multiplies the four signed components by it. Four independent divisions would be arithmetically equivalent and would round differently, so the shared reciprocal is part of the contract rather than an optimisation.
On the three HDL targets the block is offered as simulation-only: a Q16.16 datapath has no division, so the reciprocal and the four products go through real arithmetic and only the ports quantize. This is the same choice Recursive IIR and Variable Transport Delay make. Note also that n is a sum of squares, so it grows quadratically and 1/n grows without bound as the quaternion shrinks – a small quaternion is a bad thing to hand a fixed-point export.
Simulink bridge
Both directions, onto aerolibutil/Quaternion Inverse
in the Aerospace Blockset. The block has no configuration, so no
parameter pairs cross.
Its name is drawn on two lines, so the real library path carries an
embedded newline between Quaternion and
Inverse; the flattened one-line spelling resolves to nothing. And
the block defines no SampleTime parameter, so the rate stays
on the ICore side and a block configured with an explicit positive rate reports
that the rate did not cross.
Notes
- Algebraic and stateless: the output depends only on the current input, so the block cannot break an algebraic loop.
- The divisor is the SQUARED norm, not the modulus. Dividing by |q| instead would give an answer wrong by a factor of |q| – and that factor is exactly 1 on a unit quaternion, which is what most test data is made of. If you are checking this block against another implementation, check it with something that is not unit.
- The zero quaternion has no inverse, and the backends do not all give the same non-answer: the six software targets produce NaN, the three HDL targets produce zero, because fixed point has no NaN. Nothing upstream is checked and no error is logged.
- Deliberately no state space – the map is not linear, so there is no linear form to fabricate.
Code facts#
| Fact | Value |
|---|---|
| registered type | Robotics/Orientation_3D/Quaternion_Inverse |
| family | Robotics/Orientation_3D |
| solver environment class | ICoreBlock_0_Robotics_1_Orientation_3D_2_Quaternion_Inverse |
| source | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Robotics/Orientation_3D/Quaternion_Inverse/ICoreBlock_0_Robotics_1_Orientation_3D_2_Quaternion_Inverse.cpp |
| header | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Robotics/Orientation_3D/Quaternion_Inverse/ICoreBlock_0_Robotics_1_Orientation_3D_2_Quaternion_Inverse.h |
| default size on canvas | 112 × 70 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 | q |
| 2 | out | ICoreDouble | q^-1 |
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 | aerolibutil/Quaternion\nInverse |
| port-count rule | PortsParam::None |
SampleTime parameter | no — the counterpart defines none; the rate stays on the ICore side |
Caveat (shown to the user): the Aerospace Blockset block is a masked subsystem with no dialog parameters, so nothing but the signal crosses. It divides the conjugate by the SQUARED norm, which is measured rather than assumed. Note it defines no SampleTime parameter: an ICore rate set explicitly stays on this side and is reported
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:
B0no sample under docs/generated/samples/ — nothing to cross-check (P8.1)
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).
Quaternion Inverse — q^-1 = q* / (q . q), scalar-first [4,1] n = w^2 + x^2 + y^2 + z^2 q^-1 = [ w/n, -x/n, -y/n, -z/n ]
The quaternion that undoes q under the Hamilton product: q (x) q^-1 = [1 0 0 0].
MEASURED against aerolibutil/Quaternion Inverse (R2026a, 2026-09-09): q = [0.3 0.5 -0.7 0.2] answers [0.34482758620689657 -0.57471264367816099 0.8045977011494253 -0.22988505747126442]. That is the conjugate [0.3 -0.5 0.7 -0.2] divided by 0.87 -- the SQUARED norm -- and not by 0.9327, the modulus.
⚠ THE DIVISOR IS THE SQUARE, and it is the single likeliest slip in this block. Dividing by |q| rather than |q|^2 gives an answer wrong by exactly a factor of |q|, which is 1 on a UNIT quaternion -- so a rig fed unit quaternions cannot tell the two apart and would certify the wrong block. The rig for this one is deliberately not unit; the reason is written on its entry in the rig library too, where the next person to touch the tune set will read it.
⚠ ONE RECIPROCAL, NOT FOUR DIVISIONS, in every backend -- the same contract as Quaternion_Normalize, and for the same reason: four independent divisions are arithmetically equivalent and round differently.
⚠ SIMULATION-ONLY on the three HDL targets: Q16.16 has no division.
Sample results#
No sample run is committed for this block. Samples come from the headless harness (DOCS_PLAN.md P8.1) into docs/generated/samples/; until one exists this block's behaviour is witnessed by the parity and export-verification suites, not by a plot here.