TriangleSetTriangleAreas[expr,areas]
constrains triangle areas for refinement.
TriangleSetTriangleAreas
TriangleSetTriangleAreas[expr,areas]
constrains triangle areas for refinement.
Details and Options
- To use TriangleSetTriangleAreas, you first need to load it using Needs["TriangleLink`"].
- TriangleSetTriangleAreas constrains the triangle area in a refinement of a Triangle instance.
Examples
Basic Examples (1)
To use TriangleLink, it must first be loaded:
Needs["TriangleLink`"]You start by specifying the coordinates and displaying them:
pts = {{0., 0.}, {1., 0.}, {1., 1.}, {0., 1.}};Graphics[{Red, PointSize[0.02], Point[pts]}]Then you create the input instance and set the points:
inInst = TriangleCreate[]TriangleSetPoints[inInst, pts]Next, the list of segments is created:
segments = {{1, 2}, {2, 3}, {3, 4}, {4, 1}};Graphics[GraphicsComplex[pts, Line[segments]]]Set the segments in the input instance of Triangle:
TriangleSetSegments[inInst, segments]Triangulate the input with an area constraint:
outInst = TriangleTriangulate[inInst, "pqa0.01"]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]]]To compute the area of each of the triangles of the object, you write a support function first:
TriangleArea[{c1_, c2_, c3_}] := 1 / 2 * Det[Transpose[{c1, c2}] - c3];TriangleArea = Compile[{{coords, _Real, 2}, {elements, _Integer, 1}},
Block[{p1, p2, p3},
{p1, p2, p3} = coords[[elements]];
1 / 2 * Det[Transpose[{p1, p2}] - p3]
]
, RuntimeAttributes -> {Listable}, RuntimeOptions -> "Speed"
];The area of each triangle can then be computed in the following manner:
coords = TriangleGetPoints[outInst];
meshElements = TriangleGetElements[outInst];
Short[area = TriangleArea[coords, meshElements]]The total area can then be computed:
Total[area]To refine some triangles, choose a selection of coordinates. For example, all coordinates where the
component is larger than 0.7:
selection = Flatten[Position[coords, _ ? (#[[1]] ≥ 0.7&), {1}, Heads -> False]]The refinement elements are then found:
refine = Flatten[Position[meshElements, _ ? (MemberQ[#, Alternatives@@selection]&), {1}, Heads -> False]]The triangles that should not change during refinement are the complement of all triangles and the triangle selected for refinement:
fixed = Complement[Range[Length[meshElements]], refine];Each triangle that is to be refined gets a new area assigned. Those triangles that should remain unchanged are assigned a
:
area[[refine]] = area[[refine]] / 4;
area[[fixed]] = -1.;Set a Triangle instance with the new triangle areas:
TriangleSetTriangleAreas[outInst, area]By specifying the string "r", the Triangle instance is refined. The string "a" implies that volume constraints are to be fulfilled:
outInst2 = TriangleTriangulate[outInst, "qra"]coords = TriangleGetPoints[outInst2];
meshElements = TriangleGetElements[outInst2];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]]]