Programming and Computer Science in Java:
Homework #17:  Polygon Area
    David Kosbie, 2002-2003
See Course Home Page

Due Date:  Fri, April 4, 2003

Question 1:  In class today, we extensively reviewed a simple technique for finding the area of a polygon whose vertices are exclusively in the first quadrant (ie, both x and y are non-negative), given the coordinates of its vertices in clockwise order.  Basically, you drop vertical lines from each pair of successive points down to the x-axis, thereby forming a bunch of trapezoids.  To find the area of the polygon, merely sum the areas of these trapezoids, but with one odd caveat -- when the second point is to the left of the first point, count the area as negative, and when it is to the right, count it as positive.  This is not magic, and we covered the proof in class, but it sure seems like magic, eh?  Have fun.

By the way, you should expect the input to be a series of doubles, x0 y0 x1 y1 ... xn yn where the last point is the same as the first (and thus you know you are finished with the input), and the points are in fact in the first quadrant and given in clockwise order.

Good luck!


See Course Home Page