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

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 need 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). (There are some recent papers describing O(n) algorithms).

Extra features

Some ideas:

More reading

Several algorithm are known for Computing the visible polygon in O(n) time, for example: Some cool apps:

What to turn in

Enjoy!


Grading

Functionality: 80 points Code Style: 20 points

Demos from previous classes