Write code (in C/C++) to compute the convex hull of a set of points in 3D using either the incremental algorithm, or gift wrapping.
Starting naive: Start by implementing the naive algorithm. It shoud provide a nice motivation for getting the basics working. For simplicity, do not worry about storing the topology of the hull, that is, the neighboring information for its faces, edges and vertices. Store the hull as an array/vector of faces. Also, do not worry about handling degeneracies. To test, generate points randomly on the sphere, and compute their convex hull.
Going from naive to gift wrapping or incremental: A big question will be: what sort of structure do you need to store the hull? At the very least the hull will need to store its faces (an array/vector of faces on the hull). Ideally the faces use pointers to the points, rather than duplicating the points and their coordinates. For example:
typedef struct _face3d { point3d *p1, *p2, *p3; //the vertices on this face (in ccw as looking from outside) } face3d;
In addition to the faces, you may need to keep track of what vertices are on the hull, what edges are on the hull, and whether an edge has found both its adjacent faces or only one of them. Come up with structures to keep track of these. Consider using hash tables and maps and trees and such, and avoid storing a topological structure for the hull (to avoid the complexity or programming). For example you may want to keep a queue/stack that stores all the edges that are on the frontier of the search (in other words: all edges that have found only one adjacent face so far).
Degeneracies: If there exist sets of 4 or more points that are co-planar, it is possible that faces in the hull are not triangular. Whichever algorithm you implement, consider how it can be extended to handle degeneracies.
Base code: Base code is provided with the assignment's GitHub repository. The code should compile as is, but it does not do anything besides the interface. You need to add a function that computes the hull, and a function that renders the faces of the hull.
Test cases: As with the previous assignment, please provide one interesting test case (configuration of points) on which to compute the hull. Every team, please email your special test_cases to the whole class on piazza, so that everyone can include everyone's test cases in their code.
Share! Use piazza! Share on piazza anything that you stumble on, and anything you learn while working on the project, so that the whole class can benefit.
Extra features: Some ideas:
Work in style: As usual, you need to strive to 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 directly proportional to how easy and enjoyablet 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 that good.
What and how to turn in: You will receive the assignment on GitHub, including the startup code. You are encouraged to do pair-programming, but feel free to work alone. Push your code into your github repository for this assignment. Provide a README that describe the state of your code (does it work on all test cases, do you know of any bugs, any extra features).