smooth
A C++ library for Lie theory
Loading...
Searching...
No Matches
c1.hpp
1// Copyright (C) 2021-2022 Petter Nilsson. MIT License.
2
3#pragma once
4
5#include <complex>
6
7#include <Eigen/Core>
8
9#include "detail/c1.hpp"
10#include "detail/macro.hpp"
11#include "lie_group_base.hpp"
12#include "smooth/detail/macro.hpp"
13#include "so2.hpp"
14
15SMOOTH_BEGIN_NAMESPACE
16
17// \cond
18template<typename Scalar>
19class SO2;
20// \endcond
21
60template<typename _Derived>
61class C1Base : public LieGroupBase<_Derived>
62{
64
65protected:
66 C1Base() = default;
67
68public:
69 SMOOTH_INHERIT_TYPEDEFS;
70
74 Scalar angle() const
75 {
76 using std::atan2;
77
78 return atan2(static_cast<const _Derived &>(*this).coeffs().x(), static_cast<const _Derived &>(*this).coeffs().y());
79 }
80
85 {
86 using std::sqrt;
87
88 return sqrt(
89 static_cast<const _Derived &>(*this).coeffs().x() * static_cast<const _Derived &>(*this).coeffs().x()
90 + static_cast<const _Derived &>(*this).coeffs().y() * static_cast<const _Derived &>(*this).coeffs().y());
91 }
92
97 {
98 return SO2<Scalar>(c1()); // it's normalized inside SO2
99 }
100
104 std::complex<Scalar> c1() const
105 {
106 return std::complex<Scalar>(
107 static_cast<const _Derived &>(*this).coeffs().y(), static_cast<const _Derived &>(*this).coeffs().x());
108 }
109
113 template<typename EigenDerived>
114 Eigen::Matrix<Scalar, 2, 1> operator*(const Eigen::MatrixBase<EigenDerived> & v) const
115 {
116 return Base::matrix() * v;
117 }
118};
119
120// \cond
121template<typename _Scalar>
122class C1;
123// \endcond
124
125// \cond
126template<typename _Scalar>
127struct liebase_info<C1<_Scalar>>
128{
129 static constexpr bool is_mutable = true;
130
131 using Impl = C1Impl<_Scalar>;
132 using Scalar = _Scalar;
133
134 template<typename NewScalar>
136};
137// \endcond
138
144template<typename _Scalar>
145class C1 : public C1Base<C1<_Scalar>>
146{
147 using Base = C1Base<C1<_Scalar>>;
148 SMOOTH_GROUP_API(C1);
149
150public:
157 C1(const Scalar & scaling, const Scalar & angle)
158 {
159 using std::cos, std::sin;
160
161 m_coeffs.x() = scaling * sin(angle);
162 m_coeffs.y() = scaling * cos(angle);
163 }
164
170 explicit C1(const std::complex<Scalar> & c)
171 {
172 m_coeffs.x() = c.imag();
173 m_coeffs.y() = c.real();
174 }
175};
176
177// \cond
178template<typename _Scalar>
179struct liebase_info<Map<C1<_Scalar>>> : public liebase_info<C1<_Scalar>>
180{};
181// \endcond
182
188template<typename _Scalar>
189class Map<C1<_Scalar>> : public C1Base<Map<C1<_Scalar>>>
190{
192
193 SMOOTH_MAP_API();
194};
195
196// \cond
197template<typename _Scalar>
198struct liebase_info<Map<const C1<_Scalar>>> : public liebase_info<C1<_Scalar>>
199{
200 static constexpr bool is_mutable = false;
201};
202// \endcond
203
209template<typename _Scalar>
210class Map<const C1<_Scalar>> : public C1Base<Map<const C1<_Scalar>>>
211{
213
214 SMOOTH_CONST_MAP_API();
215};
216
217using C1f = C1<float>;
218using C1d = C1<double>;
219
220SMOOTH_END_NAMESPACE
Base class for C1 Lie group types.
Definition c1.hpp:62
Eigen::Matrix< Scalar, 2, 1 > operator*(const Eigen::MatrixBase< EigenDerived > &v) const
Rotation and scaling action on 2D vector.
Definition c1.hpp:114
SO2< Scalar > so2() const
Rotation.
Definition c1.hpp:96
std::complex< Scalar > c1() const
Complex number representation.
Definition c1.hpp:104
Scalar angle() const
Rotation angle.
Definition c1.hpp:74
Scalar scaling() const
Scaling.
Definition c1.hpp:84
Storage implementation of C1 Lie group.
Definition c1.hpp:146
C1(const std::complex< Scalar > &c)
Construct from complex number.
Definition c1.hpp:170
C1(const Scalar &scaling, const Scalar &angle)
Construct from scaling and angle.
Definition c1.hpp:157
Base class for Lie group types.
typename traits::Scalar Scalar
Scalar type.
Matrix matrix() const noexcept
Return as matrix Lie group element in .
Eigen::Matrix< Scalar, Dim, Dim > Matrix
Lie group matrix type.
Memory mapping of internal Lie group types.
Storage implementation of SO2 Lie group.
Definition so2.hpp:190
typename traits::man< M >::Scalar Scalar
Manifold scalar type.
Definition manifold.hpp:88
typename traits::man< M >::PlainObject PlainObject
Manifold default type.
Definition manifold.hpp:94
Type trait that maps a type to Lie group operations.