geometry_tools.h
Go to the documentation of this file.
1 #ifndef GEOMETRY_TOOLS_H_
2 #define GEOMETRY_TOOLS_H_
3 
4 #include <geometry_msgs/Polygon.h>
5 #include <geometry_msgs/Point.h>
7 
8 namespace frontier_exploration{
9 
16  template<typename T, typename S>
17  double pointsDistance(const T &one, const S &two){
18  return sqrt(pow(one.x-two.x,2.0) + pow(one.y-two.y,2.0) + pow(one.z-two.z,2.0));
19  }
20 
26  double polygonPerimeter(const geometry_msgs::Polygon &polygon){
27 
28  double perimeter = 0;
29  if(polygon.points.size() > 1)
30  {
31  for (int i = 0, j = polygon.points.size() - 1; i < polygon.points.size(); j = i++)
32  {
33  perimeter += pointsDistance(polygon.points[i], polygon.points[j]);
34  }
35  }
36  return perimeter;
37  }
38 
46  template<typename T, typename S>
47  bool pointsNearby(const T &one, const S &two, const double &proximity){
48  return pointsDistance(one, two) <= proximity;
49  }
50 
57  template<typename T>
58  bool pointInPolygon(const T &point, const geometry_msgs::Polygon &polygon){
59  int cross = 0;
60  for (int i = 0, j = polygon.points.size()-1; i < polygon.points.size(); j = i++) {
61  if ( ((polygon.points[i].y > point.y) != (polygon.points[j].y>point.y)) &&
62  (point.x < (polygon.points[j].x-polygon.points[i].x) * (point.y-polygon.points[i].y) / (polygon.points[j].y-polygon.points[i].y) + polygon.points[i].x) ){
63  cross++;
64  }
65  }
66  return bool(cross % 2);
67  }
68 
75  template<typename T, typename S>
76  double yawOfVector(const T &origin, const S &end){
77 
78  double delta_x, delta_y;
79  delta_x = end.x - origin.x;
80  delta_y = end.y - origin.y;
81 
82  double yaw = atan(delta_x/delta_y);
83 
84  if(delta_x < 0){
85  yaw = M_PI-yaw;
86  }
87 
88  return yaw;
89  }
90 
91 }
92 
93 #endif
double pointsDistance(const T &one, const S &two)
Calculate distance between two points.
TFSIMD_FORCE_INLINE Vector3 cross(const Vector3 &v) const
bool pointsNearby(const T &one, const S &two, const double &proximity)
Evaluate whether two points are approximately adjacent, within a specified proximity distance...
double polygonPerimeter(const geometry_msgs::Polygon &polygon)
Calculate polygon perimeter.
double yawOfVector(const T &origin, const S &end)
Calculate the yaw of vector defined by origin and end points.
bool pointInPolygon(const T &point, const geometry_msgs::Polygon &polygon)
Evaluate if point is inside area defined by polygon. Undefined behaviour for points on line...


frontier_exploration
Author(s): Paul Bovbel
autogenerated on Mon Jun 10 2019 13:25:00