Click or drag to resize
DigitalRuneHow To: Create a Mesh of a Convex Hull

This section will demonstrate how to construct the convex hull of a cloud of points and convert the convex hull to a triangle mesh which can be rendered.

This topic contains the following sections:

Add DigitalRune namespaces

The following example will use data types and helper methods from DigitalRune Geometry and Mathematics. The following namespaces must be imported for this example at the beginning of the source code file:

C#
using DigitalRune.Geometry;
using DigitalRune.Geometry.Meshes;
using DigitalRune.Mathematics.Algebra;
using DigitalRune.Mathematics.Statistics;
Create random points

For the purpose of this example, we will create a cloud consisting of randomly placed points. The points will lie between (-100, -100, -100) and (100, 100, 100).

C#
List<Vector3F> points = new List<Vector3F>();
for (int i = 0; i < 100; i++)
  points.Add(RandomHelper.Random.NextVector3F(-100, 100));
Create convex hull

Next, we will build the convex hull of all points. GeometryHelper is an auxiliary class which can be used to create a convex hull from any collection of points (Vector3F).

C#
DcelMesh convexHull = GeometryHelper.CreateConvexHull(points);

The DcelMesh is a doubly-connected edge list. This is a data structure that is used to build or manipulate meshes. It defines the mesh's vertices, edges, and faces (not necessarily triangles).

The returned DcelMesh can be converted to a TriangleMesh which consists only of triangles - a representation suitable for rendering.

C#
TriangleMesh triangleMesh = convexHull.ToTriangleMesh();