geometry.cpp
Go to the documentation of this file.
1 #include "geometry.h"
2 
3 #include <boost/geometry/algorithms/assign.hpp>
4 #include <boost/geometry/algorithms/detail/distance/interface.hpp>
5 
6 #include <SimoxUtility/algorithm/apply.hpp>
7 
9 {
10 
11  float
12  computeDistance(const std::vector<polygon_type>& obstacles, const Eigen::Vector2f& pt)
13  {
14  const point_type point(pt.x(), pt.y());
15 
16  float dist = std::numeric_limits<float>::max();
17  for (const auto& obstacle : obstacles)
18  {
19  const float d = boost::geometry::distance(point, obstacle);
20  if (d < dist)
21  {
22  dist = d;
23  }
24  }
25 
26  return dist;
27  }
28 
30  toPolygon(const std::vector<Eigen::Vector2f>& hull)
31  {
32  std::vector<point_type> points = simox::alg::apply(hull, toPoint);
33  points.push_back(points.front()); // close polygon
34 
35  polygon_type polygon;
36  boost::geometry::assign_points(polygon, points);
37 
38  return polygon;
39  }
40 
42  toPoint(const Eigen::Vector2f& pt)
43  {
44  return {pt.x(), pt.y()};
45  }
46 
47 } // namespace armarx::navigation::util::geometry
armarx::navigation::util::geometry::toPolygon
polygon_type toPolygon(const std::vector< Eigen::Vector2f > &hull)
Definition: geometry.cpp:30
armarx::navigation::util::geometry::computeDistance
float computeDistance(const std::vector< polygon_type > &obstacles, const Eigen::Vector2f &pt)
Definition: geometry.cpp:12
geometry.h
armarx::navigation::util::geometry::point_type
boost::geometry::model::d2::point_xy< float > point_type
Definition: geometry.h:33
max
T max(T t1, T t2)
Definition: gdiam.h:48
armarx::navigation::util::geometry
This file is part of ArmarX.
Definition: geometry.cpp:8
armarx::navigation::util::geometry::polygon_type
boost::geometry::model::polygon< point_type > polygon_type
Definition: geometry.h:34
distance
double distance(const Point &a, const Point &b)
Definition: point.hpp:88
armarx::navigation::util::geometry::toPoint
point_type toPoint(const Eigen::Vector2f &pt)
Definition: geometry.cpp:42