Thunderbots Project
Loading...
Searching...
No Matches
Polygon Class Reference

#include <polygon.h>

Inheritance diagram for Polygon:
Collaboration diagram for Polygon:

Public Member Functions

 Polygon (const std::vector< Point > &points)
 
 Polygon (const std::initializer_list< Point > &points)
 
Point centroid () const
 
Polygon expand (double expansion_amount) const
 
double perimeter () const
 
const std::vector< Segment > & getSegments () const
 
const std::vector< Point > & getPoints () const
 

Static Public Member Functions

static Polygon fromSegment (const Segment &segment, double length_radius, double width_radius)
 
static Polygon fromSegment (const Segment &segment, double radius)
 

Protected Member Functions

void initSegments ()
 

Protected Attributes

std::vector< Pointpoints_
 
std::vector< Segmentsegments_
 

Detailed Description

A shape composed of line segments.

Constructor & Destructor Documentation

◆ Polygon() [1/2]

Polygon ( const std::vector< Point > &  points)
explicit

Construct a polygon by drawing line segments between consecutive Points, and then from the last Point to the first Point.

Parameters
pointsPoints that form a polygon

◆ Polygon() [2/2]

Polygon ( const std::initializer_list< Point > &  points)
explicit

Construct a polygon by drawing line segments between consecutive Points, and then from the last Point to the first Point.

Parameters
pointsPoints that form a polygon

Member Function Documentation

◆ centroid()

Point centroid ( ) const

Returns the centroid of this polygon

Returns
The centroid of this polygon

◆ expand()

Polygon expand ( double  expansion_amount) const

Returns the Polygon expanded in all directions by the expansion_amount

Parameters
expansion_amounta non-negative expansion amount
Exceptions
std::invalid_argumentif expansion_amount is negative
Returns
a Polygon expanded in all directions by the expansion amount

◆ fromSegment()

Polygon fromSegment ( const Segment segment,
double  length_radius,
double  width_radius 
)
static

Creates a rectangular polygon that is oriented along the segment. The radius defines the closest distance to a edge of the rectangle parallel to the segment i.e. the radius is half the width of the rectangle. The polygon contains both points as "focal" points similar to an ellipse. see definition for details and diagram

Parameters
segmentsegment along which to construct the rectangular polygon
length_radiusHow much each end of the segment should be elongated by
width_radiusHow wide should the polygon be, measured from the segment
Returns
an oriented polygon along the 2 points that contains both points.

◆ getPoints()

const std::vector< Point > & getPoints ( ) const

Returns the points that form the polygon.

Returns
the points that form the polygon.

◆ getSegments()

const std::vector< Segment > & getSegments ( ) const

Returns the line segments that form this polygon.

Returns
the line segments that form this polygon.

◆ initSegments()

void initSegments ( )
protected

Initializes the segments_ vector

◆ perimeter()

double perimeter ( ) const

Returns perimeter length of the polygon

Returns
perimeter length of the polygon

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