gradientspace / geometry3Sharp

C# library for 2D/3D geometric computation, mesh algorithms, and so on. Boost license.
http://www.gradientspace.com
Boost Software License 1.0
1.72k stars 390 forks source link

Polygon meshing with fixed points inside #75

Open TTWDmitryZelenkin opened 6 years ago

TTWDmitryZelenkin commented 6 years ago

Hi. Thank you for a fantastic library. I found a TriangulatedPolygonGenerator method which does meshing of 2D polygons. I have points inside a polygon. Is there any workaround how to force mesh vertices to snap onto those points?

rms80 commented 6 years ago

snapping vertices to points is tricky because you might introduce foldovers. Another more reliable option is to insert each of your points into the meshed polygon as a new vertex, using DMesh3.PokeTriangle()

This is actually how TriangulatedPolygonGenerator works internally, it starts with a 2-triangle rectangle, inserts the polygon vertices, and then connects the edges and removes the 'outside' regions. If you look in MeshInsertUVPolyCurve.insert_corners() you will see how this is done (there are some special cases it handles there)