TriangleTriangulate[expr,settings]
triangulates a Triangle expression using settings and returns the result in a new Triangle expression.
TriangleTriangulate
TriangleTriangulate[expr,settings]
triangulates a Triangle expression using settings and returns the result in a new Triangle expression.
Details and Options
- To use TriangleTriangulate, you first need to load it using Needs["TriangleLink`"].
- The settings given to TriangleTriangulate are a string of different commands:
-
"p" triangulate a planar straight line graph (PLC) "q" quality mesh generation with no angles smaller than 20 degrees; an alternate minimum angle may be specified after the "q" "a" impose a maximum triangle area constraint; a fixed area constraint (that applies to every triangle) may be specified after the "a" "A" assign a regional attribute to each triangle that identifies what segment-bounded region it belongs to "c" enclose the convex hull with segments "D" conforming Delaunay: if all triangles in the mesh are to be Delaunay, not just constrained Delaunay, or if you want to ensure that all Voronoi vertices lie within the triangulation "r" refine a previously generated mesh "Y" prohibit the insertion of Steiner points on the mesh boundary; if specified twice ("YY"), it prohibits the insertion of Steiner points on any segment, including internal segments "S" specify the maximum number of added Steiner points "o2" generate second-order subparametric elements with six nodes each "C" check the consistency of the final mesh "Q" quiet: no terminal output except error - TriangleTriangulate has the following options:
-
"TriangleRefinement" None function to refine a triangle
Examples
open all close allBasic Examples (1)
Needs["TriangleLink`"]This creates an instance of a Triangle expression:
inst = TriangleCreate[]This sets up points and segments to use:
pts = {{0., 0.}, {2., 0.}, {2., 2.}, {0., 1.}};
segments = {{1, 2}, {2, 3}, {3, 4}, {4, 1}};This sets the points and facets in the Triangle instance:
TriangleSetPoints[inst, pts];
TriangleSetSegments[inst, segments];This carries out the triangulation, returning a new Triangle instance:
outInst = TriangleTriangulate[ inst, "pqa0.025"]This extracts the points and elements from the triangulation:
coords = TriangleGetPoints[outInst];
meshElements = TriangleGetElements[outInst];With the following support function, you can visualize the triangles:
TriangleWireframe[i_] := Line[ Flatten[ i[[All, #]]& /@ {{1, 2}, {2, 3}, {3, 1}}, 1]]Graphics[GraphicsComplex[coords, TriangleWireframe[meshElements]]]Options (1)
"TriangleRefinement" (1)
Needs["TriangleLink`"]This creates an instance of a Triangle expression:
inst = TriangleCreate[]This sets up points and segments to use:
pts = {{0., 0.}, {2., 0.}, {2., 2.}, {0., 1.}};
segments = {{1, 2}, {2, 3}, {3, 4}, {4, 1}};This sets the points and facets in the Triangle instance:
TriangleSetPoints[inst, pts];
TriangleSetSegments[inst, segments];This carries out the triangulation, returning a new Triangle instance:
outInst = TriangleTriangulate[ inst, "pq"]This extracts the points and elements from the triangulation:
coords = TriangleGetPoints[outInst];
meshElements = TriangleGetElements[outInst];With the following support function, you can visualize the triangles:
TriangleWireframe[i_] := Line[ Flatten[ i[[All, #]]& /@ {{1, 2}, {2, 3}, {3, 1}}, 1]]Graphics[GraphicsComplex[coords, TriangleWireframe[meshElements]]]This sets up a compiled function that returns True if a triangle should be refined and False otherwise:
cf = Compile[{{coordinates, _Real, 2}, {area, _Real, 0}},
Block[{c = coordinates, res, dxoa, dyoa, dxda, dyda, dxod, dyod, oalen, dalen, odlen, maxlen},
dxoa = c[[1, 1]] - c[[3, 1]];
dyoa = c[[1, 2]] - c[[3, 2]];
dxda = c[[2, 1]] - c[[3, 1]];
dyda = c[[2, 2]] - c[[3, 2]];
dxod = c[[1, 1]] - c[[2, 1]];
dyod = c[[1, 2]] - c[[2, 2]];
oalen = dxoa ^ 2 + dyoa ^ 2;
dalen = dxda ^ 2 + dyda ^ 2;
odlen = dxod ^ 2 + dyod ^ 2;
maxlen = If[dalen > oalen, dalen, oalen];
maxlen = If[oalen > maxlen, oalen, maxlen];
res = If[maxlen > 0.025 * (c[[1, 1]] ^ 2 + c[[1, 2]] ^ 2) + 0.02, True, False];
res]
];This carries out the triangulation with the refinement function, returning a new Triangle instance:
outInst2 = TriangleTriangulate[inst, "pq", "TriangleRefinement" -> cf]This extracts the points and elements from the triangulation:
coords = TriangleGetPoints[outInst2];
meshElements = TriangleGetElements[outInst2];Graphics[GraphicsComplex[coords, TriangleWireframe[meshElements]]]Neat Examples (1)
Use a black-and-white image as a refinement driver. Set an image, create a distance function, and visualize the distance function:
shape = [image];dist = DistanceTransform[Image[1 - ImageData[EdgeDetect[shape]]]];ImageAdjust@distCreate an InterpolatingFunction from the distance function:
data = Transpose[Reverse[-ImageData[dist] * (2 * ImageData[shape] - 1)]];
range = Transpose[{{1, 1}, Dimensions[data]}];
ifun = ListInterpolation[data, range, InterpolationOrder -> 1]Create and populate a Triangle instance:
inst = TriangleCreate[];
TriangleSetPoints[inst, Flatten[Outer[List, Sequence@@range], 1]];
TriangleSetSegments[inst, {{1, 3}, {3, 4}, {4, 2}, {2, 1}}];Set up a compiled function that calls the InterpolatingFunction:
cf = Compile[{{c, _Real, 2}, {area, _Real, 0}},
Block[{com},
com = Total[c] / 3;
If[area > Max[Abs[ifun[com[[1]], com[[2]]]], 2.5], True, False]
]
];This carries out the triangulation with the refinement function, returning a new Triangle instance:
outInst = TriangleTriangulate[inst, "pq", "TriangleRefinement" -> cf]This extracts the points and elements from the triangulation:
coords = TriangleGetPoints[outInst];
meshElements = TriangleGetElements[outInst];TriangleWireframe[i_] := Line[Flatten[ i[[All, #]]& /@ {{1, 2}, {2, 3}, {3, 1}}, 1]]
Graphics[GraphicsComplex[coords, TriangleWireframe[meshElements]], ImageSize -> Medium]Tech Notes
Related Guides
Text
Wolfram Research (2014), TriangleTriangulate, Wolfram Language function, https://reference.wolfram.com/language/TriangleLink/ref/TriangleTriangulate.html.
CMS
Wolfram Language. 2014. "TriangleTriangulate." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/TriangleLink/ref/TriangleTriangulate.html.
APA
Wolfram Language. (2014). TriangleTriangulate. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/TriangleLink/ref/TriangleTriangulate.html
BibTeX
@misc{reference.wolfram_2026_triangletriangulate, author="Wolfram Research", title="{TriangleTriangulate}", year="2014", howpublished="\url{https://reference.wolfram.com/language/TriangleLink/ref/TriangleTriangulate.html}", note=[Accessed: 15-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_triangletriangulate, organization={Wolfram Research}, title={TriangleTriangulate}, year={2014}, url={https://reference.wolfram.com/language/TriangleLink/ref/TriangleTriangulate.html}, note=[Accessed: 15-June-2026]}