smooth
A C++ library for Lie theory
Loading...
Searching...
No Matches
galilei.hpp
1// Copyright (C) 2021-2022 Petter Nilsson. MIT License.
2
3#pragma once
4
5#include <Eigen/Core>
6#include <Eigen/Geometry>
7
8#include "detail/galilei.hpp"
9#include "detail/macro.hpp"
10#include "lie_group_base.hpp"
11#include "so3.hpp"
12
13SMOOTH_BEGIN_NAMESPACE
14
62template<typename _Derived>
63class GalileiBase : public LieGroupBase<_Derived>
64{
66
67protected:
68 GalileiBase() = default;
69
70public:
71 SMOOTH_INHERIT_TYPEDEFS;
72
77 requires is_mutable
78 {
79 return Map<SO3<Scalar>>(static_cast<_Derived &>(*this).data() + 7);
80 }
81
85 Map<const SO3<Scalar>> so3() const { return Map<const SO3<Scalar>>(static_cast<const _Derived &>(*this).data() + 7); }
86
90 Eigen::Map<Eigen::Vector3<Scalar>> r3_v()
91 requires is_mutable
92 {
93 return Eigen::Map<Eigen::Vector3<Scalar>>(static_cast<_Derived &>(*this).data() + 0);
94 }
95
99 Eigen::Map<const Eigen::Vector3<Scalar>> r3_v() const
100 {
101 return Eigen::Map<const Eigen::Vector3<Scalar>>(static_cast<const _Derived &>(*this).data() + 0);
102 }
103
107 Eigen::Map<Eigen::Vector3<Scalar>> r3_p()
108 requires is_mutable
109 {
110 return Eigen::Map<Eigen::Vector3<Scalar>>(static_cast<_Derived &>(*this).data() + 3);
111 }
112
116 Eigen::Map<const Eigen::Vector3<Scalar>> r3_p() const
117 {
118 return Eigen::Map<const Eigen::Vector3<Scalar>>(static_cast<const _Derived &>(*this).data() + 3);
119 }
120
124 Eigen::Map<Eigen::Vector<Scalar, 1>> r1_t()
125 requires is_mutable
126 {
127 return Eigen::Map<Eigen::Vector<Scalar, 1>>(static_cast<_Derived &>(*this).data() + 6);
128 }
129
133 Eigen::Map<const Eigen::Vector<Scalar, 1>> r1_t() const
134 {
135 return Eigen::Map<const Eigen::Vector<Scalar, 1>>(static_cast<const _Derived &>(*this).data() + 6);
136 }
137
143 template<typename EigenDerived>
144 Eigen::Vector4<Scalar> operator*(const Eigen::MatrixBase<EigenDerived> & v) const
145 {
146 Eigen::Vector4<Scalar> ret;
147 ret.template segment<3>(0) = so3() * v.template segment<3>(0) + r3_v() * v(3) + r3_p();
148 ret(3) = v(3) + r1_t().x();
149 return ret;
150 }
151
159 template<typename EigenDerived>
160 Eigen::Matrix<Scalar, 4, 10> dr_action(const Eigen::MatrixBase<EigenDerived> & v) const
161 {
162 Eigen::Matrix<Scalar, 4, 10> ret = Eigen::Matrix<Scalar, 4, 10>::Zero();
163
164 // v transformation
165 ret.template block<3, 3>(0, 0) = v(3) * so3().matrix();
166 ret.template block<3, 3>(0, 3) = so3().matrix();
167 ret.template block<3, 1>(0, 6) = r3_v();
168 ret.template block<3, 3>(0, 7) = so3().dr_action(v.template segment<3>(0));
169
170 // t transformation
171 ret(3, 6) = 1;
172
173 return ret;
174 }
175};
176
177// \cond
178template<typename _Scalar>
179class Galilei;
180// \endcond
181
182// \cond
183template<typename _Scalar>
184struct liebase_info<Galilei<_Scalar>>
185{
186 static constexpr bool is_mutable = true;
187
188 using Impl = GalileiImpl<_Scalar>;
189 using Scalar = _Scalar;
190
191 template<typename NewScalar>
193};
194// \endcond
195
201template<typename _Scalar>
202class Galilei : public GalileiBase<Galilei<_Scalar>>
203{
205
206 SMOOTH_GROUP_API(Galilei);
207
208public:
217 template<typename SO3Derived, typename T1, typename T2>
219 const SO3Base<SO3Derived> & so3,
220 const Eigen::MatrixBase<T1> & r3_v,
221 const Eigen::MatrixBase<T2> & r3_p,
222 double r1_t = 0)
223 {
224 Base::so3() = static_cast<const SO3Derived &>(so3);
225 Base::r3_v() = static_cast<const T1 &>(r3_v);
226 Base::r3_p() = static_cast<const T2 &>(r3_p);
227 Base::r1_t().x() = r1_t;
228 }
229};
230
231// \cond
232template<typename _Scalar>
233struct liebase_info<Map<Galilei<_Scalar>>> : public liebase_info<Galilei<_Scalar>>
234{};
235// \endcond
236
242template<typename _Scalar>
243class Map<Galilei<_Scalar>> : public GalileiBase<Map<Galilei<_Scalar>>>
244{
246
247 SMOOTH_MAP_API();
248};
249
250// \cond
251template<typename _Scalar>
252struct liebase_info<Map<const Galilei<_Scalar>>> : public liebase_info<Galilei<_Scalar>>
253{
254 static constexpr bool is_mutable = false;
255};
256// \endcond
257
263template<typename _Scalar>
264class Map<const Galilei<_Scalar>> : public GalileiBase<Map<const Galilei<_Scalar>>>
265{
267
268 SMOOTH_CONST_MAP_API();
269};
270
271using Galileif = Galilei<float>;
273
274SMOOTH_END_NAMESPACE
Base class for Galielei Lie group types.
Definition galilei.hpp:64
Eigen::Map< Eigen::Vector< Scalar, 1 > > r1_t()
Access R1 time part.
Definition galilei.hpp:124
Eigen::Map< Eigen::Vector3< Scalar > > r3_v()
Access R3 velocity part.
Definition galilei.hpp:90
Eigen::Map< const Eigen::Vector< Scalar, 1 > > r1_t() const
Const access R1 time part.
Definition galilei.hpp:133
Map< SO3< Scalar > > so3()
Access SO(3) part.
Definition galilei.hpp:76
Map< const SO3< Scalar > > so3() const
Const access SO(3) part.
Definition galilei.hpp:85
Eigen::Map< Eigen::Vector3< Scalar > > r3_p()
Access R3 position part.
Definition galilei.hpp:107
Eigen::Map< const Eigen::Vector3< Scalar > > r3_v() const
Const access R3 velocity part.
Definition galilei.hpp:99
Eigen::Vector4< Scalar > operator*(const Eigen::MatrixBase< EigenDerived > &v) const
Tranformation action on (x, y, z, t) space-time vector.
Definition galilei.hpp:144
Eigen::Map< const Eigen::Vector3< Scalar > > r3_p() const
Const access R3 position part.
Definition galilei.hpp:116
Eigen::Matrix< Scalar, 4, 10 > dr_action(const Eigen::MatrixBase< EigenDerived > &v) const
Jacobian of rotation action w.r.t. group.
Definition galilei.hpp:160
Storage implementation of Galilei Lie group.
Definition galilei.hpp:203
Galilei(const SO3Base< SO3Derived > &so3, const Eigen::MatrixBase< T1 > &r3_v, const Eigen::MatrixBase< T2 > &r3_p, double r1_t=0)
Construct from SO3 and translation.
Definition galilei.hpp:218
Base class for Lie group types.
static constexpr bool is_mutable
True if underlying storage supports modification.
Eigen::Matrix< Scalar, Dim, Dim > Matrix
Lie group matrix type.
Memory mapping of internal Lie group types.
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.