gtsam  3.2.1
gtsam
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Point2.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
18 #pragma once
19 
20 #include <boost/serialization/nvp.hpp>
21 
22 #include <gtsam/base/DerivedValue.h>
23 #include <gtsam/base/Matrix.h>
24 #include <gtsam/base/Lie.h>
25 
26 namespace gtsam {
27 
35 class GTSAM_EXPORT Point2 : public DerivedValue<Point2> {
36 public:
38  static const size_t dimension = 2;
39 private:
40  double x_, y_;
41 
42 public:
43 
46 
48  Point2(): x_(0), y_(0) {}
49 
51  Point2(double x, double y): x_(x), y_(y) {}
52 
56 
58  Point2(const Vector& v) {
59  if(v.size() != 2)
60  throw std::invalid_argument("Point2 constructor from Vector requires that the Vector have dimension 2");
61  x_ = v(0);
62  y_ = v(1);
63  }
64 
65  /*
66  * @brief Circle-circle intersection, given normalized radii.
67  * Calculate f and h, respectively the parallel and perpendicular distance of
68  * the intersections of two circles along and from the line connecting the centers.
69  * Both are dimensionless fractions of the distance d between the circle centers.
70  * If the circles do not intersect or they are identical, returns boost::none.
71  * If one solution (touching circles, as determined by tol), h will be exactly zero.
72  * h is a good measure for how accurate the intersection will be, as when circles touch
73  * or nearly touch, the intersection is ill-defined with noisy radius measurements.
74  * @param R_d : R/d, ratio of radius of first circle to distance between centers
75  * @param r_d : r/d, ratio of radius of second circle to distance between centers
76  * @param tol: absolute tolerance below which we consider touching circles
77  * @return optional Point2 with f and h, boost::none if no solution.
78  */
79  static boost::optional<Point2> CircleCircleIntersection(double R_d, double r_d,
80  double tol = 1e-9);
81 
82  /*
83  * @brief Circle-circle intersection, from the normalized radii solution.
84  * @param c1 center of first circle
85  * @param c2 center of second circle
86  * @return list of solutions (0,1, or 2). Identical circles will return empty list, as well.
87  */
88  static std::list<Point2> CircleCircleIntersection(Point2 c1, Point2 c2, boost::optional<Point2>);
89 
99  static std::list<Point2> CircleCircleIntersection(Point2 c1, double r1,
100  Point2 c2, double r2, double tol = 1e-9);
101 
105 
107  void print(const std::string& s = "") const;
108 
110  bool equals(const Point2& q, double tol = 1e-9) const;
111 
115 
117  inline static Point2 identity() {
118  return Point2();
119  }
120 
122  inline Point2 inverse() const { return Point2(-x_, -y_); }
123 
125  inline Point2 operator- () const {return Point2(-x_,-y_);}
126 
128  inline Point2 compose(const Point2& q,
129  boost::optional<Matrix&> H1=boost::none,
130  boost::optional<Matrix&> H2=boost::none) const {
131  if(H1) *H1 = eye(2);
132  if(H2) *H2 = eye(2);
133  return *this + q;
134  }
135 
137  inline Point2 operator + (const Point2& q) const {return Point2(x_+q.x_,y_+q.y_);}
138 
140  inline Point2 between(const Point2& q,
141  boost::optional<Matrix&> H1=boost::none,
142  boost::optional<Matrix&> H2=boost::none) const {
143  if(H1) *H1 = -eye(2);
144  if(H2) *H2 = eye(2);
145  return q - (*this);
146  }
147 
149  inline Point2 operator - (const Point2& q) const {return Point2(x_-q.x_,y_-q.y_);}
150 
154 
156  inline static size_t Dim() { return dimension; }
157 
159  inline size_t dim() const { return dimension; }
160 
162  inline Point2 retract(const Vector& v) const { return *this + Point2(v); }
163 
165  inline Vector localCoordinates(const Point2& t2) const { return Logmap(between(t2)); }
166 
170 
172  static inline Point2 Expmap(const Vector& v) { return Point2(v); }
173 
175  static inline Vector Logmap(const Point2& dp) { return (Vector(2) << dp.x(), dp.y()); }
176 
180 
182  Point2 unit() const { return *this/norm(); }
183 
185  double norm(boost::optional<Matrix&> H = boost::none) const;
186 
188  double distance(const Point2& p2, boost::optional<Matrix&> H1 = boost::none,
189  boost::optional<Matrix&> H2 = boost::none) const;
190 
192  inline double dist(const Point2& p2) const {
193  return (p2 - *this).norm();
194  }
195 
197  inline Point2 operator * (double s) const {return Point2(x_*s,y_*s);}
198 
200  inline Point2 operator / (double q) const {return Point2(x_/q,y_/q);}
201 
205 
207  inline bool operator ==(const Point2& q) const {return x_==q.x_ && q.y_==q.y_;}
208 
210  double x() const {return x_;}
211 
213  double y() const {return y_;}
214 
216  Vector2 vector() const { return Vector2(x_, y_); }
217 
221  inline void operator += (const Point2& q) {x_+=q.x_;y_+=q.y_;}
222  inline void operator *= (double s) {x_*=s;y_*=s;}
224 
226  GTSAM_EXPORT friend std::ostream &operator<<(std::ostream &os, const Point2& p);
227 
228 private:
229 
232 
234  friend class boost::serialization::access;
235  template<class ARCHIVE>
236  void serialize(ARCHIVE & ar, const unsigned int version)
237  {
238  ar & boost::serialization::make_nvp("Point2",
239  boost::serialization::base_object<Value>(*this));
240  ar & BOOST_SERIALIZATION_NVP(x_);
241  ar & BOOST_SERIALIZATION_NVP(y_);
242  }
243 
245 
246 };
247 
249 inline Point2 operator*(double s, const Point2& p) {return p*s;}
250 
251 }
252 
Point2()
default constructor
Definition: Point2.h:48
Point2(double x, double y)
construct from doubles
Definition: Point2.h:51
Point2 unit() const
creates a unit vector
Definition: Point2.h:182
Base class and basic functions for Lie types.
Matrix eye(size_t m, size_t n)
Creates an identity matrix, with matlab-like syntax.
Definition: Matrix.cpp:50
Definition: Point2.h:35
static Vector Logmap(const Point2 &dp)
Log map around identity - just return the Point2 as a vector.
Definition: Point2.h:175
Point2 retract(const Vector &v) const
Updates a with tangent space delta.
Definition: Point2.h:162
Point2 between(const Point2 &q, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none) const
"Between", subtracts point coordinates. between(p,q) == compose(inverse(p),q)
Definition: Point2.h:140
Vector2 vector() const
return vectorized form (column-wise). TODO: why does this function exist?
Definition: Point2.h:216
Point2 operator*(double s, const Point2 &p)
multiply with scalar
Definition: Point2.h:249
Vector localCoordinates(const Point2 &t2) const
Local coordinates of manifold neighborhood around current value.
Definition: Point2.h:165
bool operator==(const Matrix &A, const Matrix &B)
equality is just equal_with_abs_tol 1e-9
Definition: Matrix.h:104
void print(const Matrix &A, const string &s, ostream &stream)
print a matrix
Definition: Matrix.cpp:183
static Point2 Expmap(const Vector &v)
Exponential map around identity - just create a Point2 from a vector.
Definition: Point2.h:172
Template to create a binary predicate.
Definition: Testable.h:102
Point2(const Vector &v)
construct from 2D vector
Definition: Point2.h:58
double y() const
get y
Definition: Point2.h:213
size_t dim() const
Dimensionality of tangent space = 2 DOF.
Definition: Point2.h:159
double dist(const Point2 &p2) const
Definition: Point2.h:192
typedef and functions to augment Eigen's MatrixXd
double x() const
get x
Definition: Point2.h:210
static size_t Dim()
dimension of the variable - used to autodetect sizes
Definition: Point2.h:156
static Point2 identity()
identity
Definition: Point2.h:117
Definition: DerivedValue.h:44
Point2 inverse() const
"Inverse" - negates each coordinate such that compose(p,inverse(p)) == identity() ...
Definition: Point2.h:122
Point2 compose(const Point2 &q, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none) const
"Compose", just adds the coordinates of two points. With optional derivatives
Definition: Point2.h:128