farm-ng-core
rotation2.h
Go to the documentation of this file.
1 // Copyright (c) 2011, Hauke Strasdat
2 // Copyright (c) 2012, Steven Lovegrove
3 // Copyright (c) 2021, farm-ng, inc.
4 //
5 // Use of this source code is governed by an MIT-style
6 // license that can be found in the LICENSE file or at
7 // https://opensource.org/licenses/MIT.
8 
9 #pragma once
10 
13 #include "sophus/lie/lie_group.h"
15 
16 namespace sophus {
17 
18 // definition: origin and distance preserving mapping in R^2
19 template <class TScalar>
20 class Rotation2 : public lie::Group<Rotation2, TScalar, lie::Rotation2Impl> {
21  public:
22  using Scalar = TScalar;
23 
25 
26  using Tangent = typename Base::Tangent;
27  using Params = typename Base::Params;
28  using Point = typename Base::Point;
29 
30  Rotation2() = default;
31 
32  explicit Rotation2(UninitTag /*unused*/) {}
33 
34  explicit Rotation2(TScalar angle) : Rotation2(Rotation2::fromAngle(angle)) {}
35 
36  template <class TOtherScalar>
37  explicit Rotation2(TOtherScalar angle)
39 
40  template <class TOtherScalar>
41  auto cast() const -> Rotation2<TOtherScalar> {
43  this->params_.template cast<TOtherScalar>());
44  }
45 
46  static auto fromRotationMatrix(Eigen::Matrix2<TScalar> const& mat_r)
47  -> Rotation2 {
49  isOrthogonal(mat_r),
50  "R is not orthogonal:\n {}",
51  mat_r * mat_r.transpose());
53  mat_r.determinant() > TScalar(0),
54  "det(R) is not positive: {}",
55  mat_r.determinant());
56 
57  return Rotation2::fromParams(mat_r.col(0));
58  }
59 
60  static auto fromAngle(TScalar const& theta) -> Rotation2 {
61  return Rotation2::exp(Eigen::Vector<TScalar, 1>{theta});
62  }
63 
64  static auto fitFromComplex(Complex<TScalar> const& z) -> Rotation2 {
65  return Rotation2::fromParams(z.params().normalized());
66  }
67 
68  static auto fromUnitComplex(Complex<TScalar> const& z) -> Rotation2 {
69  return Rotation2::fromParams(z.params());
70  }
71 
72  static auto fitFromMatrix(Eigen::Matrix2<TScalar> const& mat_r) -> Rotation2 {
74  }
75 
76  [[nodiscard]] auto rotationMatrix() const -> Eigen::Matrix2<TScalar> {
77  return this->matrix();
78  }
79 
80  [[nodiscard]] auto angle() const -> TScalar { return this->log()[0]; }
81 
82  [[nodiscard]] auto unitComplex() const -> Complex<TScalar> {
84  }
85 
86  auto setUnitComplex(Complex<TScalar> const& z) const -> void {
87  this->setParams(z);
88  }
89 };
90 
93 static_assert(concepts::Rotation2<Rotation2F64>);
94 
95 } // namespace sophus
sophus::Rotation2::Rotation2
Rotation2(TScalar angle)
Definition: rotation2.h:34
sophus::lie::Group< Rotation2, TScalar, lie::Rotation2Impl >::Params
Eigen::Vector< Scalar, kNumParams > Params
Definition: lie_group.h:69
Eigen
Definition: params.h:72
sophus::Rotation2::fromAngle
static auto fromAngle(TScalar const &theta) -> Rotation2
Definition: rotation2.h:60
SOPHUS_ASSERT
#define SOPHUS_ASSERT(...)
Definition: common.h:40
sophus::lie::Group< Rotation2, TScalar, lie::Rotation2Impl >::Tangent
Eigen::Vector< Scalar, kDof > Tangent
Definition: lie_group.h:68
sophus::Rotation2::Rotation2
Rotation2(TOtherScalar angle)
Definition: rotation2.h:37
sophus::Rotation2::fromRotationMatrix
static auto fromRotationMatrix(Eigen::Matrix2< TScalar > const &mat_r) -> Rotation2
Definition: rotation2.h:46
sophus::Rotation2::Scalar
TScalar Scalar
Definition: rotation2.h:22
sophus::lie::Group
Definition: lie_group.h:24
sophus::Rotation2::unitComplex
auto unitComplex() const -> Complex< TScalar >
Definition: rotation2.h:82
sophus::Rotation2::Rotation2
Rotation2(UninitTag)
Definition: rotation2.h:32
orthogonal.h
sophus
Image MutImage, owning images types.
Definition: num_diff.h:20
sophus::lie::Group< Rotation2, TScalar, lie::Rotation2Impl >::Point
Eigen::Vector< Scalar, kPointDim > Point
Definition: lie_group.h:70
sophus::lie::Group< Rotation2, TScalar, lie::Rotation2Impl >::fromParams
static auto fromParams(Params const &params) -> Derived
Definition: lie_group.h:79
sophus::Rotation2::fitFromMatrix
static auto fitFromMatrix(Eigen::Matrix2< TScalar > const &mat_r) -> Rotation2
Definition: rotation2.h:72
sophus::lie::Group< Rotation2, TScalar, lie::Rotation2Impl >::params_
Params params_
Definition: lie_group.h:265
sophus::makeRotationMatrix
auto makeRotationMatrix(Eigen::MatrixBase< TD > const &r) -> std::enable_if_t< std::is_floating_point< typename TD::Scalar >::value, Eigen::Matrix< typename TD::Scalar, TD::RowsAtCompileTime, TD::RowsAtCompileTime >>
Takes in arbitrary square matrix (2x2 or larger) and returns closest orthogonal matrix with positive ...
Definition: orthogonal.h:67
sophus::lie::Group< Rotation2, TScalar, lie::Rotation2Impl >::setParams
void setParams(Params const &params)
Definition: lie_group.h:241
sophus::Rotation2::Rotation2
Rotation2()=default
sophus::Complex::fromParams
static auto fromParams(Params const &params) -> Complex
Definition: complex.h:122
sophus::Rotation2::angle
auto angle() const -> TScalar
Definition: rotation2.h:80
sophus::Rotation2::Params
typename Base::Params Params
Definition: rotation2.h:27
sophus::Rotation2::fromUnitComplex
static auto fromUnitComplex(Complex< TScalar > const &z) -> Rotation2
Definition: rotation2.h:68
sophus::lie::Group< Rotation2, TScalar, lie::Rotation2Impl >::log
auto log() const -> Tangent
Definition: lie_group.h:97
lie_group.h
sophus::lie::Group< Rotation2, TScalar, lie::Rotation2Impl >::matrix
auto matrix() const -> Eigen::Matrix< Scalar, kAmbientDim, kAmbientDim >
Definition: lie_group.h:176
rotation2.h
sophus::Rotation2::cast
auto cast() const -> Rotation2< TOtherScalar >
Definition: rotation2.h:41
group_accessors.h
sophus::Rotation2
Definition: rotation2.h:20
sophus::isOrthogonal
auto isOrthogonal(Eigen::MatrixBase< TD > const &r) -> bool
Takes in arbitrary square matrix and returns true if it is orthogonal.
Definition: orthogonal.h:24
sophus::Rotation2::rotationMatrix
auto rotationMatrix() const -> Eigen::Matrix2< TScalar >
Definition: rotation2.h:76
sophus::Rotation2::setUnitComplex
auto setUnitComplex(Complex< TScalar > const &z) const -> void
Definition: rotation2.h:86
sophus::lie::Group< Rotation2, TScalar, lie::Rotation2Impl >::exp
static auto exp(Tangent const &tangent) -> Derived
Definition: lie_group.h:93
sophus::Rotation2::fitFromComplex
static auto fitFromComplex(Complex< TScalar > const &z) -> Rotation2
Definition: rotation2.h:64
sophus::Complex
Definition: group_accessors.h:15
sophus::Rotation2::Point
typename Base::Point Point
Definition: rotation2.h:28
sophus::Rotation2::Tangent
typename Base::Tangent Tangent
Definition: rotation2.h:26
sophus::UninitTag
Definition: common.h:70