Using TriangleLink
This section shows some of the ways that TriangleLink can be applied.
Convex Hull
To use TriangleLink, it must first be loaded.
Needs["TriangleLink`"]Next, some random points are generated and displayed.
data = RandomReal[{0, 1}, {100, 2}];
Graphics[Point[data]]Now you can compute the convex hull of the 3D points. TriangleConvexHull will return a list of points and segments.
{pts, segments} = TriangleConvexHull[data];Each segment is a list of two integers. These integers refer to the coordinates. You can plot them by using GraphicsComplex.
Graphics[GraphicsComplex[pts, Line[segments]]]Delaunay Triangulation
To use TriangleLink, it must first be loaded.
Needs["TriangleLink`"]data = RandomReal[{0, 1}, {100, 2}];You can compute the Delaunay triangulation of the data with TriangleDelaunay.
{pts, triangles} = TriangleDelaunay[data];The result is a list of points and triangles. The list of triangles is a list of three integers that refer to the coordinate positions. To visualize the triangle as a wireframe, you can use Polygon.
Graphics[GraphicsComplex[pts, {EdgeForm[LightDarkSwitched[Black, White]], FaceForm[], Polygon[triangles]}]]Meshing a Rectangle (Basic)
Needs["TriangleLink`"]First, an instance of a triangle expression is created.
inInst = TriangleCreate[]Next, coordinates and line segments are specified.
coords = {{0., 0.}, {1., 0.}, {1., 1.}, {0., 1.}};
segments = {{1, 2}, {2, 3}, {3, 4}, {4, 1}};
Graphics[GraphicsComplex[coords, Line[segments]]]These are then set into the triangle instance.
TriangleSetPoints[inInst, coords]TriangleSetSegments[inInst, segments]The actual triangulation is then done with TriangleTriangulate and a set of string parameters (Triangle string codes).
outInst = TriangleTriangulate[inInst, "pq30a0.01"]The data can be extracted from the triangle instance.
rawCoords = TriangleGetPoints[outInst];
Length[rawCoords]
incidents = TriangleGetElements[outInst];
Length[incidents]A visualization of the triangle mesh.
Graphics[ {EdgeForm[LightDarkSwitched[Black, White]], FaceForm[], GraphicsComplex[rawCoords, Polygon[incidents]]}]