Program Listing for File Polygon.hpp
↰ Return to documentation for file (include/grid_map_core/Polygon.hpp
)
/*
* Polygon.hpp
*
* Created on: Nov 7, 2014
* Author: Péter Fankhauser
* Institute: ETH Zurich, ANYbotics
*/
#ifndef GRID_MAP_CORE__POLYGON_HPP_
#define GRID_MAP_CORE__POLYGON_HPP_
// Eigen
#include <Eigen/Core>
#include <grid_map_core/TypeDefs.hpp>
// STD
#include <string>
#include <vector>
namespace grid_map
{
class Polygon
{
public:
enum class TriangulationMethods
{
FAN // Fan triangulation (only for convex polygons).
};
Polygon();
explicit Polygon(std::vector<Position> vertices);
virtual ~Polygon() = default;
bool isInside(const Position & point) const;
void addVertex(const Position & vertex);
const Position & getVertex(const size_t index) const;
void removeVertices();
const Position & operator[](const size_t index) const;
const std::vector<Position> & getVertices() const;
size_t nVertices() const;
void setTimestamp(const uint64_t timestamp);
uint64_t getTimestamp() const;
void resetTimestamp();
void setFrameId(const std::string & frameId);
const std::string & getFrameId() const;
double getArea() const;
Position getCentroid() const;
void getBoundingBox(Position & center, Length & length) const;
bool convertToInequalityConstraints(
Eigen::MatrixXd & A,
Eigen::VectorXd & b) const;
bool offsetInward(const double margin);
bool thickenLine(const double thickness);
std::vector<Polygon> triangulate(
const TriangulationMethods & method =
TriangulationMethods::FAN) const;
static Polygon fromCircle(
const Position center, const double radius,
const int nVertices = 20);
static Polygon convexHullOfTwoCircles(
const Position center1,
const Position center2,
const double radius,
const int nVertices = 20);
static Polygon convexHull(Polygon & polygon1, Polygon & polygon2);
static Polygon monotoneChainConvexHullOfPoints(const std::vector<Position> & points);
protected:
static bool sortVertices(
const Eigen::Vector2d & vector1,
const Eigen::Vector2d & vector2);
static double computeCrossProduct2D(
const Eigen::Vector2d & vector1,
const Eigen::Vector2d & vector2);
static double vectorsMakeClockwiseTurn(
const Eigen::Vector2d & pointO,
const Eigen::Vector2d & pointA,
const Eigen::Vector2d & pointB);
std::string frameId_;
uint64_t timestamp_;
std::vector<Position> vertices_;
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};
} // namespace grid_map
#endif // GRID_MAP_CORE__POLYGON_HPP_