gtsam 4.1.1
gtsam
SOn-inl.h
Go to the documentation of this file.
1/* ----------------------------------------------------------------------------
2
3 * GTSAM Copyright 2010-2019, 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
12#pragma once
13
21#include <gtsam/base/Matrix.h>
22
23#include <iostream>
24
25namespace gtsam {
26
27// Implementation for N>=5 just uses dynamic version
28template <int N>
29typename SO<N>::MatrixNN SO<N>::Hat(const TangentVector& xi) {
30 return SOn::Hat(xi);
31}
32
33// Implementation for N>=5 just uses dynamic version
34template <int N>
35typename SO<N>::TangentVector SO<N>::Vee(const MatrixNN& X) {
36 return SOn::Vee(X);
37}
38
39template <int N>
41 if (H) throw std::runtime_error("SO<N>::Retract jacobian not implemented.");
42 const Matrix X = Hat(xi / 2.0);
43 size_t n = AmbientDim(xi.size());
44 const auto I = Eigen::MatrixXd::Identity(n, n);
45 // https://pdfs.semanticscholar.org/6165/0347b2ccac34b5f423081d1ce4dbc4d09475.pdf
46 return SO((I + X) * (I - X).inverse());
47}
48
49template <int N>
50typename SO<N>::TangentVector SO<N>::ChartAtOrigin::Local(const SO& R,
51 ChartJacobian H) {
52 if (H) throw std::runtime_error("SO<N>::Local jacobian not implemented.");
53 const size_t n = R.rows();
54 const auto I = Eigen::MatrixXd::Identity(n, n);
55 const Matrix X = (I - R.matrix_) * (I + R.matrix_).inverse();
56 return -2 * Vee(X);
57}
58
59template <int N>
60typename SO<N>::MatrixDD SO<N>::AdjointMap() const {
61 if (N==2) return I_1x1; // SO(2) case
62 throw std::runtime_error(
63 "SO<N>::AdjointMap only implemented for SO2, SO3 and SO4.");
64}
65
66template <int N>
67SO<N> SO<N>::Expmap(const TangentVector& omega, ChartJacobian H) {
68 throw std::runtime_error("SO<N>::Expmap only implemented for SO3 and SO4.");
69}
70
71template <int N>
72typename SO<N>::MatrixDD SO<N>::ExpmapDerivative(const TangentVector& omega) {
73 throw std::runtime_error("SO<N>::ExpmapDerivative only implemented for SO3.");
74}
75
76template <int N>
77typename SO<N>::TangentVector SO<N>::Logmap(const SO& R, ChartJacobian H) {
78 throw std::runtime_error("SO<N>::Logmap only implemented for SO3.");
79}
80
81template <int N>
82typename SO<N>::MatrixDD SO<N>::LogmapDerivative(const TangentVector& omega) {
83 throw std::runtime_error("O<N>::LogmapDerivative only implemented for SO3.");
84}
85
86// Default fixed size version (but specialized elsewehere for N=2,3,4)
87template <int N>
88typename SO<N>::VectorN2 SO<N>::vec(
89 OptionalJacobian<internal::NSquaredSO(N), dimension> H) const {
90 // Vectorize
91 VectorN2 X = Eigen::Map<const VectorN2>(matrix_.data());
92
93 // If requested, calculate H as (I \oplus Q) * P,
94 // where Q is the N*N rotation matrix, and P is calculated below.
95 if (H) {
96 // Calculate P matrix of vectorized generators
97 // TODO(duy): Should we refactor this as the jacobian of Hat?
98 Matrix P = SO<N>::VectorizedGenerators();
99 for (size_t i = 0; i < N; i++) {
100 H->block(i * N, 0, N, dimension) =
101 matrix_ * P.block(i * N, 0, N, dimension);
102 }
103 }
104 return X;
105}
106
107template <int N>
108void SO<N>::print(const std::string& s) const {
109 std::cout << s << matrix_ << std::endl;
110}
111
112} // namespace gtsam
typedef and functions to augment Eigen's MatrixXd
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
OptionalJacobian is an Eigen::Ref like class that can take be constructed using either a fixed size o...
Definition: OptionalJacobian.h:39
Manifold of special orthogonal rotation matrices SO<N>.
Definition: SOn.h:50
static SO Expmap(const TangentVector &omega, ChartJacobian H=boost::none)
Exponential map at identity - create a rotation from canonical coordinates.
Definition: SOn-inl.h:67
static Matrix VectorizedGenerators()
Calculate N^2 x dim matrix of vectorized Lie algebra generators for SO(N)
Definition: SOn.h:297
SO inverse() const
inverse of a rotation = transpose
Definition: SOn.h:190
VectorN2 vec(OptionalJacobian< internal::NSquaredSO(N), dimension > H=boost::none) const
Return vectorized rotation matrix in column order.
Definition: SOn-inl.h:88
static TangentVector Vee(const MatrixNN &X)
Inverse of Hat. See note about xi element order in Hat.
Definition: SOn-inl.h:35
MatrixNN matrix_
Rotation matrix.
Definition: SOn.h:60
static TangentVector Logmap(const SO &R, ChartJacobian H=boost::none)
Log map at identity - returns the canonical coordinates of this rotation.
Definition: SOn-inl.h:77
MatrixDD AdjointMap() const
Adjoint map.
Definition: SO4.cpp:159
static MatrixNN Hat(const TangentVector &xi)
Hat operator creates Lie algebra element corresponding to d-vector, where d is the dimensionality of ...
Definition: SOn-inl.h:29
static MatrixDD ExpmapDerivative(const TangentVector &omega)
Derivative of Expmap, currently only defined for SO3.
Definition: SOn-inl.h:72
static MatrixDD LogmapDerivative(const TangentVector &omega)
Derivative of Logmap, currently only defined for SO3.
Definition: SOn-inl.h:82
SO()
Construct SO<N> identity for N >= 2.
Definition: SOn.h:77
static TangentVector Local(const SO &R, ChartJacobian H=boost::none)
Inverse of Retract.
Definition: SOn-inl.h:50
static SO Retract(const TangentVector &xi, ChartJacobian H=boost::none)
Retract uses Cayley map.
Definition: SOn-inl.h:40