It started life as a solution to this frustum culling problem. I don’t normally come up with anything this clever, so one thing lead to another and now I’ve got an efficient generalised volume/plane intersection finding utility on my hands. It handles non-convex volumes and the intersection polygon vertices are returned in order. I’ve got no use for it, so here you go:
Subclass IntersectionVolume to define a particular topography (number of vertices, edges between vertices, faces bound by edges). Have a look at Box, Tetrahedron and Dipyramid for examples of this. Betraying its genesis, Box has a method to set its vertices from view frustum planes.
Set the vertex positions as required (bear in mind that faces have to be convex polygons), and you’re ready to go. There are methods to find the intersection polygons with x, y and z planes, or you can query on an arbitrary plane at the minimal additional cost of a dot-product per vertex.
http://homepages.inf.ed.ac.uk/rmcnally/intersect/intersect0.png
http://homepages.inf.ed.ac.uk/rmcnally/intersect/intersect1.png
http://homepages.inf.ed.ac.uk/rmcnally/intersect/intersect2.png
Have a play with it with this webstart. 1-4 to change the query volume, q and w to alter the number of queries, a s and d to control the scan speed, left-button drag to rotate the view and right-button drag to rotate the query planes.