Modified Rodrigues Parameters are a compact method to describe orientations. We’re all familiar with 3×3 matrices, and most of us also know about quaternions.
While 3×3 matrices require 9 numbers, quaternions only require 4 numbers; so, a great savings in space is obtained using quaternions. In addition, quaternions are also nice to work with.
However, quaternions are not the most compact form for representing rotations in three dimensions; only three numbers are actually needed. One can encode the axis of rotation in a unit vector, and the angle can then be represented by its length. Obviously, different methods can be used to encode the angle.
In Modified Rodrigues Parameters (MRP) representation, the orientation is encoded as:
MRP = E * tan(phi/4)
where E is the unit vector (e1,e2,e3) describing the axis of rotation, and phi is the angle of rotation about this axis.
To be able to use the MRP, we often need to convert it to different representations, a quaternion, or a 3×3 rotation matrix.
The quaternion Q=(q1,q2,q3,q4) can be obtained from MRP m=(m1,m2,m3) as follows:
q1 = 2 * m1 * D q2 = 2 * m2 * D q3 = 2 * m3 * D q4 = (1-|m|*|m|) * D
where D is given as:
D = 1 / (1 + |m|*|m|)
and |m| is the length of the MRP vector m as in:
|m| = sqrt(m1*m1+m2*m2+m3*m3),
Converting a quaternion to Modified Rodrigues Parameter (MRP) m is even easier:
m1 = q1 / k m2 = q2 / k m3 = q3 / k
where k is defined as:
k = 1 / (1 + q4)
In our definition of the quaternion above, the real component is the last number.
Convert MRP to the 3×3 matrix M is quite a bit trickier, but fortunately, this procedure is adequately documented in some publications. The following expressions can be used:
M = I + a*X + b*(X*X)
where I is the 3×3 identity matrix, and X is 3×3 the skew-symmetric matrix:
0 -m3 m2 X = m3 0 -m1 -m2 m1 0
and, with a and b calculated as:
a = 4 * (1-|m|*|m|) / ((1+|m|*|m|) * (1+|m|*|m|)) b = 8 / ((1+|m|*|m|) * (1+|m|*|m|))
The above equations are detailed in the paper “A Survey of Attitude Representations”, Malcolm D. Shuster, J. Astronautical Sciences, Vol. 41, No. 4. Oct-Dec. 1993.
Converting a 3×3 matrix to Modified Rodrigues Parameter representation, i.e. the opposite of the procedure above, turned out to be not documented in any literature I’ve been able to find. So, taking a stab at it by using our existing knowledge to extract axis and angle from a 3×3 rotation matrix M:
cos(phi) = (m11+m22+m33-1)/2 r1 = (m32-m23) r2 = (m13-m31) r3 = (m21-m12)
Note that R=(r1,r2,r3) has length of 2*sin(phi), so at this point in time we have both
sin(phi) and cos(phi). Thus, angle phi can be extracted by:
which can be simplified to:
Then the MRP m can be obtained by:
m1 = r1*tan(phi/4)/|R| m2 = r2*tan(phi/4)/|R| m3 = r3*tan(phi/4)/|R|
The above solution works quite well; however, it involves expensive calls to tan() and atan2(), which we’d rather avoid.
Fortunately, we can in fact avoid them! First, recall that:
cos(phi/2) = (1/2) * sqrt(m11+m22+m33+1)
Now, apply half-angle formula for cos(), which yields the following identities:
cos^2(phi/4) = (1 + (1/2) * sqrt(m11+m22+m33+1))/2 sin^2(phi/4) = (1 - (1/2) * sqrt(m11+m22+m33+1))/2
then we easily obtain the required:
tan(phi/4) = sqrt( (1-sqrt(m11+m22+m33+1)/2) / (1+sqrt(m11+m22+m33+1)/2))
With some manipulation, we can produce the most compact calculations yet:
r1 = (m32 - m23) r2 = (m13 - m31) r3 = (m21 - m12) RR = r1*r1 + r2*r2 + r3*r3 C = sqrt(m11 + m22 + m33 + 1)/2 t = sqrt((1 - C) / ((1 + C) * RR)) m1 = r1 * t m2 = r2 * t m3 = r3 * t
This probably represents the fastest method to convert 3×3 matrix into MRP possible;
note, however, a practical implementation should be wary of |R| = 0, which represents
the non-rotation case. However in this case the answer is simply the 0-vector.