Assignment: 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. You will notice that the main file viewpoints.cpp is now in cpp and uses vectors. This is the one assignment where I wolud 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 base code is provided to help, but it represents my vision. 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.

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

You need to extend this code to:

  1. Compute the intersection points
  2. 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).
  3. 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.
  4. Include all the test cases emailed by the other teams into your own code.
  5. 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',....
  6. 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.

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.

Keep in mind that in the subsequent assignments we'll be moving towards you writing the code from scratch.

Team work

You are encouraged to work with a partner, but you don't have to. If you work with a partner, you will be held to higher standards than if you work alone; put differently, you'll need to do more work than if you work alone.

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.

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.

Submitting your work

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


Last modified: Mon Feb 8 17:13:11 EST 2016