Mesh generation algorithm - algorithm

As part of a project I'm working on, I need to generate a 2D triangular mesh.
At the minute, I've implemented a Delaunay triangulation algorithm. I have to input a set of vertices, and it triangulates between them, and that works out great.
However, I'd like to improve on this and instead input a set of vertices that represent the edge of an arbitrary 2D shape (with no holes), and generate a (as uniformly as possible) mesh inside that shape, with varying degrees of precision (target number of triangles).
My Google skills seem to be lacking today, and I haven't found quite what I'm looking for.
Does anyone know of an algorithm / library / concept that will set me on my way?

The triangles of the possibly non-convex 2D shape must not cross the border edges, a Constrained Delaunay triangulation can achieve that.
One solution: Triangulate with Fade [1] and insert the edges of the polygon. A uniform mesh inside the area can then be created using Delaunay Refinement.
[1] http://www.geom.at/fade2d/html/
hth

Related

Build constrained alpha shape of polygons

I have a quite specific task.
I need to compute alpha shape of a set of points. (You can frolic with already implemented algorith there)
The point is that I have predefined subsets of points (let's call them details) and I do not want their structure to be changed. For example, suppose these polygons to be details:
Then, the following hulls are ok depending on alpha-radius:
And the following is not:
In brief, I want the structure of specified subsets of points to stay unchanged during reducing the radius.
So, how do you think:
May I use any of already implemented algorithm or should I figure out some specific one?
Is there implemented example of Alpha-Shape algorithm with open source code anywhere? (Alpha-Shape, not Concave hull. It must split contour into several parts when reducing the radius)
Well, Finally I solved this using constrained Delaunay triangulation.
The idea (that Yves Daoust shared in comment to the question) was to use not just Delaunay triangulation during building Alpha shape, but constrained Delaunay triangulation.
Algorithm: In brief, I:
Took convex hull of the promoted polygons
Computed its constrained triangulation. (Constraining segments are polygon's edges)
On this step I used Triangle .NET library for C#. I guess, every popular language has alternatives to it.
Built alpha shape: threw away all triangles where any edge is longer than predefined alpha
Results of my struggles:
Alpha = 1000, alpha shape is just a convex hull
Alpha = 400
Alpha = 30. Only very small concavities are smoothened
Feel free to write me for a deeper explanation, if you wish.

Generate a 2D mesh from an outline

I got an outline (list of points) for a plane I want to generate. The plane is quite big and I need evenly distributed vertices inside the outline. Each vertex has a color value from red to green to visualize some data in the plane. I need to visualize the data as precise as possible in real time.
My idea was to simply create a grid and adjust all the vertices outside of the outline. This turned out to be quite complex.
This is a quick example what I want to achieve.
Is there any algorithm that solves this problem?
Is there another way to generate a mesh from an outline with evenly distributed vertices?
It sounds like you want to do something like this:
1) First generate a triangulate your polygon to create a mesh. There are plenty of options: https://en.wikipedia.org/wiki/Polygon_triangulation
2) Then while any of the edges in the mesh are too long (meaning that the points at either end might be too far apart), add the midpoint of the longest edge to the mesh, dividing the adjacent triangles into 2.
The results is a mesh with every point within a limited distance of other points in every direction. The resulting mesh will not necessarily be optimal, in that it may have more points than are strictly required, but it will probably satisfy your needs.
If you need to reduce the number of points and thin triangles, you can apply Delaunay Triangulation flipping around each candidate edge first: https://en.wikipedia.org/wiki/Delaunay_triangulation#Visual_Delaunay_definition:_Flipping
Although not totally clear from the question, the marching cubes algorithm, adapted to two dimensions, comes to mind. A detailed descriptione of the two-dimensional version can be found here.
Delaunay meshing can create evenly distributed vertices inside a shape. The image below shows a combined grid- and Delaunay-mesh. You may have a look here.

Polygon adding algorithm

I want to do the following: I have some faces in the 3D space as polygons. I have a projection direction and a projection plane. I have a convex clipping polygon in the projection plane. I wnat to get a polygon representing the shaddow of all the faces clipped on the plane.
What I do till now: I calculate the projections of the faces as polygons in the projection plane.
I could use the Sutherland–Hodgman algorithm to clip all the singe projected polygons to clip to the desired area.
Now my question: How can I combine the projected (maybe clipped) polygons together? Do I have to use algorithms like Margalit/Knott?
The algorithm should be quite efficient because it has to run quite often. So what algorithm do you suppose?
Is it maybe possible to modify the algorithm of Sutherland–Hodgman to solve the merging problem?
I'm currently implementing this algorithm (union of n concave polygons) using Bentley–Ottmann to find all edge intersections and meanwhile keeping track of the polygon nesting level on both sides of edge segments (how many overlapping polygons each side of the line is touching). Edges that have a nesting level of 0 on one side are output to the result polygon. It's fairly tricky to get done right. An existing solution with a different algorithm design can be found at:
http://sourceforge.net/projects/polyclipping/

Generating quadrilateral mesh from Mathematica surface mesh

I am trying to make a quadrilateral mesh from a surface mesh (which is mostly triangular) generated by Mathematica. I am not looking for high quality mesher but a simple work around algorithm. I use GMSH for doing it externally. We can make use of Mathematic's CAD import capabilities to generate 3D geometries that are understood by the Mathematica kernel.
We can see the imported Geometry3D objects and the plots of number of sides in each polygons they consist of. It become visible that the polygons that form the mesh are not always triangles.
Name3D=RandomChoice[ExampleData["Geometry3D"][[All,2]],6];
AllPic=
Table[
Vertex=ExampleData[{"Geometry3D",Name3D[[i]]},"VertexData"];
Polygons=ExampleData[{"Geometry3D",Name3D[[i]]},"PolygonData"];
GraphicsGrid[
{{ListPlot[#,Frame-> True,PlotLabel->Name3D[[i]] ]&#(Length[#]&/#Polygons),
Graphics3D[GraphicsComplex[Vertex,Polygon[Polygons]],Boxed-> False]}}
,ImageSize-> 300,Spacings-> {0,0}],
{i,1,Length#Name3D}];
GraphicsGrid[Partition[AllPic,2],Spacings-> {0,0}]
Now what I am looking for is an algorithm to form a quadrilateral mesh from that polygon information available to MMA. Any easy solution is very much welcome. By easy solution I mean which is not going to work in a very general setting (where mesh constitutes of polygons with sides more than 5 or 6) and which might be quite inefficient compared to commercial software. But one can see that there are not many quadrilateral surface mesh generator available other than few expensive commercial one.
BR
this will produce quads regardless of the input topology:
insert one vertex in the center of each face
insert one vertex at the midpoint of each edge
insert edges connecting each face's center vertex with it's edges' midpoint vertices

Merge overlapping triangles into a polygon

I've got a bunch of overlapping triangles from a 3D model projected into a 2D plane. I need to merge each island of touching triangles into a closed, non-convex polygon.
The resultant polygons shouldn't have any holes in them (since the source data doesn't).
Many of the source triangles share (floating point identical) edges with other triangles in the source data.
What's the easiest way to do this? Performance isn't particularly important, since this will be done at design time.
Try gpc, or the General Polygon Clipper Library.
Imagine the projection onto a plane as a "view" of the model (i.e. the direction of projection is the line of sight, and the projection is what you see). In that case, the borders of the polygons you want to compute correspond to the silhouette of the model.
The silhouette, in turn, is a set of edges in the model. For each edge in the silhouette, the adjacent faces will have normals that either point away from the plane or toward the plane. You can check this be taking the dot product of the face normal with the plane normal -- look for edges whose adjacent face normals have dot products of opposite signs with the projection direction.
Once you have found all the silhouette edges you can join them together into the boundaries of the desired polygons.
Generally, you can find more about silhouette detection and extraction by googling terms like mesh silouette finding detection. Maybe a good place to start is here.
I've also found this[1] approach, which I will be trying next.
[1] 2d outline algorithm for projected 3D mesh

Resources