next up previous contents
Next: Rational Circles (rat_circle) Up: Basic Data Types for Previous: Straight Rational Lines (rat_line)

   
Rational Polygons (rat_polygon)

Definition

An instance P of the data type rat_polygon is a simple polygon in the two-dimensional plane defined by the sequence of its vertices in counter-clockwise order. Each vertex is represented by a rational point. The number of vertices is called the size of P. A rational polygon with empty vertex sequence is called empty.

Creation

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

rat_polygon

P(polygon Q, int prec); introduces a variable P of type rat_polygon. P is initialized to a rational approximation of the (floating point) polygon Q of coordinates with denominator at most prec.

   

Operations

polygon P.to_polygon() returns a floating point approximation of the P.
bool P.is_simple() tests whether P is simple or not.
list<rat_point> P.vertices() returns the sequence of vertices of P in counterclockwise ordering.
list<rat_segment> P.edges() returns the sequence of bounding segments of P in counterclockwise ordering.
list<rat_point> P.intersection(rat_segment s)
    returns P <intersection> s as a list of points.
list<rat_point> P.intersection(rat_line l)
    returns P <intersection> l as a list of points.
list<rat_polygon> P.unite(rat_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<rat_polygon> P.simple_parts() returns the simple parts of P as a list of simple polygons.
list<rat_polygon> P.intersection(rat_polygon Q)
    returns P <intersection> Q as a list of rational polygons.
list<rat_polygon> P.diff(rat_polygon Q) returns P - Q as a list of rational polygons.
list<rat_polygon> P.sym_diff(rat_polygon Q) returns (P<union> Q) - (P<intersection> Q) as a list of polygons.
rat_polygon P.complement() returns the complement of P.
rat_polygon P.translate(rational dx, rational dy)
    returns P translated by vector (dx,dy).
rat_polygon P.translate(integer dx, integer dy, integer dw)
    returns P translated by vector (dx/dw,dy/dw).
rat_polygon P.translate(rat_vector v) returns P translated by vector v.
rat_polygon P + rat_vector v returns P translated by vector v.
rat_polygon P - rat_vector v returns P translated by vector -v.
rat_polygon P.rotate90(rat_point q) returns P rotated by 90 degrees about q.
rat_polygon P.reflect(rat_point p, rat_point q)
    returns P reflected across the straight line passing through p and q.
rat_polygon P.reflect(rat_point p) returns P reflected across point p.
bool P.contains(rat_point p) returns true if p lies inside of P and false otherwise.
rational P.sqr_dist(rat_point p) returns the square of the Euclidean distance between P and p.
rational P.area() returns the area of 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 rat_point v'' $\}$

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


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