Apollo
6.0
Open source self driving car software
|
The class of polygon in 2-D. More...
#include <polygon2d.h>
Public Member Functions | |
Polygon2d ()=default | |
Empty constructor. More... | |
Polygon2d (const Box2d &box) | |
Constructor which takes a box. More... | |
Polygon2d (std::vector< Vec2d > points) | |
Constructor which takes a vector of points as its vertices. More... | |
const std::vector< Vec2d > & | points () const |
Get the vertices of the polygon. More... | |
const std::vector< LineSegment2d > & | line_segments () const |
Get the edges of the polygon. More... | |
int | num_points () const |
Get the number of vertices of the polygon. More... | |
bool | is_convex () const |
Check if the polygon is convex. More... | |
double | area () const |
Get the area of the polygon. More... | |
double | DistanceToBoundary (const Vec2d &point) const |
Compute the distance from a point to the boundary of the polygon. This distance is equal to the minimal distance from the point to the edges of the polygon. More... | |
double | DistanceTo (const Vec2d &point) const |
Compute the distance from a point to the polygon. If the point is within the polygon, return 0. Otherwise, this distance is the minimal distance from the point to the edges of the polygon. More... | |
double | DistanceTo (const LineSegment2d &line_segment) const |
Compute the distance from a line segment to the polygon. If the line segment is within the polygon, or it has intersect with the polygon, return 0. Otherwise, this distance is the minimal distance between the distances from the two ends of the line segment to the polygon. More... | |
double | DistanceTo (const Box2d &box) const |
Compute the distance from a box to the polygon. If the box is within the polygon, or it has overlap with the polygon, return 0. Otherwise, this distance is the minimal distance among the distances from the edges of the box to the polygon. More... | |
double | DistanceTo (const Polygon2d &polygon) const |
Compute the distance from another polygon to the polygon. If the other polygon is within this polygon, or it has overlap with this polygon, return 0. Otherwise, this distance is the minimal distance among the distances from the edges of the other polygon to this polygon. More... | |
double | DistanceSquareTo (const Vec2d &point) const |
Compute the square of distance from a point to the polygon. If the point is within the polygon, return 0. Otherwise, this square of distance is the minimal square of distance from the point to the edges of the polygon. More... | |
bool | IsPointIn (const Vec2d &point) const |
Check if a point is within the polygon. More... | |
bool | IsPointOnBoundary (const Vec2d &point) const |
Check if a point is on the boundary of the polygon. More... | |
bool | Contains (const LineSegment2d &line_segment) const |
Check if the polygon contains a line segment. More... | |
bool | Contains (const Polygon2d &polygon) const |
Check if the polygon contains another polygon. More... | |
bool | HasOverlap (const LineSegment2d &line_segment) const |
Check if a line segment has overlap with this polygon. More... | |
bool | GetOverlap (const LineSegment2d &line_segment, Vec2d *const first, Vec2d *const last) const |
Get the overlap of a line segment and this polygon. If they have overlap, output the two ends of the overlapped line segment. More... | |
void | GetAllVertices (std::vector< Vec2d > *const vertices) const |
Get all vertices of the polygon. More... | |
std::vector< Vec2d > | GetAllVertices () const |
Get all vertices of the polygon. More... | |
std::vector< LineSegment2d > | GetAllOverlaps (const LineSegment2d &line_segment) const |
Get all overlapped line segments of a line segment and this polygon. There are possibly multiple overlapped line segments if this polygon is not convex. More... | |
bool | HasOverlap (const Polygon2d &polygon) const |
Check if this polygon has overlap with another polygon. More... | |
bool | ComputeOverlap (const Polygon2d &other_polygon, Polygon2d *const overlap_polygon) const |
Compute the overlap of this polygon and the other polygon if any. Note: this function only works for computing overlap between two convex polygons. More... | |
double | ComputeIoU (const Polygon2d &other_polygon) const |
Compute intersection over union ratio of this polygon and the other polygon. Note: this function only works for computing overlap between two convex polygons. More... | |
AABox2d | AABoundingBox () const |
Get the axis-aligned bound box of the polygon. More... | |
Box2d | BoundingBoxWithHeading (const double heading) const |
Get the bound box according to a heading. More... | |
Box2d | MinAreaBoundingBox () const |
Get the bounding box with the minimal area. More... | |
void | ExtremePoints (const double heading, Vec2d *const first, Vec2d *const last) const |
Get the extreme points along a heading direction. More... | |
Polygon2d | ExpandByDistance (const double distance) const |
Expand this polygon by a distance. More... | |
std::string | DebugString () const |
Get a string containing essential information about the polygon for debugging purpose. More... | |
double | min_x () const |
double | max_x () const |
double | min_y () const |
double | max_y () const |
Static Public Member Functions | |
static bool | ComputeConvexHull (const std::vector< Vec2d > &points, Polygon2d *const polygon) |
Compute the convex hull of a group of points. More... | |
Protected Member Functions | |
void | BuildFromPoints () |
int | Next (int at) const |
int | Prev (int at) const |
Static Protected Member Functions | |
static bool | ClipConvexHull (const LineSegment2d &line_segment, std::vector< Vec2d > *const points) |
Protected Attributes | |
std::vector< Vec2d > | points_ |
int | num_points_ = 0 |
std::vector< LineSegment2d > | line_segments_ |
bool | is_convex_ = false |
double | area_ = 0.0 |
double | min_x_ = 0.0 |
double | max_x_ = 0.0 |
double | min_y_ = 0.0 |
double | max_y_ = 0.0 |
The class of polygon in 2-D.
|
default |
Empty constructor.
|
explicit |
Constructor which takes a box.
box | The box to construct the polygon. |
|
explicit |
Constructor which takes a vector of points as its vertices.
points | The points to construct the polygon. |
AABox2d apollo::common::math::Polygon2d::AABoundingBox | ( | ) | const |
Get the axis-aligned bound box of the polygon.
|
inline |
Get the area of the polygon.
Box2d apollo::common::math::Polygon2d::BoundingBoxWithHeading | ( | const double | heading | ) | const |
Get the bound box according to a heading.
heading | The specified heading of the bounding box. |
|
protected |
|
staticprotected |
|
static |
Compute the convex hull of a group of points.
points | The target points. To compute the convex hull of them. |
polygon | The convex hull of the points. |
double apollo::common::math::Polygon2d::ComputeIoU | ( | const Polygon2d & | other_polygon | ) | const |
Compute intersection over union ratio of this polygon and the other polygon. Note: this function only works for computing overlap between two convex polygons.
other_polygon | The target polygon. To compute its overlap with this polygon. |
bool apollo::common::math::Polygon2d::ComputeOverlap | ( | const Polygon2d & | other_polygon, |
Polygon2d *const | overlap_polygon | ||
) | const |
Compute the overlap of this polygon and the other polygon if any. Note: this function only works for computing overlap between two convex polygons.
other_polygon | The target polygon. To compute its overlap with this polygon. |
overlap_polygon | The overlapped polygon. |
If | there is an overlapped polygon. |
bool apollo::common::math::Polygon2d::Contains | ( | const LineSegment2d & | line_segment | ) | const |
Check if the polygon contains a line segment.
line_segment | The target line segment. To check if the polygon contains it. |
bool apollo::common::math::Polygon2d::Contains | ( | const Polygon2d & | polygon | ) | const |
Check if the polygon contains another polygon.
polygon | The target polygon. To check if this polygon contains it. |
std::string apollo::common::math::Polygon2d::DebugString | ( | ) | const |
Get a string containing essential information about the polygon for debugging purpose.
double apollo::common::math::Polygon2d::DistanceSquareTo | ( | const Vec2d & | point | ) | const |
Compute the square of distance from a point to the polygon. If the point is within the polygon, return 0. Otherwise, this square of distance is the minimal square of distance from the point to the edges of the polygon.
point | The point to compute whose square of distance to the polygon. |
double apollo::common::math::Polygon2d::DistanceTo | ( | const Vec2d & | point | ) | const |
Compute the distance from a point to the polygon. If the point is within the polygon, return 0. Otherwise, this distance is the minimal distance from the point to the edges of the polygon.
point | The point to compute whose distance to the polygon. |
double apollo::common::math::Polygon2d::DistanceTo | ( | const LineSegment2d & | line_segment | ) | const |
Compute the distance from a line segment to the polygon. If the line segment is within the polygon, or it has intersect with the polygon, return 0. Otherwise, this distance is the minimal distance between the distances from the two ends of the line segment to the polygon.
line_segment | The line segment to compute whose distance to the polygon. |
double apollo::common::math::Polygon2d::DistanceTo | ( | const Box2d & | box | ) | const |
Compute the distance from a box to the polygon. If the box is within the polygon, or it has overlap with the polygon, return 0. Otherwise, this distance is the minimal distance among the distances from the edges of the box to the polygon.
box | The box to compute whose distance to the polygon. |
double apollo::common::math::Polygon2d::DistanceTo | ( | const Polygon2d & | polygon | ) | const |
Compute the distance from another polygon to the polygon. If the other polygon is within this polygon, or it has overlap with this polygon, return 0. Otherwise, this distance is the minimal distance among the distances from the edges of the other polygon to this polygon.
polygon | The polygon to compute whose distance to this polygon. |
double apollo::common::math::Polygon2d::DistanceToBoundary | ( | const Vec2d & | point | ) | const |
Compute the distance from a point to the boundary of the polygon. This distance is equal to the minimal distance from the point to the edges of the polygon.
point | The point to compute whose distance to the polygon. |
Polygon2d apollo::common::math::Polygon2d::ExpandByDistance | ( | const double | distance | ) | const |
Expand this polygon by a distance.
distance | The specified distance. To expand this polygon by it. |
void apollo::common::math::Polygon2d::ExtremePoints | ( | const double | heading, |
Vec2d *const | first, | ||
Vec2d *const | last | ||
) | const |
Get the extreme points along a heading direction.
heading | The specified heading. |
first | The point on the boundary of this polygon with the minimal projection onto the heading direction. |
last | The point on the boundary of this polygon with the maximal projection onto the heading direction. |
std::vector<LineSegment2d> apollo::common::math::Polygon2d::GetAllOverlaps | ( | const LineSegment2d & | line_segment | ) | const |
Get all overlapped line segments of a line segment and this polygon. There are possibly multiple overlapped line segments if this polygon is not convex.
line_segment | The target line segment. To get its all overlapped line segments with this polygon. |
void apollo::common::math::Polygon2d::GetAllVertices | ( | std::vector< Vec2d > *const | vertices | ) | const |
Get all vertices of the polygon.
All | vertices of the polygon |
std::vector<Vec2d> apollo::common::math::Polygon2d::GetAllVertices | ( | ) | const |
Get all vertices of the polygon.
bool apollo::common::math::Polygon2d::GetOverlap | ( | const LineSegment2d & | line_segment, |
Vec2d *const | first, | ||
Vec2d *const | last | ||
) | const |
Get the overlap of a line segment and this polygon. If they have overlap, output the two ends of the overlapped line segment.
line_segment | The target line segment. To get its overlap with this polygon. |
first | First end of the overlapped line segment. |
second | Second end of the overlapped line segment. |
bool apollo::common::math::Polygon2d::HasOverlap | ( | const LineSegment2d & | line_segment | ) | const |
Check if a line segment has overlap with this polygon.
line_segment | The target line segment. To check if it has overlap with this polygon. |
bool apollo::common::math::Polygon2d::HasOverlap | ( | const Polygon2d & | polygon | ) | const |
Check if this polygon has overlap with another polygon.
polygon | The target polygon. To check if it has overlap with this polygon. |
|
inline |
Check if the polygon is convex.
bool apollo::common::math::Polygon2d::IsPointIn | ( | const Vec2d & | point | ) | const |
Check if a point is within the polygon.
point | The target point. To check if it is within the polygon. |
bool apollo::common::math::Polygon2d::IsPointOnBoundary | ( | const Vec2d & | point | ) | const |
Check if a point is on the boundary of the polygon.
point | The target point. To check if it is on the boundary of the polygon. |
|
inline |
Get the edges of the polygon.
|
inline |
|
inline |
|
inline |
|
inline |
Box2d apollo::common::math::Polygon2d::MinAreaBoundingBox | ( | ) | const |
Get the bounding box with the minimal area.
|
protected |
|
inline |
Get the number of vertices of the polygon.
|
inline |
Get the vertices of the polygon.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |