Search code examples
c#3dgeometryprojection

Triangulating a non planar polygon in 3D space


I have an ordered list of vertices in 3D, that form a polygon.

I'm looking to project these onto a 2D plane (as a way to triangulate and then calculate the area of them).

I'm not entirely sure how to go about doing this though, anyone have any suggestions?

Edit:

I've clarified the title to the real problem I had and posted the fairly specific solution that I used. It might come in helpful to someone at some point, even if it is a bit niche.


Solution

  • The solution I eventually went with, which is far from optimal, but it might help some people:

    1. Begin by taking an axis aligned bounding box of the polygon you're working with (this is simple done by taking the maximum and minimum of each x, y and z value for the pointset you have).

    2. Project the points you have onto each of the 3 axes, the planes of which you can get from your bounding box. For help with projecting I recommend this: Projecting to a plane

    3. From here, we now have 3 two dimensional polygons. Check if they are convex, which can be done by taking the dot product of every corner in the polygon, normalising it, and comparing it the others, if they're not all the same , it's not convex.

    4. If any of them are convex, pick one and triangulate it (I used Triangle.NET). The indices of the points you get out of that will correspond to your original points, giving you a functional triangulation.

    Notes:

    This isn't ideal, it doesn't always work (although it will in a lot of cases). In particular if the polygon overlaps with itself.

    A more suitable but still not ideal method would be the minimum bounding box, but that's a lot more complicated to work out.