|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
A regular polygon defined by center, side length, and vertex count. More...
#include <polygon.H>
Classes | |
| class | Segment_Iterator |
| Iterator over the edges (segments) of a regular polygon. More... | |
| class | Vertex_Iterator |
| Iterator over the vertices of a regular polygon. More... | |
Public Member Functions | |
| Regular_Polygon () | |
| Default constructor. Creates an invalid empty polygon. | |
| Regular_Polygon (const Point &c, const double &side_sz, const size_t &n, const double &ang=0) | |
| Construct a regular polygon. | |
| const double & | get_side_size () const |
| Get the side length. | |
| const Point & | get_center () const |
| Get the center point. | |
| const size_t & | size () const |
| Get the number of vertices. | |
| const double & | radius () const |
| Get the circumradius. | |
| bool | is_closed () const |
| Check if the polygon is closed. | |
| const Point | get_vertex (const size_t &i) const |
| Get the i-th vertex of the polygon. | |
| const Point | get_first_vertex () const |
| Get the first vertex (index 0). | |
| const Point | get_last_vertex () const |
| Get the last vertex (index size()-1). | |
| Segment | get_first_segment () const |
| Get the first segment (edge). | |
| Segment | get_last_segment () const |
| Get the last segment (closing edge). | |
| Point | lowest_point () const |
| Get the lowest point of the bounding circle. | |
| Point | highest_point () const |
| Get the highest point of the bounding circle. | |
| Point | leftmost_point () const |
| Get the leftmost point of the bounding circle. | |
| Point | rightmost_point () const |
| Get the rightmost point of the bounding circle. | |
Public Member Functions inherited from Geom_Object | |
| Geom_Object ()=default | |
| virtual | ~Geom_Object ()=default |
Private Attributes | |
| Point | center |
| Center point of the polygon. | |
| double | side_size |
| Length of each side. | |
| size_t | num_vertex |
| Number of vertices (sides) | |
| double | angle |
| Rotation angle in radians. | |
| double | r |
| Circumradius (distance from center to vertices) | |
| double | beta |
| Central angle between adjacent vertices (2π/n) | |
A regular polygon defined by center, side length, and vertex count.
Regular_Polygon represents an n-sided regular polygon (equilateral and equiangular) defined parametrically by its center point, the length of each side, and the number of vertices.
The polygon is constructed using the law of sines to calculate the circumradius from the side length:
Where:
beta = 2π/n (central angle)alpha = (π - beta)/2 (angle between radius and side)Vertices are numbered 0 to n-1. Vertex 0 is positioned at angle angle from the negative y-axis (i.e., pointing "south" when angle=0).
|
inline |
|
inline |
Construct a regular polygon.
| c | Center point of the polygon. |
| side_sz | Length of each side. |
| n | Number of vertices (must be >= 3). |
| ang | Rotation angle in radians (default 0). |
| std::domain_error | If n < 3. |
Definition at line 851 of file polygon.H.
References ah_domain_error_if, beta, Aleph::maps(), PI, r, side_size, and sin().
|
inline |
Get the first segment (edge).
Definition at line 920 of file polygon.H.
References get_vertex().
Get the first vertex (index 0).
Definition at line 912 of file polygon.H.
References get_vertex().
|
inline |
Get the last segment (closing edge).
Definition at line 927 of file polygon.H.
References get_vertex(), and num_vertex.
Get the last vertex (index size()-1).
Definition at line 916 of file polygon.H.
References get_vertex(), and num_vertex.
Get the i-th vertex of the polygon.
Vertex 0 is at angle angle from the negative y-axis. Subsequent vertices are placed at equal angular intervals counter-clockwise.
| std::out_of_range | If i >= size(). |
Definition at line 895 of file polygon.H.
References ah_out_of_range_error_if, angle, beta, center, Segment::get_tgt_point(), num_vertex, r, and Segment::rotate().
Referenced by build_poly_graph(), Polygon::copy_regular_polygon(), Regular_Polygon::Segment_Iterator::get_current_segment(), Regular_Polygon::Vertex_Iterator::get_current_vertex(), get_first_segment(), get_first_vertex(), get_last_segment(), get_last_vertex(), TEST(), TEST_F(), and TEST_F().
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Get the number of vertices.
Definition at line 876 of file polygon.H.
References num_vertex.
Referenced by Polygon::copy_regular_polygon(), Regular_Polygon::Segment_Iterator::get_current_segment(), Regular_Polygon::Vertex_Iterator::has_curr(), Regular_Polygon::Segment_Iterator::has_curr(), TEST(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().
|
private |
|
private |
Central angle between adjacent vertices (2π/n)
Definition at line 835 of file polygon.H.
Referenced by Regular_Polygon(), and get_vertex().
|
private |
Center point of the polygon.
Definition at line 830 of file polygon.H.
Referenced by get_center(), get_vertex(), highest_point(), leftmost_point(), lowest_point(), and rightmost_point().
|
private |
Number of vertices (sides)
Definition at line 832 of file polygon.H.
Referenced by get_last_segment(), get_last_vertex(), get_vertex(), and size().
|
private |
Circumradius (distance from center to vertices)
Definition at line 834 of file polygon.H.
Referenced by Regular_Polygon(), get_vertex(), highest_point(), leftmost_point(), lowest_point(), radius(), and rightmost_point().
|
private |
Length of each side.
Definition at line 831 of file polygon.H.
Referenced by Regular_Polygon(), and get_side_size().