# Save data from TriangulateMesh

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]
´´´


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}} *)

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]];


True

Graphics[{RandomColor[], #} & /@ MeshPrimitives[tm, 2]]

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