next up previous contents
Next: Circles (circle) Up: Basic Data Types for Previous: Straight Lines (line)

   
Polygons (polygon)

Definition

An instance P of the data type polygon is a simple polygon in the two-dimensional plane defined by the sequence of its vertices. The number of vertices is called the size of P. A polygon with empty vertex sequence is called empty.

Creation

polygon P(list<point> pl, bool check=true);
    introduces a variable P of type polygon. P is initialized to the polygon with vertex sequence pl.
Precondition: The vertices in pl define a simple polygon (checked if check == true).
polygon P; introduces a variable P of type polygon. P is initialized to the empty polygon.

   

Operations

bool P.is_simple() tests whether P is simple or not.
list<point> P.vertices() returns the sequence of vertices of P in counterclockwise ordering.
list<segment> P.edges() returns the sequence of bounding segments of P in counterclockwise ordering.
list<point> P.intersection(segment s) returns P <intersection> s as a list of points.
list<point> P.intersection(line l) returns P <intersection> l as a list of points.
list<polygon> P.unite(polygon Q) returns P <union> Q as a list of polygons. The first polygon in the list gives the outer boundary of the contour of the union. Possibly following polygons define the inner boundaries (holes) of the contour (holes).
list<polygon> P.simple_parts() returns the simple parts of P as a list of simple polygons.
list<polygon> P.intersection(polygon Q) returns P <intersection> Q as a list of polygons.
list<polygon> P.diff(polygon Q) returns P - Q as a list of polygons.
list<polygon> P.sym_diff(polygon Q) returns (P<union> Q) - (P<intersection> Q) as a list of polygons.
polygon P.complement() returns the complement of P.
bool P.contains(point p) returns true if p lies inside of P and false otherwise.
double P.sqr_dist(point p) returns the square of the Euclidean distance between P and p.
double P.distance(point p) returns the Euclidean distance between P and p.
double P.area() returns the area of P.
polygon P.translate_by_angle(double a, double d)
    returns P translated in direction a by distance d.
polygon P.translate(double dx, double dy)
    returns P translated by vector (dx,dy).
polygon P.translate(vector v) returns P translated by vector v.
polygon P + vector v returns P translated by vector v.
polygon P - vector v returns P translated by vector -v.
polygon P.rotate(point q, double a)
    returns P rotated by angle a about point q.
polygon P.rotate(double a) returns P rotated by angle a about the origin.
polygon P.rotate90(point q) returns P rotated about q by angle of 90 degrees.
polygon P.reflect(point p, point q)
    returns P reflected across the straight line passing through p and q.
polygon P.reflect(point p) returns P reflected across point p.
int P.size() returns the size of P.
bool P.empty() returns true if P is empty, false otherwise.


Iterations Macros

forall_vertices(v,P) $\{$ ``the vertices of P are successively assigned to point v'' $\}$

forall_segments(s,P) $\{$ ``the edges of P are successively assigned to segment s'' $\}$


next up previous contents
Next: Circles (circle) Up: Basic Data Types for Previous: Straight Lines (line)
LEDA research project
1998-10-02