se2.h
Go to the documentation of this file.
1 // g2o - General Graph Optimization
2 // Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 
27 #pragma once
28 
29 #include "../eigen/Eigen/Core"
30 #include "../eigen/Eigen/Geometry"
31 
32 const double empty_angle = 9;
33 
34 inline double normalize_theta(double theta)
35 {
36  if (theta >= -M_PI && theta < M_PI)
37  return theta;
38  double multiplier = floor(theta / (2*M_PI));
39  theta = theta - multiplier*2*M_PI;
40  if (theta >= M_PI)
41  theta -= 2*M_PI;
42  if (theta < -M_PI)
43  theta += 2*M_PI;
44  return theta;
45 }
46 
47 namespace iro
48 {
49  class SE2
50  {
51  public:
53  SE2() :_R(0), _t(0, 0){}
54 
55  SE2(double x, double y, double theta) :_R(theta), _t(x, y){}
56 
57  //SE2(double x, double y, double theta) :_R(normalize_theta(theta)), _t(x, y){}
58 
59  const Eigen::Vector2d& translation() const { return _t; }
60 
61  Eigen::Vector2d& translation() { return _t; }
62 
63  const Eigen::Rotation2Dd& rotation() const { return _R; }
64 
66 
67  SE2 operator * (const SE2& tr2) const
68  {
69  SE2 result(*this);
70  result._t += _R*tr2._t;
71  result._R.angle() += tr2._R.angle();
72  result._R.angle() = normalize_theta(result._R.angle());
73  return result;
74  }
75 
76  SE2& operator *= (const SE2& tr2)
77  {
78  _t += _R*tr2._t;
79  _R.angle() += tr2._R.angle();
81  return *this;
82  }
83 
84  Eigen::Vector2d operator * (const Eigen::Vector2d& v) const
85  {
86  return _t + _R*v;
87  }
88 
89  SE2 inverse() const
90  {
91  SE2 ret;
92  ret._R = _R.inverse();
93  ret._R.angle() = normalize_theta(ret._R.angle());
94  ret._t = ret._R*(Eigen::Vector2d(-1 * _t));
95  return ret;
96  }
97 
98  double operator [](int i) const
99  {
100  assert(i >= 0 && i < 3);
101  if (i < 2)
102  return _t(i);
103  return _R.angle();
104  }
105 
106  double& operator [](int i)
107  {
108  assert(i >= 0 && i < 3);
109  if (i < 2)
110  return _t(i);
111  return _R.angle();
112  }
113 
114  void fromVector(const Eigen::Vector3d& v)
115  {
116  *this = SE2(v[0], v[1], v[2]);
117  }
118 
119  Eigen::Vector3d toVector() const
120  {
121  Eigen::Vector3d ret;
122  for (int i = 0; i < 3; i++){
123  ret(i) = (*this)[i];
124  }
125  return ret;
126  }
127 
128  protected:
130  Eigen::Vector2d _t;
131  };
132 
133 } // end namespace
134 
135 /*
136 // check se2 equal
137 bool se2_equal(iro::SE2 p1, iro::SE2 p2)
138 {
139  Eigen::Vector3d pose1(p1.translation().x(), p1.translation().y(), p1.rotation().angle());
140  Eigen::Vector3d pose2(p2.translation().x(), p2.translation().y(), p2.rotation().angle());
141  if ((pose1 - pose2).norm() < 0.00001)
142  return true;
143  return false;
144 }
145 //*/
Eigen::Vector2d _t
Definition: se2.h:130
Eigen::Rotation2Dd _R
Definition: se2.h:129
const Eigen::Rotation2Dd & rotation() const
Definition: se2.h:63
SE2 & operator*=(const SE2 &tr2)
Definition: se2.h:76
EIGEN_DEVICE_FUNC const FloorReturnType floor() const
void fromVector(const Eigen::Vector3d &v)
Definition: se2.h:114
Eigen::Vector2d & translation()
Definition: se2.h:61
SE2 inverse() const
Definition: se2.h:89
double operator[](int i) const
Definition: se2.h:98
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
Definition: se2.h:52
EIGEN_DEVICE_FUNC Rotation2D inverse() const
Definition: Rotation2D.h:98
Definition: se2.h:47
SE2 operator*(const SE2 &tr2) const
Definition: se2.h:67
Eigen::Rotation2Dd & rotation()
Definition: se2.h:65
SE2()
Definition: se2.h:53
Represents a rotation/orientation in a 2 dimensional space.
Definition: se2.h:49
SE2(double x, double y, double theta)
Definition: se2.h:55
const double empty_angle
Definition: se2.h:32
EIGEN_DEVICE_FUNC Scalar angle() const
Definition: Rotation2D.h:78
Eigen::Vector3d toVector() const
Definition: se2.h:119
const Eigen::Vector2d & translation() const
Definition: se2.h:59
double normalize_theta(double theta)
Definition: se2.h:34


co_scan
Author(s):
autogenerated on Mon Feb 28 2022 23:00:48