Finding the visible area of a guard inside an art gallery

In this assignment the goal is to find the visible area of a guard (point) inside an art gallery (a polygon).

Generally speaking, assume you have an input polygon (2D) 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.

This assignment is split into two parts.

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

    For extra credit: Implement an O(n lg n) algorithm, where n is the size of the polygon.

  2. Part 2: Add code so that the guard (last point clicked by the user) is moving throughout 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.

    For extra credit: add more than one guard, and render the visible area transparently, so that the overlap is easy to see.

The interface:

The interface should be as follows: To make it easy to test, yoru code will have to use the mouse both to initialize a polygon (based on the user's mouse clicks), and also to initialize the position of a guard inside the polygon.

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

To see some simple OpenGL examples on how to use the mouse, look in: Code/mouse.

Computing the visible polygon

The crux of this assignment is to come up with an algorithm to compute the visible polygon of teh guard. We have not talked about this in class, so you will come up with it from 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 fame) (hint: radial sweep).

Below are some explanatory images:

Comments


How to turn in: Please use the svn folder provided for the class! If you would like to change partners, just come talk to me or send me an email, and we'll create new svn folders for you.


The usual comments:

Start early. Always code assuming you'll have to debug. Think and structure your code incrementally so that it is easy to debug it. Test one piece before you move on to the next one. Keep in mind that pointer errors do not always manifest, and soemtimes they manifest in different ways on different computers. Start early.

Team work: Please give me feedback on how your team works. If I don't hear any feedback from you I assume your team is working well. If at any point you would like to work alone or change partners, email me so that I can ask DJ to update the svn folders.

Enjoy!