Linear Algebra · Theory · M10
M10-T5 — The Logarithmic Map
The logarithm turns the difference between two poses into a small vector you can measure, average and plot. It is accurate in the middle and delicate at both ends.
To compare two orientations, compute the error of an estimate, or form a residual in a pose graph, we need the rotation vector of a rotation matrix: the inverse of the exponential. The formula is short, but two special angles need special handling: near 0 (division by zero) and near π (ambiguous axis).
Learning objectives
After this lesson, you should be able to:
- Compute the rotation angle from the trace and the axis from the skew-symmetric part of R, giving log(R).
- Handle θ ≈ 0 with a series and θ ≈ π with the symmetric part, and explain why.
- Write the SE(3) logarithm using V⁻¹, and recover a twist from a pose.
- State what the principal logarithm returns for rotation vectors beyond angle π.
Introduction and motivation
A SLAM system reports an orientation error between its estimate and the ground truth. “Subtract the Euler angles” gives nonsense near the wrap-around, and “subtract the matrices” has no geometric meaning. The right number is the angle of R_estᵀR_true, found from the logarithm. The same operation produces the residual of every pose-graph edge: log(T_measured⁻¹ T_i⁻¹ T_j), a six-vector that the optimiser drives to zero.
The intuition
Any rotation is a turn by some angle about some axis. The trace tells us the angle: it is large when the matrix is close to the identity and equals −1 for a half turn. The skew-symmetric part of R, R − Rᵀ, points along the axis with magnitude proportional to sin θ. Dividing by 2 sin θ and multiplying by θ gives the rotation vector. Problems arise exactly where sin θ vanishes: θ = 0 (identity: no axis information needed, but 0/0) and θ = π (the skew part vanishes: the axis hides in the symmetric part).
Interactive figure. A rotated box driven by a rotation vector with a check that the logarithm returns the same vector. For lengths near or above pi the readout explains that the logarithm becomes ill-posed or wraps to the principal value. This figure needs JavaScript to be interactive.
Geometric and physical interpretation
Geometric view. log maps the group back into the flat tangent space, but a rotation by θ about n is the same as a rotation by 2π − θ about −n, and by θ + 2π about n: the exponential is many-to-one. The principal logarithm picks the shortest vector, with length in [0, π]; at θ = π both ±n are equally short and the choice is arbitrary. Physical view. The magnitude ‖log(R_estᵀR_true)‖ is the geodesic angle between two attitudes (the shortest rotation taking one into the other), the correct attitude error measure.
The mathematics
- θ
- the rotation angle, 0 ≤ θ ≤ π.
- vee(R − Rᵀ)
- the 3-vector (R₃₂ − R₂₃, R₁₃ − R₃₁, R₂₁ − R₁₂).
- V⁻¹
- the inverse of the V matrix of the exponential lesson.
- log: SO(3) → ℝ³, SE(3) → ℝ⁶
- the principal logarithms.
Logarithm on SO(3)
θ = arccos( (tr R − 1) / 2 ), ω = log(R) = ( θ / (2 sin θ) ) · vee( R − Rᵀ )
What it means. The trace gives the angle; the skew part gives the axis scaled by 2 sin θ. The result has ‖ω‖ = θ ≤ π. The formula needs sin θ ≠ 0.
Edge cases
θ → 0: ω ≈ ½ vee(R − Rᵀ) ( 1 + θ²/6 ) θ → π: n from the largest column of (R + I)/2, ω = θ n
What it means. For tiny angles use the series (the first factor θ/sin θ ≈ 1 + θ²/6) so that no 0/0 occurs. Near π the skew part is nearly zero but R + I = 2nnᵀ is not: take a column of it, normalise, and choose a sign.
Logarithm on SE(3)
ξ = log(T): ω = log(R), v = V(ω)⁻¹ t
What it means. Recover the rotation vector from R, then the linear part from the translation through the inverse of V. This returns the unique twist of smallest rotation angle that generates T in unit time.
log(R) = θ/(2 sin θ)·vee(R − Rᵀ) with θ = arccos((tr R − 1)/2); series near 0, symmetric part near π; log(T) = (V⁻¹t, log R). It is the principal inverse of exp.
Step-by-step derivation: angle from the trace, axis from the skew part, edge cases
- Trace. From Rodrigues,
R = I + sin θ K + (1 − cos θ)K²with K = [n]ₓ. The trace of K is 0 and the trace ofK² = nnᵀ − Iis −2. Sotr R = 3 − 2(1 − cos θ) = 1 + 2 cos θ, hencecos θ = (tr R − 1)/2and θ in [0, π] is determined. - Skew part.
R − Rᵀ = 2 sin θ K(the symmetric terms I and K² cancel, and K is skew). Taking the vee:vee(R − Rᵀ) = 2 sin θ n. - Axis and vector. If sin θ ≠ 0,
n = vee(R − Rᵀ)/(2 sin θ)andω = θn = θ/(2 sin θ) · vee(R − Rᵀ). - Small angle. As θ → 0,
sin θ → 0andvee(R − Rᵀ) → 0, so the quotient is 0/0. Usingθ/sin θ = 1 + θ²/6 + 7θ⁴/360 + ⋯givesω ≈ ½vee(R − Rᵀ)(1 + θ²/6), which is finite and accurate. Computing θ by arccos of a number near 1 loses precision too (arccos has infinite slope at 1); better to obtain θ asatan2(‖vee(R − Rᵀ)‖/2, (tr R − 1)/2)everywhere. - Near π. As θ → π,
sin θ → 0so the skew part carries no axis information. ButR + I = 2I + sin θ K + (1 − cos θ)K² → 2nnᵀat θ = π, sinceI + K² = nnᵀ. Taking the column of(R + I)/2 = nnᵀwith the largest diagonal entrynᵢ²and dividing bynᵢrecovers n up to sign; the sign is chosen to match any small remaining skew part (or arbitrarily at exactly π). - Principal value. Because
exp(θn) = exp(−(2π − θ)n), the rotation vector for a given R is not unique; log returns the one with θ ≤ π. If you exponentiate ω of length 3.74 (as in the example) and take the log, you get the vector of length 2π − 3.74 = 2.54 in the opposite direction. - SE(3). For T = (R, t): the twist ξ = (v, ω) must satisfy
R = exp([ω]ₓ)andt = V(ω)v. Soω = log Randv = V⁻¹t, with a closed formV⁻¹ = I − ½[ω]ₓ + (1/θ² − (1 + cos θ)/(2θ sin θ))[ω]ₓ²and the limit V⁻¹ → I − ½[ω]ₓ as θ → 0. - Round-trip test. For any ω with ‖ω‖ below π (say 3.0),
log(exp(ω)) = ωto rounding. Use this as a unit test, along withexp(log(R)) = Rfor random R.
Geodesic distance. Define d(R₁, R₂) = ‖log(R₁ᵀR₂)‖ = θ. It is a proper metric on SO(3): symmetric, zero only if equal, obeying the triangle inequality, and it equals the minimal rotation angle between the two attitudes.
Averaging rotations. The chordal mean (project the matrix average with the SVD) and the Karcher mean (iterate R ← R exp(mean_i log(Rᵀ Rᵢ))) are two standard answers; both rely on the machinery above.
A worked example: round trips, the wrap and the edge cases
- Round trip.
ω = (0.3, −0.2, 0.5):R = exp([ω]ₓ) = [[0.860, −0.498, −0.115], [0.440, 0.835, −0.330], [0.260, 0.233, 0.937]]. The trace is 2.632, socos θ = 0.816andθ = 0.616✓ (equal to ‖ω‖). The skew part isvee(R − Rᵀ) = (0.563, −0.375, 0.938)andθ/(2 sin θ) = 0.533, so the logarithm is0.533·(0.563, −0.375, 0.938) = (0.300, −0.200, 0.500): the original ω is recovered. - Wrap.
ω = (1, 2, 3)has length 3.742 > π.log(exp(ω)) = (−0.679, −1.359, −2.038): length2π − 3.742 = 2.541, direction opposite. Both vectors give the same rotation. - Near π.
R = diag(1, −1, −1)(half turn about x): the skew part is zero, but(R + I)/2 = diag(1, 0, 0), whose largest column is e₁:ω = (π, 0, 0)✓. Likewisediag(−1, 1, −1)gives(0, π, 0). - Near zero. For
ω = (10⁻⁶, 2 × 10⁻⁶, 0)the angle from arccos of the trace is only accurate to about10⁻⁸(relative error 1%); using the atan2 form and the series keeps full precision. - Pose log.
T = exp(ξ^)forξ = (0.5, 0.2, 0; 0, 0, 1)has translation(0.3288, 0.3981, 0);log T = (0.5, 0.2, 0; 0, 0, 1): the linear part is recovered throughV⁻¹t. - Attitude error. An estimate off by 2° about x and 1° about z has
‖log(R_estᵀR_true)‖ = 2.24°(to first order the vector norm combines like Pythagoras).
Robotics application
Pose-graph SLAM. Every edge residual is log(Z⁻¹T_i⁻¹T_j), a six-vector in the tangent space; its covariance is whitened by the information matrix; see pose graphs and nonlinear least squares.
UAV estimation and evaluation. Attitude error against ground truth is reported as the angle of log(R_estᵀR_true); the error-state filter measures the correction as a rotation vector; see the error-state Kalman filter and quaternion-based orientation.
LiDAR registration and calibration. After ICP, the update twist is the log of the relative transform, and trajectory evaluation (ATE, RPE) uses it; see ICP fundamentals and scan registration.
Control and manipulators. Orientation tracking error of a hand pose is log(R_desᵀR), which a feedback law turns into an angular velocity command (Module 8).
Engineering implications and limitations
Practical rules
- Use atan2 for the angle. θ = atan2(‖vee(R − Rᵀ)‖/2, (tr R − 1)/2) is accurate for all angles; arccos of the trace loses precision near 0 and π.
- Branch at both ends. Use a series below about 10⁻⁴ and the symmetric-part formula above about π − 10⁻³; test at exactly 0 and exactly π.
- Clip the trace argument. Rounding can push (tr R − 1)/2 slightly outside [−1, 1] and make arccos return a not-a-number value.
- Know the principal value. A rotation vector of 4 rad is returned as a vector of 2.28 rad about the opposite axis; this matters when you compare against a stored rotation vector.
- Keep inputs on the group. The formula assumes R is a rotation; re-orthonormalise a drifted matrix first.
- Use the same ordering as exp. The twist order (v, ω) and the V matrix must be consistent with the exponential you use.
Limits
The logarithm is discontinuous at θ = π (the cut locus): arbitrarily close rotations can have logarithms far apart. Tangent-space algorithms (filters, optimisers) are only valid when the quantities involved stay well inside π, which is why errors must be small.
Common misconceptions
“log(exp(ω)) = ω always.”
Only for ‖ω‖ < π. Larger vectors come back as the equivalent shorter one.
“The rotation angle is arccos of the trace.”
It is arccos((tr R − 1)/2), and numerically atan2 is better; the trace alone is 1 + 2 cos θ.
“The axis is always the skew part of R.”
Only if sin θ ≠ 0. At θ = π the skew part vanishes and the axis comes from the symmetric part.
“The difference of two rotations is R₁ − R₂.”
The meaningful difference is log(R₁ᵀR₂): its norm is the true angle between them.
Engineering takeaways
- θ = arccos((tr R − 1)/2) (better atan2), and log(R) = θ/(2 sin θ)·vee(R − Rᵀ).
- Near θ = 0 use the series (θ/sin θ ≈ 1 + θ²/6); near θ = π use the symmetric part (R + I)/2 = nnᵀ.
- log(T) = (V⁻¹t, log R) recovers the twist of a pose.
- The principal logarithm has ‖ω‖ ≤ π, so exp is not inverted for larger vectors; ‖log(R₁ᵀR₂)‖ is the geodesic distance between rotations.
- Pose-graph residuals and attitude errors are logarithms; clip, branch and test at 0 and π.
References and further reading
Primary papers and authoritative documentation.
- Solà, Deray and Atchuthan, A micro Lie theory for state estimation in robotics: A micro Lie theory for state estimation in robotics: the logarithmic map
- Modern Robotics (Lynch and Park), free preprint: chapter 3.2.3, the matrix logarithm of a rotation and algorithm 3.1
- Barfoot, State Estimation for Robotics (author-hosted first edition, free to read): chapter 7, logarithmic map and its edge cases
- Buss, Introduction to Inverse Kinematics with Jacobian Transpose, Pseudoinverse and Damped Least Squares: 3D rotations: recovering axis and angle; the site did not load when we last checked
Knowledge check
Three conceptual questions. Write an answer, then reveal the explanation. Your answers stay in your browser.
Question 1
Find the angle and axis of R = [[0, 0, 1], [1, 0, 0], [0, 1, 0]].
Explanation
tr R = 0, so cos θ = −1/2 and θ = 120°. vee(R − Rᵀ) = (R₃₂ − R₂₃, R₁₃ − R₃₁, R₂₁ − R₁₂) = (1 − 0, 1 − 0, 1 − 0) = (1, 1, 1), so the axis is (1, 1, 1)/√3: a 120° turn about the cube diagonal.
Question 2
Compute the logarithm of the half-turn matrix diag(−1, −1, 1), a rotation by 180° about the z-axis.
Explanation
tr = −1, so cos θ = −1, θ = π, and the skew part is 0. (R + I)/2 = diag(0, 0, 1) = nnᵀ with n = e₃, so log(R) = (0, 0, π) (or (0, 0, −π): the same rotation, the sign is arbitrary).
Question 3
The logarithm of exp(ω) for ω = (0, 0, 4) returns what, and why?
Explanation
The angle 4 rad exceeds π. The same rotation is a turn of 2π − 4 = 2.283 rad in the opposite sense about z, so log(exp(ω)) = (0, 0, −2.283): the principal value with ‖ω‖ ≤ π.
What’s next
For small tangent vectors the exponential and logarithm simplify to identity plus a skew matrix. The next lesson quantifies how small is small enough, and what you lose by dropping the higher-order terms.
Related content
Nothing below is required to finish this lesson.
- BeforeM10-T4: The Exponential Map
Map a rotation vector or twist to a rotation or rigid transform, with the closed forms.
Get notified when the next lesson and new labs are released.
One email per new lesson or lab.