gtsam  4.0.0
gtsam
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 
21 #pragma once
22 
23 #include <gtsam/base/Matrix.h>
24 #include <gtsam/base/Lie.h>
25 
26 #include <cmath>
27 #include <iosfwd>
28 
29 namespace gtsam {
30 
36 class SO3: public Matrix3, public LieGroup<SO3, 3> {
37 
38 protected:
39 
40 public:
41  enum {
42  dimension = 3
43  };
44 
47 
49  SO3() :
50  Matrix3(I_3x3) {
51  }
52 
54  template<typename Derived>
55  SO3(const MatrixBase<Derived>& R) :
56  Matrix3(R.eval()) {
57  }
58 
60  SO3(const Eigen::AngleAxisd& angleAxis) :
61  Matrix3(angleAxis) {
62  }
63 
65  static SO3 AxisAngle(const Vector3& axis, double theta);
66 
70 
71  void print(const std::string& s) const;
72 
73  bool equals(const SO3 & R, double tol) const {
74  return equal_with_abs_tol(*this, R, tol);
75  }
76 
80 
82  static SO3 identity() {
83  return I_3x3;
84  }
85 
87  SO3 inverse() const {
88  return this->Matrix3::inverse();
89  }
90 
94 
99  static SO3 Expmap(const Vector3& omega, ChartJacobian H = boost::none);
100 
102  static Matrix3 ExpmapDerivative(const Vector3& omega);
103 
108  static Vector3 Logmap(const SO3& R, ChartJacobian H = boost::none);
109 
111  static Matrix3 LogmapDerivative(const Vector3& omega);
112 
113  Matrix3 AdjointMap() const {
114  return *this;
115  }
116 
117  // Chart at origin
118  struct ChartAtOrigin {
119  static SO3 Retract(const Vector3& omega, ChartJacobian H = boost::none) {
120  return Expmap(omega, H);
121  }
122  static Vector3 Local(const SO3& R, ChartJacobian H = boost::none) {
123  return Logmap(R, H);
124  }
125  };
126 
128 
130 };
131 
132 // This namespace exposes two functors that allow for saving computation when
133 // exponential map and its derivatives are needed at the same location in so<3>
134 // The second functor also implements dedicated methods to apply dexp and/or inv(dexp)
135 namespace so3 {
136 
138 class GTSAM_EXPORT ExpmapFunctor {
139  protected:
140  const double theta2;
141  Matrix3 W, K, KK;
142  bool nearZero;
143  double theta, sin_theta, one_minus_cos; // only defined if !nearZero
144 
145  void init(bool nearZeroApprox = false);
146 
147  public:
149  ExpmapFunctor(const Vector3& omega, bool nearZeroApprox = false);
150 
152  ExpmapFunctor(const Vector3& axis, double angle, bool nearZeroApprox = false);
153 
155  SO3 expmap() const;
156 };
157 
159 class GTSAM_EXPORT DexpFunctor : public ExpmapFunctor {
160  const Vector3 omega;
161  double a, b;
162  Matrix3 dexp_;
163 
164  public:
166  DexpFunctor(const Vector3& omega, bool nearZeroApprox = false);
167 
168  // NOTE(luca): Right Jacobian for Exponential map in SO(3) - equation
169  // (10.86) and following equations in G.S. Chirikjian, "Stochastic Models,
170  // Information Theory, and Lie Groups", Volume 2, 2008.
171  // expmap(omega + v) \approx expmap(omega) * expmap(dexp * v)
172  // This maps a perturbation v in the tangent space to
173  // a perturbation on the manifold Expmap(dexp * v) */
174  const Matrix3& dexp() const { return dexp_; }
175 
177  Vector3 applyDexp(const Vector3& v, OptionalJacobian<3, 3> H1 = boost::none,
178  OptionalJacobian<3, 3> H2 = boost::none) const;
179 
181  Vector3 applyInvDexp(const Vector3& v,
182  OptionalJacobian<3, 3> H1 = boost::none,
183  OptionalJacobian<3, 3> H2 = boost::none) const;
184 };
185 } // namespace so3
186 
187 template<>
188 struct traits<SO3> : public internal::LieGroup<SO3> {
189 };
190 
191 template<>
192 struct traits<const SO3> : public internal::LieGroup<SO3> {
193 };
194 } // end namespace gtsam
195 
static SO3 identity()
identity rotation for group operation
Definition: SO3.h:82
Functor that implements Exponential map and its derivatives.
Definition: SO3.h:159
bool equal_with_abs_tol(const Eigen::DenseBase< MATRIX > &A, const Eigen::DenseBase< MATRIX > &B, double tol=1e-9)
equals with a tolerance
Definition: Matrix.h:82
static Vector3 Logmap(const SO3 &R, ChartJacobian H=boost::none)
Log map at identity - returns the canonical coordinates of this rotation.
Definition: SO3.cpp:139
Both LieGroupTraits and Testable.
Definition: Lie.h:237
Template to create a binary predicate.
Definition: Testable.h:110
Functor implementing Exponential map.
Definition: SO3.h:138
OptionalJacobian is an Eigen::Ref like class that can take be constructed using either a fixed size o...
Definition: OptionalJacobian.h:39
A CRTP helper class that implements Lie group methods Prerequisites: methods operator*,...
Definition: Lie.h:36
SO3()
Constructor from AngleAxisd.
Definition: SO3.h:49
SO3 inverse() const
inverse of a rotation = transpose
Definition: SO3.h:87
Definition: SO3.h:118
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
SO3(const Eigen::AngleAxisd &angleAxis)
Constructor from AngleAxisd.
Definition: SO3.h:60
True SO(3), i.e., 3*3 matrix subgroup We guarantee (all but first) constructors only generate from su...
Definition: SO3.h:36
static SO3 AxisAngle(const Vector3 &axis, double theta)
Static, named constructor TODO think about relation with above.
Definition: SO3.cpp:115
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
SO3(const MatrixBase< Derived > &R)
Constructor from Eigen Matrix.
Definition: SO3.h:55
typedef and functions to augment Eigen's MatrixXd
Base class and basic functions for Lie types.
static Matrix3 LogmapDerivative(const Vector3 &omega)
Derivative of Logmap.
Definition: SO3.cpp:182
static SO3 Expmap(const Vector3 &omega, ChartJacobian H=boost::none)
Exponential map at identity - create a rotation from canonical coordinates using Rodrigues' formula.
Definition: SO3.cpp:125
static Matrix3 ExpmapDerivative(const Vector3 &omega)
Derivative of Expmap.
Definition: SO3.cpp:134