COMPUTATIONAL GEOMETRY in CODE
This applet illustrates several pieces of code from
Computational Geometry in C
by
Joseph O'Rourke
.
The code illustrated includes
orientation.c,
area.c,
centroid.c,
inpoly.c, and
tri.c.
Code from the forthcoming second edition of the book is used, but this
is similar to the code shown in the first edition (and distributed via
ftp).
The applet includes polygon entering and editing.
- Start by drawing a polygon. Click on the position of the vertices
on the canvas with your mouse in order,
and then push the "Finish Polygon" button.
If you click within the disk of the first point, the polygon is
automatically closed.
Immediately after closing, the orientation of the polygon is
computed, and if you entered it clockwise, it is reversed to
be counterclockwise. This is done because some of the code
assumes the polygon has been input counterclockwise.
- After a polygon is created, it can be modified: vertices can be added,
deleted, or moved. For each operation, press the corresponding button and then
click with the mouse on the area or vertex where the change should occur.
Click on a vertex to delete it; click near an edge to add a new point;
click on a vertex to move it.
The current mode (add, delete, move) is indicated by italics in the
corresponding button.
- To find the area, the center of gravity, or a triangulation of the
polygon, press the corresponding button.
Note: the triangulation code does not work for non-simple polygons.
- To exercise the point-in-polygon code,
press the "In Poly?" button, and then click a query point on the canvas.
The rays used in the code are displayed.
(This is one instance where the code differs substantially between
the First and Second editions.)
- To draw a new polygon, clear the screen with the "To Clear" button.
The Java code was written by Lilla Zollei and Irena Pashchenko.
Questions to
orourke@cs.smith.edu