I am trying to calculate the top most intersection of an arbitrary number of planes, with no joy! I am using actionscript, but just need find an algorithm that i can implement.
Problem:
Here is a picture to clarify what I mean with 2 triangles:
However, when we allow for more than 2 triangles, I get awkward lines of intersection.
I'm interested by your problem much so I described the algorithm and implemented it in C++ (I dont know AS as good as C++). The main idea of the algorithm is iterative recalculation of the top surface while adding new triangles.
After triangles have intercepted they can change their form into polygons with custom vertex number. So each triangle is initially transformed into plain polygon. Each polygon instance includes its plane equation and a set of polygon faces. Each face as a data structure includes one vertex of polygon and equation of vertical boundary plane crossing that vertex and the next vertex in polygon vertex sequence. (Thus the order of faces in a set is important.)
Lets think of the top surface as of a polygon set. While new polygon is adding we should iteratively recalculate faces of all the surface polygons. Algorithm of face recalculation includes following steps:
Not to flood on this page I've put the code into pastebin.
You are constructing your surface of interest between the three vertical "axes". The surface is bounded below by a base. Bound it above so that the problem is contained in a triangular prism.
The volume above your surface is a convex hull formed by intersecting planes (to wit: the cap, three sides, and triangle intersections). There is a lot of theory and code about convex hulls.
I don't know ActionScript, but a quick internet search on "convex hulls intersecting planes" and such terms led me to this code which (purports to) solve your problem:
http://nauful.com/pages/convexhull.html
Hope this helps, Glenn
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With