I would like to triangulate between two sets of polygons. One set is always inside the other, in fact, the outer polygons are created as offsets from the original set. Triangulation would be easy if they were on the same plane, but I would like to add depth by moving the outer polygon to a parallel but different plane. The usual method for triangulation that I use (glu tesselator) does not work. Is there an alternative that would?
You are saying that you have a triangulation method that works in 2D. Fine. Put both of your contours on the same plane z = 0
, do the 2D triangulation, then set z
coordinate of the vertices of the outer contour to the value you need. As you said, move the outer contour to the parallel plane.
Why this approach doesn't suit you?
Yes, you may end up with some horizontal triangles, which have all three vertices with the same z
coordinate. If you used a "true" 3D triangulation you also may end up with same horizontal triangles. It all depends on the shape of the contour and algorithm.
If it is not acceptable to have such horizontal triangles you can add a second pass to try to eliminate them:
Find a horizontal triangle. Two of its edges would belong to either original inner or original outer contour. The third edge would "short-circuit" the vertices of the original contour. Find another triangle that has the same edge as the "third" edge described above. The pair of these triangles form a rhombus. There are only two ways to triangulate the rhombus. The one that you've got is not acceptable, so just re-triangulate the rhombus in a different way.
It is hard to explain this without drawings.
IMO when you have moved the outer polygon you can try a delaunay triangulation in 3d for example with circumspheres. Cgal can do 3d triangulation.
If I understand what you're asking correctly, it sounds like you're trying to do what's sometimes called an extrusion, like this
.
There are a number of font libraries that can do what you'd like for OpenGL. While the information on this page is somewhat dated, I've heard good things about GLTT.
If you want to do it yourself, you might get away with just a simple triangle strip connecting the two contours (assuming they're connected [in the mathematical graph sense]), and may not need the tessellator (aside from creating the first contour).
Let's say the "inner" contour is the one emitted from the tessellator, and you record its perimeter vertices. Then as you say, create the "outer" contour (the one that you want to offset) by translating each inner vertex by some offset (perhaps using normal [orthogonal to the tangent line] at the vertex, or whatever) in the same plane, and then add the extrusion depth. If you keep the same general topology (i.e., same number of vertices and same connectivity information for each vertex), then you can just "stitch" that set of contours into a single triangle strip. Depending on the effect you're looking for, you may need to add additional vertices to the outer contour to make it more aesthetically pleasing. That's no real problem, other than it makes the triangle strip connecting the contours a bit more complicated.
© 2022 - 2024 — McMap. All rights reserved.