Created by Codex.
Solve and optionally certify spatial rotation averaging through the Shonan staircase.
Mathematical idea¶
For spatial rotations , Shonan averaging minimizes weighted relative-rotation disagreement,
then lifts to levels when necessary for certification. is the three-dimensional special orthogonal group; one global rotation remains unobservable unless an anchor fixes the world frame.
import gtsam
import numpy as np
from gtsam import symbol_shorthand
C = symbol_shorthand.C
K = symbol_shorthand.K
P = symbol_shorthand.P
S = symbol_shorthand.S
X = symbol_shorthand.XInputs¶
The 3D interface accepts BinaryMeasurementRot3, BetweenFactorPose3, or a three-dimensional general graph optimization (g2o) file. Measurements must follow the ordered edge convention: R_ij maps from key i to key j under GTSAM’s between-measurement convention.
rotation_noise = gtsam.noiseModel.Isotropic.Sigma(3, 0.05)
measurements = [
gtsam.BinaryMeasurementRot3(0, 1, gtsam.Rot3.RzRyRx(0.1, 0.0, 0.0), rotation_noise),
gtsam.BinaryMeasurementRot3(1, 2, gtsam.Rot3.RzRyRx(0.0, -0.1, 0.0), rotation_noise),
gtsam.BinaryMeasurementRot3(0, 2, gtsam.Rot3.RzRyRx(0.1, -0.1, 0.0), rotation_noise),
]
parameters = gtsam.ShonanAveragingParameters3(gtsam.LevenbergMarquardtParams())
shonan = gtsam.ShonanAveraging3(measurements, parameters)
rotations, certificate = shonan.run(3, 6)
print("measurements:", shonan.numberMeasurements())
print("certificate value:", certificate)
print("R(2):")
print(rotations.atRot3(2).matrix())measurements: 3
certificate value: 0.0
R(2):
[[-1. 0. 0.]
[ 0. -1. 0.]
[ 0. 0. 1.]]
Workflow¶
Inspect residuals and connectivity before running the staircase. Rotation averaging has one global rotation gauge; set an anchor in ShonanAveragingParameters3 if the output must align with a chosen world frame.