Examlpes

Problem: Find a rastered Delaunay triangulation of a projectable set of points

Consider the Delaunay triangulation of the previous example. Due to the random point generation on the surface of the starfish, the triangles also have a random shape.

You can easily re-triangulate the existing triangulation over an arbitrary rectangular raster. Use this feature not only to rasterize your point data but also to reduce the number of triangles.

Solution using D#

1.        public static void DelaunayRasteredExample()
2.         {
3.             // Create a sample point set
4.             PointSet ps = SamplePoints.SupershapeStarfish(10000);
5.
6.             // Instantiate a delaunay triangulation
7.             DelaunayTriangulation2d dt = new DelaunayTriangulation2d();
8.
9.             // Assign the point set to triangulate
10.             dt.TriangulationPoints = ps;
11.
12.             // Triangulate the point set
13.             dt.Triangulate();
14.
15.             // You may add points to the existing triangulation
16.             dt.AddPointToCurrentTriangulation(new Point(0.5, 0.5, 0));
17.
18.             // Rasterize the current triangulation in over 0.02x0.02-raster
19.             dt.RasterizeCurrentTriangulation(0.02, 0.02);
20.
21.             // Get the triangulation
22.             List<Triangle> triangles = dt.GetTriangles();
23.
24.             // visualize: ---------------------------------------------------
25.             // Make a scene
26.             Scene sc = new Scene();
27.
28.             // Set the point style
29.             sc.PointDisplayMode = 0;
30.             sc.PointSize = 0;
31.
32.             // Make a layer for the triangles
33.             Scene.Layer tLayer = new Scene.Layer("Delaunay_Triangles", 90);
34.
35.             // Make a layer for the triangulation points
36.             Scene.Layer pLayer = new Scene.Layer("Triangulation_Points", 1);
37.
38.             // Add the triangles and the triangulation points to the scene
39.             sc.Add(triangles, tLayer);
40.             sc.Add(dt.TriangulationPoints, pLayer);
41.
42.             // Output the scene as dxf
43.             sc.WriteDxf(@"c:\delaunay_rastered.dxf");
44.         }

Output

Rastered Delaunay triangulation of 10001 random points on a starfish supershape. The rastered triangulation only comprises 11882 triangles compared to 19986 triangles in the initial triangulation.
Partial top view on the rastered mesh.

<< back