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 
28 namespace gtsam {
29 
35 class GTSAM_EXPORT SO3: public Matrix3, public LieGroup<SO3, 3> {
36 
37 protected:
38 
39 public:
40  enum {
41  dimension = 3
42  };
43 
46 
48  SO3() :
49  Matrix3(I_3x3) {
50  }
51 
53  template<typename Derived>
54  SO3(const MatrixBase<Derived>& R) :
55  Matrix3(R.eval()) {
56  }
57 
59  SO3(const Eigen::AngleAxisd& angleAxis) :
60  Matrix3(angleAxis) {
61  }
62 
64  static SO3 AxisAngle(const Vector3& axis, double theta);
65 
69 
70  void print(const std::string& s) const {
71  std::cout << s << *this << std::endl;
72  }
73 
74  bool equals(const SO3 & R, double tol) const {
75  return equal_with_abs_tol(*this, R, tol);
76  }
77 
81 
83  static SO3 identity() {
84  return I_3x3;
85  }
86 
88  SO3 inverse() const {
89  return this->Matrix3::inverse();
90  }
91 
95 
100  static SO3 Expmap(const Vector3& omega, ChartJacobian H = boost::none);
101 
103  static Matrix3 ExpmapDerivative(const Vector3& omega);
104 
109  static Vector3 Logmap(const SO3& R, ChartJacobian H = boost::none);
110 
112  static Matrix3 LogmapDerivative(const Vector3& omega);
113 
114  Matrix3 AdjointMap() const {
115  return *this;
116  }
117 
118  // Chart at origin
119  struct ChartAtOrigin {
120  static SO3 Retract(const Vector3& omega, ChartJacobian H = boost::none) {
121  return Expmap(omega, H);
122  }
123  static Vector3 Local(const SO3& R, ChartJacobian H = boost::none) {
124  return Logmap(R, H);
125  }
126  };
127 
129 
131 };
132 
133 // This namespace exposes two functors that allow for saving computation when
134 // exponential map and its derivatives are needed at the same location in so<3>
135 // The second functor also implements dedicated methods to apply dexp and/or inv(dexp)
136 namespace so3 {
137 
140  protected:
141  const double theta2;
142  Matrix3 W, K, KK;
143  bool nearZero;
144  double theta, sin_theta, one_minus_cos; // only defined if !nearZero
145 
146  void init(bool nearZeroApprox = false);
147 
148  public:
150  ExpmapFunctor(const Vector3& omega, bool nearZeroApprox = false);
151 
153  ExpmapFunctor(const Vector3& axis, double angle, bool nearZeroApprox = false);
154 
156  SO3 expmap() const;
157 };
158 
160 class DexpFunctor : public ExpmapFunctor {
161  const Vector3 omega;
162  double a, b;
163  Matrix3 dexp_;
164 
165  public:
167  DexpFunctor(const Vector3& omega, bool nearZeroApprox = false);
168 
169  // NOTE(luca): Right Jacobian for Exponential map in SO(3) - equation
170  // (10.86) and following equations in G.S. Chirikjian, "Stochastic Models,
171  // Information Theory, and Lie Groups", Volume 2, 2008.
172  // expmap(omega + v) \approx expmap(omega) * expmap(dexp * v)
173  // This maps a perturbation v in the tangent space to
174  // a perturbation on the manifold Expmap(dexp * v) */
175  const Matrix3& dexp() const { return dexp_; }
176 
178  Vector3 applyDexp(const Vector3& v, OptionalJacobian<3, 3> H1 = boost::none,
179  OptionalJacobian<3, 3> H2 = boost::none) const;
180 
182  Vector3 applyInvDexp(const Vector3& v,
183  OptionalJacobian<3, 3> H1 = boost::none,
184  OptionalJacobian<3, 3> H2 = boost::none) const;
185 };
186 } // namespace so3
187 
188 template<>
189 struct traits<SO3> : public internal::LieGroup<SO3> {
190 };
191 
192 template<>
193 struct traits<const SO3> : public internal::LieGroup<SO3> {
194 };
195 } // end namespace gtsam
196 
SO3()
Constructor from AngleAxisd.
Definition: SO3.h:48
Base class and basic functions for Lie types.
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:140
True SO(3), i.e., 3*3 matrix subgroup We guarantee (all but first) constructors only generate from su...
Definition: SO3.h:35
OptionalJacobian is an Eigen::Ref like class that can take be constructed using either a fixed size o...
Definition: OptionalJacobian.h:39
Functor implementing Exponential map.
Definition: SO3.h:139
Functor that implements Exponential map and its derivatives.
Definition: SO3.h:160
A CRTP helper class that implements Lie group methods Prerequisites: methods operator*, inverse, and AdjointMap, as well as a ChartAtOrigin struct that will be used to define the manifold Chart To use, simply derive, but also say "using LieGroup<Class,N>::inverse" For derivative math, see doc/math.pdf.
Definition: Lie.h:36
SO3(const MatrixBase< Derived > &R)
Constructor from Eigen Matrix.
Definition: SO3.h:54
typedef and functions to augment Eigen&#39;s MatrixXd
Template to create a binary predicate.
Definition: Testable.h:110
SO3 inverse() const
inverse of a rotation = transpose
Definition: SO3.h:88
SO3(const Eigen::AngleAxisd &angleAxis)
Constructor from AngleAxisd.
Definition: SO3.h:59
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
Definition: SO3.h:119
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 SO3 identity()
identity rotation for group operation
Definition: SO3.h:83
Both LieGroupTraits and Testable.
Definition: Lie.h:237
Global functions in a separate testing namespace.
Definition: chartTesting.h:28