Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
polygon.H File Reference

2D polygon representation and geometric operations. More...

#include <dlink.H>
#include <point.H>
#include <ah-errors.H>
#include <string>
Include dependency graph for polygon.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  Vertex
 A vertex in a polygon's doubly-linked vertex list. More...
 
class  Polygon
 A general (irregular) 2D polygon defined by a sequence of vertices. More...
 
struct  Polygon::Vertex_Iterator
 Iterator over the vertices of a polygon. More...
 
class  Polygon::Segment_Iterator
 Iterator over the edges (segments) of a polygon. More...
 
class  Regular_Polygon
 A regular polygon defined by center, side length, and vertex count. More...
 
class  Regular_Polygon::Vertex_Iterator
 Iterator over the vertices of a regular polygon. More...
 
class  Regular_Polygon::Segment_Iterator
 Iterator over the edges (segments) of a regular polygon. More...
 

Detailed Description

2D polygon representation and geometric operations.

This file provides classes for representing and manipulating 2D polygons:

  • Vertex: A point that participates in a doubly-linked list of vertices.
  • Polygon: General (irregular) polygon defined by a sequence of vertices.
  • Regular_Polygon: Regular polygon defined by center, side length, and vertex count.

Key Features

  • Dynamic vertex management: Add/remove vertices with automatic validation.
  • Self-intersection detection: Prevents creation of self-intersecting polygons.
  • Colinearity handling: Automatically merges colinear edges.
  • Containment testing: Check if a point lies inside a closed polygon.
  • Extreme points tracking: Efficiently track bounding box vertices.
  • Iterators: Traverse vertices or edges (segments) of the polygon.
  • Regular polygon support: Create n-sided regular polygons with rotation.

Usage Example

#include <polygon.H>
// Create a square polygon
Polygon square;
square.add_vertex(Point(0, 0));
square.add_vertex(Point(100, 0));
square.add_vertex(Point(100, 100));
square.add_vertex(Point(0, 100));
square.close();
// Check if point is inside
Point p(50, 50);
if (square.contains_to(p))
std::cout << "Point is inside the square\n";
// Create a regular hexagon
Regular_Polygon hexagon(Point(200, 200), 50.0, 6);
std::cout << "Hexagon radius: " << hexagon.radius() << "\n";
Rectangular point in the plane.
Definition point.H:156
A general (irregular) 2D polygon defined by a sequence of vertices.
Definition polygon.H:233
void close()
Close the polygon.
Definition polygon.H:710
void add_vertex(const Point &point)
Add a vertex to the polygon.
Definition polygon.H:610
bool contains_to(const Point &p)
Check if a point is inside the polygon.
Definition polygon.H:751
A regular polygon defined by center, side length, and vertex count.
Definition polygon.H:829
2D polygon representation and geometric operations.

Thread Safety

None of the classes in this file are thread-safe. External synchronization is required for concurrent access.

Author
Leandro Rabindranath León

Definition in file polygon.H.