Orthogonal segment intersections

Implement the sweep line algorithm for finding the intersections of a set of orthogonal line segments in 2D and animate the algorithm.

Base code is provided here. The base code is provided to help, but it represents how I think of the code. Feel free to use as much or as little of this base code as you want. Feel free to extend it and change it as you see fit.

Use cpp: You will notice that the main file intersect.cpp is now in cpp and uses vectors. For this assignment I suggest that you use cpp because it gives you balanced binary search trees. If you decide to stick to C, you'll need to find a free implementation of balanced binary search trees (like red-black trees or AVL trees). You don't need to write OO code, just c plus the vectors and linked lists that come conveniently with cpp.

The code should compile as is, but it does not do anything besides the interface.

You need to extend this code to:

  1. Understand how the animation works
  2. Compute the intersection points
  3. Simulate the algorithm as it is computing the intersection points (visualize the sweep line moving to the right, the segments being added or deleted from the active structure, and the intersection points as they are computed).
  4. Provide some interesting test cases (configurations of points). Every team, please email your special test_cases to the whole class, so that everyone can include everyone's test cases in their code.
  5. Include all the test cases emailed by the other teams into your own code.
  6. Provide a nice way to cycle through the test cases that does not involve recompiling the code. For example you could make it so that every time the user presses 'i', the segments are initialized with the next test case. OR, you could make it so that different test cases are called when the user presses '0', '1', '2', '3', '4',....
  7. Whenever the user presses a new test case, your code should start over simulating the sweep.

What should I write and where?

Part of this assignment is to understand how the code works, why it's doing what it's doing, and where to insert your code. Once you understand, you will see that the actual code you need to write is fairly straightforward (meaning, it's not terribly difficult).

There are a couple of issues you will need to think about: how to use binary search trees in cpp (you can use sets, or multimaps, which are implemented as BST's), how write the comparator function for the binary search trees; and how to get them to do a range search for you.

Submitting your work

Make a folder called segmentintersection 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!


Reminder on good style

As usual, you need to strive you write not merely code, but simple, elegant and easy to understand code. Furthermore, you need to strive to do this out of habit, as you start programming, and not only at the end. Writing good code has to become your second nature. Write good code not because you have to, but because you don't know any other way.

People often disagree what consitutues elegant when it comes to coding, but everyone agrees on the following:

How do you know if you write good code? My theory is that the the quality of your code is ditrectly proportional to how easy and pleasant is to debug and update/extend your code. If you find debugging is frustrating and like searching a needle in a haystack, then your code style is probably not good.