Saint Louis University |
Computer Science 493
|
Dept. of Math & Computer Science |
Topic: Triangulating a Polygon
Related Reading: Ch. 3
Due:
Friday, 26 October 2007, 4:10pm
Please make sure you adhere to the policies on academic integrity.
The goal of this assignment is to implement the algorithm for triangulating a simple polygon, as described in Chapter 3 of our text book. This algorithm proceeds by breaking the initial polygon into one or more monotone polygon, and then by independently triangulating each of those monotone pieces.
Repository: source code
Documentation is embedded directly in the source code, however we provide a brief overview of the major components.
triangulate.py
This is a stub for your part of the project. Please place all
of your code in this one file. It must support a method
triangulate(subdivision) which takes a DCEL structure
and modifies that very structure so as to triangulate the
presumed polygon.
driver.py
A main driver. The original polygon is described within a
simple text file specified as a command line argument (e.g.,
DCEL.py
The definitions for a doubly-connected edge list
similar to the one described in the text. In addition to
providing accessors to the true attributes
(e.g., Edge.getOrigin(), Edge.getTwin()) we
have provided implementations for several convenient derived
accessors (e.g., Edge.getDest(), Edge.getFaceBoundary()).
Each overall DCEL has a designated "exterior" face that represents the unbounded region outside of all other faces. This can be identified as DCEL.getExteriorFace() and it cannot be changed.
For the overall DCEL structure, we have provided a DCEL.validate() method for convenience. This scans the overall structure looking for an obvious inconcistencies (e.g., a half edge whose twin's twin is not the same edge). If an inconcsitency is found, this method throws an exception; otherwise it returns quietly. Please note: the lack of an exception does not guarantee the integrity of the structure, it simply means that we did not find any of the obvious inconsistencies. Our driver calls this method once, at the completion of your work. However, we recommend that you use it as a debugging tool, checking the integrity of your structure each time you make a local modification.
This module also supports a renderDCEL method to generate a visualization of the structure using the cs1graphics package. Our driver automatically produces such an image for the original polygon and the resulting subidvision after your triangulation. However you may feel free to generate intermediate images as a debugging tool. There is also a definition for a GraphicsData class that can be used to affect the color of a rendered feature. Each DCEL feature (i.e., Vertex, Edge, Face) has an auxillary data field. If that field is set to one of these GraphicsData objects, the specified color will be used.
geomutil.py, Point.py, Rational.py
Low level support for basic geometric computing. A
Point is used to represent the coordinates of
a vertex (but do not confuse a Point and a DCEL.Vertex).
The geomutil module defines many useful functions and classes for checking the orientation of points and the implicit segments or lines defined by a pair of points. In particular, verticalCmp is a comparison function that order points in the conventional top-to-bottom (but with ties broken left-to-right). In similar spirit, checkLineLine provides a comparison of whether one line segment is left or right of another, and checkPointLine checks whether an isolated point is left or right or on a given line.
BinarySearchTree.py, RedBlackTree.py
These define general search trees, with the
BinarySearchTree class being a base class, and a
RedBlackTree an extension of that class which
guarantees a balanced structure.
The public interface works as follows. Entries are inserted as (key,data) pairs, where the key can be any type of object and the data can be any type of associated value. The order of the tree is based upon the keys; the data is stored and can subsequently be retrieved. By default, keys are compared to each other using the standard comparison order for that type. However, the use of an alternate order can be specified when initializing the tree by providing a comparator (a function or function-like object that returns -1, 0, +1 when comparing two keys).
Please note (although this might not be relevant for this assignment) that our tree is implemented so that all data entries are stored at leaves of the tree. Also, if two or more entries are inserted with the same key, those duplicates are maintained at a single leaf of the tree (see documentation for details).
page54.txt,
page58.txt,
page59.txt,
rectilinearSimple.txt,
rectilinear.txt
Three sample text files defining polygons (see below). You
should also test your program on additional polygons of your choosing.
intersection.py
Used by our driver to build general subdivisions of a set of
edges. Conveniently, this provides an example of another
sweepline algorithm (namely that from Ch. 2).
cs1graphics.py
A beta release of our graphics module. Not the most efficient
(there may be a noticeable delay when rendering the results),
but it should do for now.
The red lines in the folloiwng diagrams are added during the phase of divising into monotone polygons. The green lines are added when triangulating those monotonoe polygons.
filename | original | monotone | triangulated |
---|---|---|---|
page54.txt | |||
rectilinearSimple.txt | |||
rectilinear.txt |
You are only required to implement the triangulation for a subdivision which is assumed to represent a simple polygon (without holes). However, the end of the chapter in the book discusses how this very same approch can be used to triangulate an arbitrary plana subdivision. Design the triangulate(subdivision) to work with arbitrary DCEL configurations.
The same driver can be used for the more general case, giving a file that gives a complete list of edges (in arbitrary order).
Here are a few examples, taken from figures in the book. Please note that the triangulation that results from the sweepline algorithm is not actually the one shown in the book.
filename | original | monotone | triangulated |
---|---|---|---|
page58.txt | |||
page59.txt |