4
$\begingroup$

Is it possible to extract the coordinates from each triangle after using TriangulateMesh? It sounds very weird but i really need it for one of my projects. I have to save each triangle separately in a txt file.

pts = {{-5, 29.6537}, {-4, 16.3031}, {-3, 13.8614}, {-2, 
    9.22332}, {-1, 6.89646}, {0, 6.76047}, {1, 9.20436}, {2, 
    6.65919}, {3, 18.2084}, {4, 18.9102}, {5, 31.6521}};

Show[TriangulateMesh[Polygon[pts], 
  MaxCellMeasure -> {"Area" -> Infinity}], Axes -> True, 
 AspectRatio -> 1/GoldenRatio]
´´´
$\endgroup$
4
$\begingroup$

You could do something like this:

tm = TriangulateMesh[Polygon[pts], 
   MaxCellMeasure -> {"Area" -> Infinity}];
crd = MeshCoordinates[tm];
incidents = MeshCells[tm, 2] /. Polygon[inc_] -> inc;
tris = crd[[#]] & /@ incidents;
tris[[1]]
(* {{-2., 9.22332}, {1., 9.20436}, {2.34505, 10.6443}} *)
$\endgroup$
4
$\begingroup$
tm = TriangulateMesh[Polygon[pts], MaxCellMeasure -> {"Area" -> Infinity}];

You can also use MeshPrimitives to get the triangles and take first part of each to get the coordinates:

trianglecoords = MeshPrimitives[tm, 2][[All, 1]];

trianglecoords == tris (* tris from Tim Laska's answer *)
True
Graphics[{RandomColor[], #} & /@ MeshPrimitives[tm, 2]]

enter image description here

Graphics[{RandomColor[], Polygon@#} & /@ trianglecoords] 

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.