Homework 4

Read Chapter 11 in the text because next Monday we will be discussing Splines.

Also, do the assignment below. When you have finished the assignment, email your source code to the grader at wanghua@cs.nyu.edu, and post the working applet onto the web.

Write an applet which displays at least two convex polygons. If the user pushs the mouse button down within of one of these polygons, and then drags the mouse around, the polygon moves accordingly (until the user lifts the mouse). If the user drags within the intersection area, then move both polygons around together.

Display the two polygons in two different fill colors, and display their mutual intersection in a third color. You can make the two polygons any convex shapes you like. Go ahead and make creative shapes if you prefer.

To do the above, you should create a convex Polygon class, I recommend you do this by extending class java.util.Vector. Your class should contain the following methods:

You should also create the following classes:

The HalfPlane class will let you implement Polygon.intersect(Polygon) by implementing a Polygon.intersect(HalfPlane) method, which you can repeatedly invoke to intersect with the entire Polygon.

It will also let you implement Polygon.contains(Point) by successively invoking HalfPlane.eval(Point) for the HalfPlane defined by each of the polygon's successive edges, and returning true if all these evaluations return non-negative.