Problem: Find the 3d convex hull of a spatial set of points
A 3d convex hull encloses a spatial point set with a minimal surface area. The following example generates random points in the unit cube and then computes the convex hull of these points.
Coplanar facets are not merged. Consequently, the 3d convex hull will always consist of triangles.
Solution using G#
- public static void ConvexHullExample()
- {
- // Generate some points in the unit cube
- PointSet ps = SamplePoints.RandomInCube(1000, 1, 1, 1);
- // Instantiate a 3d convex hull
- // Assign the initial point set
- ch.InitialPoints = ps;
- // Compute the 3d convex hull in O(n*log(n)) time
- ch.ComputeHull();
- // Get the triangles forming the hull
- List<Triangle> triangles = ch.Triangles;
- // visualize: ----------------------------------------------------
- // Make a scene
- // Set the point style
- sc.PointDisplayMode = 0;
- sc.PointSize = 0;
- // Make a layer for the triangles
- // Make a layer for the initial points
- // Make a layer for the vertices on the hull
- // Add the hull to the scene
- sc.Add(triangles, tLayer);
- sc.Add(ch.InitialPoints, ipLayer);
- sc.Add(ch.Vertices, hpLayer);
- // Output the scene as dxf
- sc.WriteDxf(@"c:\hull.dxf");
- }


