31 #ifndef TOON_INCLUDE_SE2_H 32 #define TOON_INCLUDE_SE2_H 49 template <
typename Precision = DefaultPrecision>
53 SE2() : my_translation(Zeros) {}
69 template <
int S,
typename P,
typename A>
81 return SE2(rinv, -(rinv*my_translation));
117 template<
typename Accessor>
121 result.template slice<0,2>() = my_rotation * vect.template slice<0,2>();
122 result[0] += vect[2] * my_translation[1];
123 result[1] -= vect[2] * my_translation[0];
127 template <
typename Accessor>
130 for(
int i=0; i<3; ++i)
131 result.T()[i] =
adjoint(M.T()[i]);
132 for(
int i=0; i<3; ++i)
133 result[i] =
adjoint(result[i]);
144 template <
class Precision>
145 inline std::ostream& operator<<(std::ostream& os, const SE2<Precision> & rhs){
146 std::streamsize fw = os.width();
147 for(
int i=0; i<2; i++){
149 os << rhs.get_rotation().get_matrix()[i];
151 os << rhs.get_translation()[i] <<
'\n';
158 template <
class Precision>
160 for(
int i=0; i<2; i++)
173 template<
int S,
typename P,
typename PV,
typename A>
177 template<
int S,
typename P,
typename PV,
typename A>
184 template <
int S0,
typename P0,
typename A0>
187 res.template slice<0,2>()=lhs.get_rotation()*rhs.template slice<0,2>();
188 res.template slice<0,2>()+=lhs.get_translation() * rhs[2];
191 int size()
const {
return 3; }
196 template<
int S,
typename P,
typename PV,
typename A>
203 template <
typename P,
typename PV,
typename A>
214 template<
int S,
typename P,
typename PV,
typename A>
218 template<
int S,
typename P,
typename PV,
typename A>
225 template <
int S0,
typename P0,
typename A0>
228 res.template slice<0,2>() = lhs.template slice<0,2>()*rhs.
get_rotation();
232 int size()
const {
return 3; }
237 template<
int S,
typename P,
typename PV,
typename A>
248 template <
int R,
int C,
typename PM,
typename A,
typename P>
252 template<
int R,
int Cols,
typename PM,
typename A,
typename P>
253 struct Operator<Internal::SE2MMult<R, Cols, PM, A, P> > {
259 template <
int R0,
int C0,
typename P0,
typename A0>
262 for(
int i=0; i<rhs.num_cols(); ++i)
263 res.T()[i] = lhs * rhs.T()[i];
265 int num_cols()
const {
return rhs.num_cols(); }
266 int num_rows()
const {
return 3; }
271 template <
int R,
int Cols,
typename PM,
typename A,
typename P>
282 template <
int Rows,
int C,
typename PM,
typename A,
typename P>
286 template<
int Rows,
int C,
typename PM,
typename A,
typename P>
287 struct Operator<Internal::MSE2Mult<Rows, C, PM, A, P> > {
293 template <
int R0,
int C0,
typename P0,
typename A0>
296 for(
int i=0; i<lhs.num_rows(); ++i)
297 res[i] = lhs[i] * rhs;
299 int num_cols()
const {
return 3; }
300 int num_rows()
const {
return lhs.num_rows(); }
305 template <
int Rows,
int C,
typename PM,
typename A,
typename P>
310 template <
typename Precision>
311 template <
int S,
typename PV,
typename Accessor>
316 static const Precision one_6th = 1.0/6.0;
317 static const Precision one_20th = 1.0/20.0;
321 const Precision theta = mu[2];
322 const Precision theta_sq = theta * theta;
327 if (theta_sq < 1e-8){
331 if (theta_sq < 1e-6) {
332 A = 1.0 - theta_sq * one_6th*(1.0 - one_20th * theta_sq);
333 B = 0.5 - 0.25 * one_6th * theta_sq;
335 const Precision inv_theta = (1.0/theta);
336 const Precision sine = result.my_rotation.get_matrix()[1][0];
337 const Precision cosine = result.my_rotation.get_matrix()[0][0];
338 A = sine * inv_theta;
339 B = (1 - cosine) * (inv_theta * inv_theta);
341 result.
get_translation() = TooN::operator*(A,mu.template slice<0,2>()) + TooN::operator*(B,cross);
346 template <
typename Precision>
350 Precision shtot = 0.5;
351 if(fabs(theta) > 0.00001)
352 shtot = sin(theta/2)/theta;
356 result.template slice<0,2>() = (halfrotator * se2.
get_translation())/(2 * shtot);
364 template <
typename Precision>
SE2< Precision > operator*(const SO2< Precision > &lhs, const SE2< Precision > &rhs)
Multiply a SO2 with and SE2.
Definition: se2.h:365
SE2< typename Internal::MultiplyType< Precision, P >::type > operator*(const SE2< P > &rhs) const
Right-multiply by another SE2 (concatenate the two transformations)
Definition: se2.h:87
Vector< 3, Precision > ln() const
Definition: se2.h:76
std::istream & operator>>(std::istream &is, SE2< Precision > &rhs)
Read an SE2 from a stream.
Definition: se2.h:159
Pretty generic SFINAE introspection generator.
Definition: vec_test.cc:21
A vector.
Definition: vector.hh:126
Vector< 3, typename Internal::MultiplyType< PV, P >::type > operator*(const Vector< S, PV, A > &lhs, const SE2< P > &rhs)
Left-multiply with a Vector<3>
Definition: se2.h:238
Class to represent a two-dimensional rotation matrix.
Definition: so2.h:37
static SO2 exp(const Precision &d)
Exponentiate an angle in the Lie algebra to generate a new SO2.
Definition: so2.h:89
Matrix< Rows, 3, typename Internal::MultiplyType< PM, P >::type > operator*(const Matrix< Rows, C, PM, A > &lhs, const SE2< P > &rhs)
Left-multiply with a Matrix<3>
Definition: se2.h:306
Vector< 3, Precision > adjoint(const Vector< 3, Precision, Accessor > &vect) const
transfers a vector in the Lie algebra, from one coord frame to another so that exp(adjoint(vect)) = (...
Definition: se2.h:118
Definition: operators.hh:119
Vector< 2, typename Internal::MultiplyType< P, PV >::type > operator*(const SE2< P > &lhs, const Vector< 2, PV, A > &rhs)
Right-multiply with a Vector<2> (special case, extended to be a homogeneous vector) ...
Definition: se2.h:204
const SO2< Precision > & get_rotation() const
Definition: se2.h:60
SE2 inverse() const
compute the inverse of the transformation
Definition: se2.h:79
Vector< 3, typename Internal::MultiplyType< P, PV >::type > operator*(const SE2< P > &lhs, const Vector< S, PV, A > &rhs)
Right-multiply with a Vector<3>
Definition: se2.h:197
Matrix< 3, Cols, typename Internal::MultiplyType< P, PM >::type > operator*(const SE2< P > &lhs, const Matrix< R, Cols, PM, A > &rhs)
Right-multiply with a Matrix<3>
Definition: se2.h:272
const Vector< 2, Precision > & get_translation() const
Definition: se2.h:64
static Matrix< 3, 3, Precision > generator(int i)
returns the generators for the Lie group.
Definition: se2.h:104
static SE2 exp(const Vector< S, P, A > &vect)
Exponentiate a Vector in the Lie Algebra to generate a new SE2.
Definition: size_mismatch.hh:103
Vector< 2, Precision > & get_translation()
Returns the translation part of the transformation as a Vector.
Definition: se2.h:62
Represent a two-dimensional Euclidean transformation (a rotation and a translation).
Definition: se2.h:50
SE2()
Default constructor. Initialises the the rotation to zero (the identity) and the translation to zero...
Definition: se2.h:53
SO2< Precision > & get_rotation()
Returns the rotation part of the transformation as a SO2.
Definition: se2.h:58
SE2 & operator*=(const SE2< P > &rhs)
Self right-multiply by another SE2 (concatenate the two transformations)
Definition: se2.h:94