gtsam
Loading...
Searching...
No Matches
SO3.h
Go to the documentation of this file.
1/* ----------------------------------------------------------------------------
2
3 * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4 * Atlanta, Georgia 30332-0415
5 * All Rights Reserved
6 * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7
8 * See LICENSE for the license information
9
10 * -------------------------------------------------------------------------- */
11
20
21#pragma once
22
23#include <gtsam/base/Lie.h>
24#include <gtsam/base/Matrix.h>
26#include <gtsam/dllexport.h>
28#include <gtsam/geometry/SOn.h>
29
30#include <optional>
31#include <vector>
32
33namespace gtsam {
34
35using SO3 = SO<3>;
36
37// Below are all declarations of SO<3> specializations.
38// They are *defined* in SO3.cpp.
39
40template <>
41GTSAM_EXPORT
42SO3 SO3::AxisAngle(const Vector3& axis, double theta);
43
44template <>
45GTSAM_EXPORT
46SO3 SO3::ClosestTo(const Matrix3& M);
47
48template <>
49GTSAM_EXPORT
50SO3 SO3::ChordalMean(const std::vector<SO3>& rotations);
51
52template <>
53GTSAM_EXPORT
54Matrix3 SO3::Hat(const Vector3& xi);
55
56template <>
57GTSAM_EXPORT
58Vector3 SO3::Vee(const Matrix3& X);
59
61template <>
62inline Matrix3 SO3::AdjointMap() const{ return matrix_; }
63
68template <>
69GTSAM_EXPORT
70SO3 SO3::Expmap(const Vector3& omega);
71
72template <>
73GTSAM_EXPORT
74SO3 SO3::Expmap(const Vector3& omega, ChartJacobian H);
75
77template <>
78GTSAM_EXPORT
79Matrix3 SO3::ExpmapDerivative(const Vector3& omega);
80
85template <>
86GTSAM_EXPORT
87Vector3 SO3::Logmap(const SO3& R);
88
89template <>
90GTSAM_EXPORT
91Vector3 SO3::Logmap(const SO3& R, ChartJacobian H);
92
94template <>
95GTSAM_EXPORT
96Matrix3 SO3::LogmapDerivative(const Vector3& omega);
97
98// Chart at origin for SO3 is *not* Cayley but actual Expmap/Logmap
99template <>
100GTSAM_EXPORT
101SO3 SO3::ChartAtOrigin::Retract(const Vector3& omega);
102
103template <>
104GTSAM_EXPORT
105SO3 SO3::ChartAtOrigin::Retract(const Vector3& omega, ChartJacobian H);
106
107template <>
108GTSAM_EXPORT
109Vector3 SO3::ChartAtOrigin::Local(const SO3& R);
110
111template <>
112GTSAM_EXPORT
113Vector3 SO3::ChartAtOrigin::Local(const SO3& R, ChartJacobian H);
114
115template <>
116GTSAM_EXPORT
117Vector9 SO3::vec(OptionalJacobian<9, 3> H) const;
118
119#if GTSAM_ENABLE_BOOST_SERIALIZATION
120template <class Archive>
122void serialize(Archive& ar, SO3& R, const unsigned int /*version*/) {
123 Matrix3& M = R.matrix_;
124 ar& boost::serialization::make_nvp("R11", M(0, 0));
125 ar& boost::serialization::make_nvp("R12", M(0, 1));
126 ar& boost::serialization::make_nvp("R13", M(0, 2));
127 ar& boost::serialization::make_nvp("R21", M(1, 0));
128 ar& boost::serialization::make_nvp("R22", M(1, 1));
129 ar& boost::serialization::make_nvp("R23", M(1, 2));
130 ar& boost::serialization::make_nvp("R31", M(2, 0));
131 ar& boost::serialization::make_nvp("R32", M(2, 1));
132 ar& boost::serialization::make_nvp("R33", M(2, 2));
133}
134#endif
135
136namespace so3 {
137
142GTSAM_EXPORT Matrix3 compose(const Matrix3& M, const SO3& R,
143 OptionalJacobian<9, 9> H = {});
144
146GTSAM_EXPORT Matrix99 Dcompose(const SO3& R);
147
154struct GTSAM_EXPORT ExpmapFunctor {
155 double theta2;
156 double theta;
157 Matrix3 W;
158 Matrix3 WW;
159 bool nearZero{false};
160
161 // Ethan Eade's constants:
162 double A; // A = sin(theta) / theta
163 double B; // B = (1 - cos(theta)) / theta^2
164
166 explicit ExpmapFunctor(const Vector3& omega);
167
169 ExpmapFunctor(double nearZeroThresholdSq, const Vector3& axis);
170
172 ExpmapFunctor(const Vector3& axis, double angle);
173
175 inline Matrix3 expmap() const { return I_3x3 + A * W + B * WW; }
176
177protected:
178 void init(double nearZeroThresholdSq);
179};
180
184struct GTSAM_EXPORT DexpFunctor : public ExpmapFunctor {
185 Vector3 omega;
186 bool nearPi{false};
187
189 explicit DexpFunctor(const Vector3& omega);
190
192 explicit DexpFunctor(const Vector3& omega, double nearZeroThresholdSq, double nearPiThresholdSq);
193
194 // Rodrigues kernel: R_[l/r](ω) = I + A(θ) Ω + B(θ) Ω² (left).
195 Kernel Rodrigues() const&;
196
197 // Jacobian kernel J_[l/r](ω) = I +/0 B Ω + C Ω² (left/right).
198 Kernel Jacobian() const&;
199
200 // Specialized kernel for inverse Jacobian, stable even for |ω| > π
201 InvJKernel InvJacobian() const&; // I +/- 1/2 Ω + D Ω²
202
203 // Gamma kernel: Γ_[l/r](ω) = 0.5 I ± C Ω + E Ω² (left/right).
204 Kernel Gamma() const&;
205
206 // NOTE(luca): Right Jacobian for Exponential map in SO(3)
207 // This maps a perturbation dxi=(w,v) in the tangent space to
208 // a perturbation on the manifold Expmap(dexp * xi)
209 Matrix3 rightJacobian() const;
210
211 // Compute the left Jacobian for Exponential map in SO(3)
212 Matrix3 leftJacobian() const;
213
220 Vector3 tangentExpmap(const Vector3& v,
221 OptionalJacobian<6, 6> H = {}) const;
222
228 Vector3 tangentExpmap(const Vector3& v, const Matrix3& rotation,
229 OptionalJacobian<6, 6> H = {}) const;
230
231#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V43
233 Matrix3 rightJacobianInverse() const;
234
236 Matrix3 leftJacobianInverse() const;
237
239 Vector3 applyRightJacobian(const Vector3& v,
240 OptionalJacobian<3, 3> H1 = {}, OptionalJacobian<3, 3> H2 = {}) const;
241
243 Vector3 applyRightJacobianInverse(const Vector3& v,
244 OptionalJacobian<3, 3> H1 = {}, OptionalJacobian<3, 3> H2 = {}) const;
245
247 Vector3 applyLeftJacobian(const Vector3& v,
248 OptionalJacobian<3, 3> H1 = {}, OptionalJacobian<3, 3> H2 = {}) const;
249
251 Vector3 applyLeftJacobianInverse(const Vector3& v,
252 OptionalJacobian<3, 3> H1 = {}, OptionalJacobian<3, 3> H2 = {}) const;
253
255 inline Matrix3 dexp() const { return rightJacobian(); }
256
258 inline Matrix3 invDexp() const { return rightJacobianInverse(); }
259#endif
260
261 // access to (lazily evaluated) coefficients
262 double C() const;
263 double D() const;
264 double E() const;
265
266 // access to (lazily evaluated) radial derivatives c'(θ)/θ
267 double dA() const;
268 double dB() const;
269 double dC() const;
270 double dE() const;
271
272 protected:
273 // Lazy caches stored as std::optional
274 mutable std::optional<double> C_, D_, E_;
275 mutable std::optional<double> dA_, dB_, dC_, dE_;
276};
277} // namespace so3
278
279/*
280 * Define the traits. internal::MatrixLieGroup provides both Lie group and Testable
281 */
282
283template <>
284struct traits<SO3> : public internal::MatrixLieGroup<SO3, 3> {};
285
286template <>
287struct traits<const SO3> : public internal::MatrixLieGroup<SO3, 3> {};
288
289} // end namespace gtsam
typedef and functions to augment Eigen's MatrixXd
Macros for Matrix constants to avoid excessive template instantiation.
Base class and basic functions for Lie types.
N*N matrix representation of SO(N).
GTSAM_EXPORT Matrix99 Dcompose(const SO3 &Q)
(constant) Jacobian of compose wrpt M
Definition SO3.cpp:61
GTSAM_EXPORT Matrix3 compose(const Matrix3 &M, const SO3 &R, OptionalJacobian< 9, 9 > H)
Compose general matrix with an SO(3) element.
Definition SO3.cpp:70
Specialized kernels for SO(3).
Global functions in a separate testing namespace.
Definition chartTesting.h:28
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
static SO< N > Retract(const TangentVector &v)
Definition Lie.h:193
Both LieGroupTraits and Testable.
Definition MatrixLieGroup.h:350
OptionalJacobian is an Eigen::Ref like class that can take be constructed using either a fixed size o...
Definition OptionalJacobian.h:40
Kernel: M(ω) = a I + b Ω + c Ω² with radial derivatives db,dc for Fréchet.
Definition Kernel.h:38
Definition Kernel.h:58
Opaque evaluation context at ω: caches Ω, Ω², θ, θ², nearZero/nearPi, Lazily computes C,...
Definition SO3.h:154
bool nearZero
Flag indicating if theta is near zero.
Definition SO3.h:159
double theta
The norm of the rotation vector (θ).
Definition SO3.h:156
Matrix3 expmap() const
Rodrigues formula.
Definition SO3.h:175
Matrix3 WW
The square of the skew-symmetric matrix (Ω²).
Definition SO3.h:158
Matrix3 W
The skew-symmetric matrix Ω for the rotation vector.
Definition SO3.h:157
ExpmapFunctor(const Vector3 &omega)
Constructor with element of Lie algebra so(3).
Definition SO3.cpp:95
double theta2
The squared norm of the rotation vector (θ²).
Definition SO3.h:155
Functor that implements Exponential map and its derivatives Math extends Ethan theme of elegant I + a...
Definition SO3.h:184
std::optional< double > E_
C, D and E lazily computed.
Definition SO3.h:274
bool nearPi
Flag indicating if theta is near pi.
Definition SO3.h:186
std::optional< double > dE_
lazy c(θ)′/θ
Definition SO3.h:275
DexpFunctor(const Vector3 &omega)
Constructor with element of Lie algebra so(3).
Definition SO3.cpp:122
Vector3 omega
The rotation vector.
Definition SO3.h:185
Manifold of special orthogonal rotation matrices SO<N>.
Definition SOn.h:55
static SO ChordalMean(const std::vector< SO > &rotations)
static TangentVector Vee(const MatrixNN &X)
MatrixNN matrix_
Rotation matrix.
Definition SOn.h:66
VectorN2 vec(OptionalJacobian< internal::NSquaredSO(N), dimension > H={}) const
Definition SOn.h:306
static SO Expmap(const TangentVector &omega)
static SO AxisAngle(const Vector3 &axis, double theta)
Definition SO3.cpp:254
static MatrixNN Hat(const TangentVector &xi)
static MatrixDD LogmapDerivative(const TangentVector &omega)=delete
static MatrixDD ExpmapDerivative(const TangentVector &omega)=delete
static TangentVector Logmap(const SO &R)
MatrixDD AdjointMap() const
Definition SOn.h:272
static SO ClosestTo(const MatrixNN &M)