Skip to article frontmatterSkip to article content

SO3

Typically, 3D rotations are used in GTSAM via the class Rot3, which can use either SO3 or Quaternion as the underlying representation.

gtsam.SO3 is the 3x3 matrix representation of an element of SO(3), and implements all the Jacobians associated with the group structure.

This document documents some of the math involved.

SO3 implements the exponential map and its inverse, as well as their Jacobians. For more information on Lie groups and their use here, see GTSAM concepts.

Open In Colab

The Exponential Map

The exponential map for SO(3)\text{SO}(3) converts a 3D rotation vector ω (corresponding to a Lie algebra element [ω]×[\boldsymbol{\omega}]_\times in so(3)\mathfrak{so}(3)) into a rotation matrix (Lie group element in SO(3)\text{SO}(3)). I.e., we map a rotation vector ωR3\boldsymbol{\omega} \in \mathbb{R}^3 to a rotation matrix RSO(3)R \in \text{SO}(3).

Given a rotation vector ω=(ωx,ωy,ωz)\boldsymbol{\omega} = (\omega_x, \omega_y, \omega_z), define:

  • The rotation axis as the unit vector:

    ω^=ωθ,where θ=ω\hat{\omega} = \frac{\boldsymbol{\omega}}{\theta}, \quad \text{where } \theta = \|\boldsymbol{\omega}\|
  • The skew-symmetric matrix [ω]×[\boldsymbol{\omega}]_\times:

    [ω]×=[0ωzωyωz0ωxωyωx0][\boldsymbol{\omega}]_\times = \begin{bmatrix} 0 & -\omega_z & \omega_y \\ \omega_z & 0 & -\omega_x \\ -\omega_y & \omega_x & 0 \end{bmatrix}

Using Rodrigues’ formula, the exponential map is:

exp([ω]×)=I+sinθθ[ω]×+1cosθθ2[ω]×2\exp([\boldsymbol{\omega}]_\times) = I + \frac{\sin\theta}{\theta} [\boldsymbol{\omega}]_\times + \frac{1 - \cos\theta}{\theta^2} [\boldsymbol{\omega}]_\times^2

which results in the rotation matrix:

R=I+sinθθ[ω]×+1cosθθ2[ω]×2R = I + \frac{\sin\theta}{\theta} [\boldsymbol{\omega}]_\times + \frac{1 - \cos\theta}{\theta^2} [\boldsymbol{\omega}]_\times^2

where:

  • I I is the 3×3 3 \times 3 identity matrix.
  • θ \theta is the magnitude of the rotation vector (rotation angle).
  • [ω]× [\boldsymbol{\omega}]_\times represents the skew-symmetric matrix, the infinitesimal rotation generator.

For very small θ \theta , we use the Taylor series approximation:

RI+[ω]×R \approx I + [\boldsymbol{\omega}]_\times

since sinθθ \sin\theta \approx \theta and 1cosθθ22 1 - \cos\theta \approx \frac{\theta^2}{2} .

The logarithm map

The logarithm map for SO(3) \text{SO}(3) is the inverse of the exponential map It converts a rotation matrix RSO(3) R \in SO(3) into a 3D rotation vector (corresponding to a Lie algebra element [\boldsymbol{\omega}]_\times in so(3) \mathfrak{so}(3) ).

Given a rotation matrix R R , the corresponding rotation vector ωR3 \boldsymbol{\omega} \in \mathbb{R}^3 is computed as:

ω=θω^\boldsymbol{\omega} = \theta \hat{\omega}

where:

  • θ \theta is the rotation angle:

    θ=cos1(Tr(R)12)\theta = \cos^{-1} \left( \frac{\text{Tr}(R) - 1}{2} \right)
  • ω^ \hat{\omega} is the rotation axis, obtained from the skew-symmetric matrix [ω]× [\boldsymbol{\omega}]_\times :

    [ω]×=θ2sinθ(RRT)[\boldsymbol{\omega}]_\times = \frac{\theta}{2 \sin\theta} (R - R^T)
  • Extracting the components:

    ω=θ2sinθ(RRT)\boldsymbol{\omega} = \frac{\theta}{2 \sin\theta} (R - R^T)^\vee

For small θ \theta , we use the Taylor series approximation:

ω12(RRT)\boldsymbol{\omega} \approx \frac{1}{2} (R - R^T)^\vee

In both cases, (RRT) (R - R^T)^\vee extracts the unique 3D vector from a skew-symmetric matrix:

(RRT)=[R32R23R13R31R21R12](R - R^T)^\vee= \begin{bmatrix} R_{32} - R_{23} \\ R_{13} - R_{31} \\ R_{21} - R_{12} \end{bmatrix}

where Rij R_{ij} are the elements of R R .

Deep Dive: SO(3) Jacobians

The Jacobians defined in SO3.h describe how small changes in the so(3) tangent space (represented by a 3-vector ω) relate to small changes on the SO(3) manifold (represented by rotation matrices RR). They are crucial for tasks like uncertainty propagation, state estimation (e.g., Kalman filtering), and optimization (e.g., bundle adjustment) involving rotations.

Definitions:

Let ω be a vector in the tangent space so(3), θ=ω\theta = \|\omega\| be the rotation angle, and Ω=ω\Omega = \omega^\wedge be the 3x3 skew-symmetric matrix corresponding to ω. The key coefficients used are:

  • A=sin(θ)/θA = \sin(\theta) / \theta
  • B=(1cos(θ))/θ2B = (1 - \cos(\theta)) / \theta^2
  • C=(1A)/θ2=(θsin(θ))/θ3C = (1 - A) / \theta^2 = (\theta - \sin(\theta)) / \theta^3
  • D=(1/θ2)(1A/(2B))D = (1 / \theta^2) (1 - A / (2 * B))

Note: Taylor series expansions are used for these coefficients when θ is close to zero for numerical stability.

1. Right Jacobian (rightJacobian, dexp)

  • Formula: Jr(ω)=IBΩ+CΩ2J_r(\omega) = I - B \Omega + C \Omega^2
  • Relationship to Expmap: Relates a small change δ in the tangent space so(3) to the corresponding small rotation applied on the right on the manifold SO(3).
    Exp(ω+δ)Exp(ω)Exp(Jr(ω)δ)\text{Exp}(\omega + \delta) ≈ \text{Exp}(\omega) \, \text{Exp}(J_r(\omega) \, \delta)
  • Explanation: This Jacobian maps a perturbation δ in the tangent space (at the origin) to the equivalent perturbation τ=Jr(ω)δ\tau = J_r(\omega) \, \delta in the tangent space at R=Exp(ω)R = \text{Exp}(\omega), such that the change on the manifold corresponds to right multiplication by Exp(τ)\text{Exp}(\tau). It represents the derivative of the exponential map considering right-composition (dexp). Often associated with perturbations in the body frame.
  • Synonyms: Right Jacobian of Exp, dexp, Differential of Exp (right convention).

2. Left Jacobian (leftJacobian)

  • Formula: Jl(ω)=I+BΩ+CΩ2J_l(\omega) = I + B \Omega + C \Omega^2
  • Relationship to Expmap: Relates a small change δ in the tangent space so(3) to the corresponding small rotation applied on the left on the manifold SO(3).
    Exp(ω+δ)Exp(Jl(ω)δ)Exp(ω)\text{Exp}(\omega + \delta) ≈ \text{Exp}(J_l(\omega) \, \delta) \, \text{Exp}(\omega)
  • Explanation: This Jacobian maps a perturbation δ in the tangent space (at the origin) to the equivalent perturbation τ=Jl(ω)δ\tau = J_l(\omega) \, \delta in the tangent space at R=Exp(ω)R = \text{Exp}(\omega), such that the change on the manifold corresponds to left multiplication by Exp(τ)\text{Exp}(\tau). Often associated with perturbations in the world frame. Note that Jl(ω)=Jr(omega)J_l(\omega) = J_r(-omega).
  • Synonyms: Left Jacobian of Exp, Differential of Exp (left convention).

3. Inverse Right Jacobian (rightJacobianInverse, invDexp)

  • Formula: Jr1(ω)=I+0.5Ω+DΩ2J_r^{-1}(\omega) = I + 0.5 \Omega + D \Omega^2
  • Relationship to Logmap: Relates a small rotation perturbation τ applied on the right of a rotation R=Exp(ω)R = \text{Exp}(\omega) back to the resulting change in the logarithm map vector (tangent space coordinates).
    Log(RExp(τ))Log(R)Jr1(ω)τ\text{Log}(R \, \text{Exp}(\tau)) - \text{Log}(R) ≈ J_r^{-1}(\omega) \, \tau
  • Explanation: This Jacobian maps a small rotation increment τ (applied in the body frame, i.e., right multiplication) to the corresponding change in the so(3) coordinates ω. It is the derivative of the logarithm map when considering right perturbations. This is frequently needed in optimization algorithms that parameterize updates using right perturbations.
  • Synonyms: Inverse Right Jacobian of Exp, invDexp, Right Jacobian of Log (often implied by context).

4. Inverse Left Jacobian (leftJacobianInverse)

  • Formula: Jl1(ω)=I0.5Ω+DΩ2J_l^{-1}(\omega) = I - 0.5 \Omega + D \Omega^2
  • Relationship to Logmap: Relates a small rotation perturbation τ applied on the left of a rotation R=Exp(ω)R = \text{Exp}(\omega) back to the resulting change in the logarithm map vector (tangent space coordinates).
    Log(Exp(τ)R)Log(R)Jl1(ω)τLog(\text{Exp}(\tau) * R) - \text{Log}(R) ≈ J_l^{-1}(\omega) \, \tau
  • Explanation: This Jacobian maps a small rotation increment τ (applied in the world frame, i.e., left multiplication) to the corresponding change in the so(3) coordinates ω. It is the derivative of the logarithm map when considering left perturbations. Note that Jl1(ω)=Jr1(ω)J_l^{-1}(\omega) = J_r^{-1}(-\omega).
  • Synonyms: Inverse Left Jacobian of Exp, Left Jacobian of Log (often implied by context).

GTSAM Convention

GTSAM updates (retractions) for SO(3)SO(3) in GTSAM are performed using right multiplication:

Rnew=RExp(δ)R_{\text{new}} = R \cdot \text{Exp}(\delta)

where δso(3)\delta \in \mathfrak{so}(3) is a tangent space increment,and hence we naturally uses the right Jacobian Jr(ω)J_r(\omega) for the related derivatives. This choice is also known as right trivialization. This means we relate the tangent space at any rotation R back to the tangent space at the identity (the Lie algebra so(3)) using the differential of right multiplication.

Note that this choice is left-invariant, because we can multiply with an arbitrary rotation matrix RR' on the left above, on both sides, and the update would not be affected. This term is often used in control theory, referring to how error states are defined or how system dynamics evolve relative to a world frame.

Even with the right-multiplication convention, the left Jacobians (associated with world-frame perturbations, R=Exp(τ)RR' = \text{Exp}(\tau) \cdot R) are used in several other places, most notably in Building Jacobians for the SE(3)SE(3) group (Pose3).

Numerical Behavior near 0 and π

SO(3) Jacobian Coefficients Near Zero: Taylor Expansions

When working with the exponential map (Exp\text{Exp}) and logarithm map (Log\text{Log}) for SO(3)SO(3), and especially their Jacobians, we encounter several coefficients that depend on the rotation angle θ=ω\theta = ||\omega||, where ωso(3)\omega \in \mathfrak{so}(3) is the tangent vector.

These coefficients appear in the formulas for the Jacobians and the Exp\text{Exp} map itself:

  • Exp(ω)=I+AW+BW2\text{Exp}(\omega) = I + A \cdot W + B \cdot W^2
  • Jr(ω)=IBW+CW2J_r(\omega) = I - B \cdot W + C \cdot W^2 (Right Jacobian of Exp)
  • Jl(ω)=I+BW+CW2J_l(\omega) = I + B \cdot W + C \cdot W^2 (Left Jacobian of Exp)
  • Jr1(ω)=I+12W+DW2J_r^{-1}(\omega) = I + \frac{1}{2} W + D \cdot W^2 (Inverse Right Jacobian)
  • Jl1(ω)=I12W+DW2J_l^{-1}(\omega) = I - \frac{1}{2} W + D \cdot W^2 (Inverse Left Jacobian)

where W=ωW = \omega^\wedge is the skew-symmetric matrix corresponding to ω.

The coefficients are defined as:

  • A=sin(θ)θA = \frac{\sin(\theta)}{\theta}
  • B=1cos(θ)θ2B = \frac{1 - \cos(\theta)}{\theta^2}
  • C=1Aθ2=θsin(θ)θ3C = \frac{1 - A}{\theta^2} = \frac{\theta - \sin(\theta)}{\theta^3}
  • D=1A2Bθ2=1θ2(1sinθθ21cosθθ2)=1θ2(1sinθ2(1cosθ))D = \frac{1 - \frac{A}{2B}}{\theta^2} = \frac{1}{ \theta^2} \left( 1 - \frac{\frac{\sin\theta}{\theta}}{2 \frac{1 - \cos\theta}{\theta^2}} \right) = \frac{1}{\theta^2} \left( 1 - \frac{\sin\theta}{2(1-\cos\theta)} \right)

The Problem Near θ=0\theta = 0

As the rotation angle θ approaches zero, the standard formulas for these coefficients become numerically unstable due to division by zero or indeterminate forms like 0/00/0.

  • AA: sin(0)000\frac{\sin(0)}{0} \rightarrow \frac{0}{0}
  • BB: 1cos(0)0200\frac{1 - \cos(0)}{0^2} \rightarrow \frac{0}{0}
  • CC: 0sin(0)0300\frac{0 - \sin(0)}{0^3} \rightarrow \frac{0}{0}
  • DD: Involves AA and BB.

Direct computation using floating-point arithmetic near θ=0\theta=0 leads to loss of precision or NaN results.

The Solution: Taylor Series Expansions

To maintain numerical stability and accuracy near θ=0\theta=0, we replace the exact formulas with their Taylor series expansions around θ=0\theta=0. GTSAM’s ExpmapFunctor and DexpFunctor use expansions including the θ2\theta^2 term, which provides good accuracy for small angles.

  • A=1θ26+O(θ4)A = 1 - \frac{\theta^2}{6} + O(\theta^4)
  • B=12θ224+O(θ4)B = \frac{1}{2} - \frac{\theta^2}{24} + O(\theta^4)
  • C=16θ2120+O(θ4)C = \frac{1}{6} - \frac{\theta^2}{120} + O(\theta^4)
  • D=112+θ2720+O(θ4)D = \frac{1}{12} + \frac{\theta^2}{720} + O(\theta^4)

Let’s visualize how well these approximations work near θ=0\theta=0.

SO(3) Jacobian Coefficients Near Singularities: GTSAM Calculation

This notebook visualizes how GTSAM’s DexpFunctor calculates the Jacobian coefficients C and D near the singularities at θ=0\theta = 0 and θ=π\theta = \pi. It compares the values computed by GTSAM (which uses Taylor expansions in the singular regions) against the exact mathematical formulas.

Visualization Near Zero (θ0\theta \approx 0)

<Figure size 1200x1600 with 8 Axes>

Interpretation Near Zero: The plots show the Taylor expansion values computed by GTSAM (. markers) and the “exact” mathematical formulas (-- lines). The red dotted line indicates the threshold θ=1050.00316\theta = \sqrt{10^{-5}} \approx 0.00316 radians.

For A and B, the difference plot shows that the Taylor expansion introduces a small approximation error below the threshold. The error increases as θ moves away from 0. ForC and D the exact formula is itself hard to compute accurately, but we see that the error of the Taylor expansion starts going up only far from the threshold.

Visualization Near Pi (θπ\theta \approx \pi)

GTSAM specifically uses a Taylor expansion for coefficient D near π, as the standard formula becomes unstable. Other coefficients (A, B, C) are typically computed using their standard, stable forms near π.

<Figure size 1200x500 with 2 Axes>

Interpretation Near Pi: The plots focus on coefficient D as θ approaches π. The red dotted line indicates the threshold θ=π103π0.0316\theta = \pi - \sqrt{10^{-3}} \approx \pi - 0.0316 radians.

We only plot the Taylor expansion. To the right of the threshold (closer to π) GTSAM will use this, and the difference plot shows the approximation error introduced by this Taylor expansion is small (less than 10e810e-8).