Having fun in an art gallery

In this assignment the goal is to find the visible area of a guard (point) inside an art gallery (polygon). That is, assume you have an input polygon in the plane that represents the plan of an art gallery, and a point inside this polygon that represents a guard. Your task is to implement an algorithm that computes and displays the part of the gallery visible to the guard. To manage complexity we'll split it into two parts:

  1. Part 1: the user can click on points, and the code computes and displays the visible area from that point.

  2. Part 2: Add code so that the guard (last point clicked by the user) is moving inside the polygon, and the visible area is displayed as the guard is moving. Make it so that the guard does not get stuck in a corner of the polygon.

The interface

Once the polygon and the guard are set, run your algorithm that computes that polygon that's visible and render it with a different color.

You may have already seen that OpenGL can render a polygon in two ways: just its boundary (GL_LINE mode), or filled (GL_FILL mode), by turning on one of:

glPolygonMode(GL_LINE);
//glPolygonMode(GL_FILL);

Something to be aware of is that openGL can only render filled polygons that are convex. This seems like a big limitation, however if you think about it a little it becomes clear that its not trivial to render a non-convex polygon filled. Essentially you need to compute the triangulation of the polygon, and then render one triangle at a time. Computing a triangulation of a non-convex polygon is a big problem in itself. You'll need to find a different way to render the visible non-convex polygon. Ideally it has to be filled.

Computing the visible polygon

The crux of this assignment is to come up with an algorithm to compute the visible polygon of the guard. We have not talked specifically about this problem in class, so you have a chance to come up with a solution form scratch. A quadratic algorithm will be fine. If you can come up with an O(n lg n) algorithm you'll get extra credit and a round of applause in class (hint: radial sweep).

Extra features

Some ideas:

Submitting your work

Make a folder called guard in your svn folder on microwave. I will have access to this svn, so no need to submit anything --- just make sure everything is checked in.

Enjoy!