LocalGuidance
A library that generates velocity references to follow a path.
robot_utils::geometry::Polygon Class Reference

#include <Polygon.hpp>

Inheritance diagram for robot_utils::geometry::Polygon:
Inheritance graph

Public Types

using VertexList = std::vector< Eigen::Vector2d, Eigen::aligned_allocator< Eigen::Vector2d >>
 
using LineCoefficientList = std::vector< std::vector< double >>
 

Public Member Functions

 Polygon ()
 
 Polygon (const VertexList &vertices, robot_utils::geometry::VertexOrder vertexOrder=robot_utils::geometry::VertexOrder::Undefined)
 
 Polygon (VertexList &&vertices, robot_utils::geometry::VertexOrder vertexOrder=robot_utils::geometry::VertexOrder::Undefined)
 
 Polygon (const Position2d &vertexCenter, unsigned int numOfVertices, double polygonSize)
 
 Polygon (const Position2d &vertexCenter, unsigned int numOfVertices, double polygonSize, const Eigen::Matrix2d &RotationMatrix2d)
 
 Polygon (const Polygon &polygon)
 
 Polygon (Polygon &&rhs)=default
 
Polygonoperator= (const Polygon &rhs)
 
Polygonoperator= (Polygon &&rhs)=default
 
virtual ~Polygon ()=default
 
virtual double getArea () const
 Get the area of the polygon (is negative if order is clock wise). More...
 
double getPerimeter () const
 Get the perimeter of the polygon. More...
 
size_t getNumVertices () const
 Get the number of vertices. More...
 
void setVertex (const Position2d &vertex, unsigned int vertexId)
 Copy a vertex to the vertex list at a specific index. More...
 
const Position2dgetVertex (unsigned int vertexId) const
 Copy a vertex to the vertex list at a specific index. More...
 
void pushVertex (const Position2d &vertex)
 Add a vertex to the vertex list. More...
 
bool reorderVertices (VertexOrder vertexOrder)
 Reorder the vertices in clockwise or counter-clockwise order. More...
 
VertexOrder getVertexOrder () const
 Get the order in which the vertices are stored. More...
 
virtual bool updateLineCoefficients ()
 Compute the line coefficients of all edges of the polygon. More...
 
const LineCoefficientListgetLineCoefficients () const
 Get the set of line coefficients of all edges of the polygon. More...
 
const VertexListgetVertices () const
 Get the set of vertices. More...
 
virtual bool isPointInPolygon (const Position2d &point, double tol=1e-6) const
 Check if a point is in the polygon. More...
 
bool resizePolygonTowardsInCenter (double lengthLineToLine)
 The edges of the polygon are moved with towards the incenter with a certain distance. More...
 
bool resizeVerticesTowardsCentroid (double percent)
 The polygon center is defined to be the centroid (average of all vertices). Vertices are. More...
 
bool resizeAreaTriangleBased (double percent)
 For each polygon, we extract one (random) triangle and move its vertices towards the incenter. More...
 
void resetVertices (unsigned int numOfVertices=0u)
 Emtpy the vertex list. More...
 
void print () const
 Print information about the polygon. More...
 
bool computePolygonCentroid (Eigen::Vector2d &center) const
 Compute centroid (polygon center). More...
 

Static Public Member Functions

static bool doPolygonsIntersect (const Polygon &polygonA, const Polygon &polygonB)
 
static void projectPolygonToRange (const Polygon &polygon, const Position2d &axisDirection, Eigen::Vector2d &range)
 Project the vertices of a polygon to a scalar range directed along an axis. More...
 
static bool doRangesOverlap (const Position2d &rangeA, const Position2d &rangeB)
 Check if two scalar ranges A = {a, b} and B = {c, d} overlap. More...
 

Protected Attributes

VertexList vertices_
 A list of vertices. More...
 
robot_utils::geometry::VertexOrder vertexOrder_
 The order in which the vertices are stored. More...
 
LineCoefficientList lineCoefficients_
 The set of coefficients of the edges of the polygon. More...
 

Member Typedef Documentation

using robot_utils::geometry::Polygon::LineCoefficientList = std::vector<std::vector<double>>
using robot_utils::geometry::Polygon::VertexList = std::vector<Eigen::Vector2d, Eigen::aligned_allocator<Eigen::Vector2d>>

Constructor & Destructor Documentation

robot_utils::geometry::Polygon::Polygon ( )
robot_utils::geometry::Polygon::Polygon ( const VertexList vertices,
robot_utils::geometry::VertexOrder  vertexOrder = robot_utils::geometry::VertexOrder::Undefined 
)
explicit
robot_utils::geometry::Polygon::Polygon ( VertexList &&  vertices,
robot_utils::geometry::VertexOrder  vertexOrder = robot_utils::geometry::VertexOrder::Undefined 
)
explicit
robot_utils::geometry::Polygon::Polygon ( const Position2d vertexCenter,
unsigned int  numOfVertices,
double  polygonSize 
)
robot_utils::geometry::Polygon::Polygon ( const Position2d vertexCenter,
unsigned int  numOfVertices,
double  polygonSize,
const Eigen::Matrix2d &  RotationMatrix2d 
)
robot_utils::geometry::Polygon::Polygon ( const Polygon polygon)
robot_utils::geometry::Polygon::Polygon ( Polygon &&  rhs)
default
virtual robot_utils::geometry::Polygon::~Polygon ( )
virtualdefault

Member Function Documentation

bool robot_utils::geometry::Polygon::computePolygonCentroid ( Eigen::Vector2d &  center) const

Compute centroid (polygon center).

static bool robot_utils::geometry::Polygon::doPolygonsIntersect ( const Polygon polygonA,
const Polygon polygonB 
)
static

Find whether two polygons intersect. This method assumes that both polygons have been reordered either clockwise or counterclockwise. This is an implementation of the SAT algorithm

static bool robot_utils::geometry::Polygon::doRangesOverlap ( const Position2d rangeA,
const Position2d rangeB 
)
static

Check if two scalar ranges A = {a, b} and B = {c, d} overlap.

virtual double robot_utils::geometry::Polygon::getArea ( ) const
virtual

Get the area of the polygon (is negative if order is clock wise).

Reimplemented in robot_utils::geometry::Line.

const LineCoefficientList& robot_utils::geometry::Polygon::getLineCoefficients ( ) const

Get the set of line coefficients of all edges of the polygon.

size_t robot_utils::geometry::Polygon::getNumVertices ( ) const

Get the number of vertices.

double robot_utils::geometry::Polygon::getPerimeter ( ) const

Get the perimeter of the polygon.

const Position2d& robot_utils::geometry::Polygon::getVertex ( unsigned int  vertexId) const

Copy a vertex to the vertex list at a specific index.

VertexOrder robot_utils::geometry::Polygon::getVertexOrder ( ) const

Get the order in which the vertices are stored.

const VertexList& robot_utils::geometry::Polygon::getVertices ( ) const

Get the set of vertices.

virtual bool robot_utils::geometry::Polygon::isPointInPolygon ( const Position2d point,
double  tol = 1e-6 
) const
virtual

Check if a point is in the polygon.

Reimplemented in robot_utils::geometry::Line.

Polygon& robot_utils::geometry::Polygon::operator= ( const Polygon rhs)
Polygon& robot_utils::geometry::Polygon::operator= ( Polygon &&  rhs)
default
void robot_utils::geometry::Polygon::print ( ) const

Print information about the polygon.

static void robot_utils::geometry::Polygon::projectPolygonToRange ( const Polygon polygon,
const Position2d axisDirection,
Eigen::Vector2d &  range 
)
static

Project the vertices of a polygon to a scalar range directed along an axis.

void robot_utils::geometry::Polygon::pushVertex ( const Position2d vertex)

Add a vertex to the vertex list.

bool robot_utils::geometry::Polygon::reorderVertices ( VertexOrder  vertexOrder)

Reorder the vertices in clockwise or counter-clockwise order.

void robot_utils::geometry::Polygon::resetVertices ( unsigned int  numOfVertices = 0u)

Emtpy the vertex list.

bool robot_utils::geometry::Polygon::resizeAreaTriangleBased ( double  percent)

For each polygon, we extract one (random) triangle and move its vertices towards the incenter.

bool robot_utils::geometry::Polygon::resizePolygonTowardsInCenter ( double  lengthLineToLine)

The edges of the polygon are moved with towards the incenter with a certain distance.

bool robot_utils::geometry::Polygon::resizeVerticesTowardsCentroid ( double  percent)

The polygon center is defined to be the centroid (average of all vertices). Vertices are.

void robot_utils::geometry::Polygon::setVertex ( const Position2d vertex,
unsigned int  vertexId 
)

Copy a vertex to the vertex list at a specific index.

virtual bool robot_utils::geometry::Polygon::updateLineCoefficients ( )
virtual

Compute the line coefficients of all edges of the polygon.

Reimplemented in robot_utils::geometry::Line.

Member Data Documentation

LineCoefficientList robot_utils::geometry::Polygon::lineCoefficients_
protected

The set of coefficients of the edges of the polygon.

robot_utils::geometry::VertexOrder robot_utils::geometry::Polygon::vertexOrder_
protected

The order in which the vertices are stored.

VertexList robot_utils::geometry::Polygon::vertices_
protected

A list of vertices.


The documentation for this class was generated from the following file: