# Quarter a given triangular meshregion

For a given , examplary simple, triangular meshregion

<< NDSolveFEM
pts = {{0, 0}, {1, 0}, {1, .2}, {.2, .2}, {.2, 1}, {0, 1}};
mreg = MeshRegion@ToElementMesh["Coordinates" -> pts,"MeshElements" -> {TriangleElement[{{1, 2,4}, {2, 3, 4}, {1, 4, 6}, {4, 5, 6}}]}]


I would like to refine the mesh in such way, that every triangle, using the side midpoints, is splitted into four new triangle elements.

Sounds simple, but I couldn't solve this example for a "concave" region.

How to solve this problem? Thanks!

• You can also make a second order mesh an then connect the second order element incidents to 4 first order Elements. Another alternative is to use the mesh refinement function. Apr 11 at 5:29
• @user21 Thanks, I tried MeshRefinementFunction but didn't succeed. My goal is to keep the original mesh. Apr 11 at 6:03

There is probably a more efficient way. Just out for a Sunday drive:

mcoords = MeshCoordinates[mreg];
mdpts = MeshCells[mreg, 1] /. Line -> Line@*Sort;
mtri = MeshCells[mreg, 2];
newcoords = Block[{Line = Mean@mcoords[[#]] &}, mdpts];
mp2i = mdpts ->
Range[1 + Length@mcoords, Length@mcoords + Length@mdpts] // Thread;
newtri =
mtri /.
Polygon[pts_] :>
Append[
Polygon[{#[[1]], Line@Sort@{#[[1]], #[[2]]},
Line@Sort@{#[[3]], #[[1]]}}] & /@
NestList[RotateLeft, pts, 2],
Polygon[Line@*Sort /@ Partition[pts, 2, 1, 1]]] /. mp2i //
Flatten;
{mreg, MeshRegion[Join[mcoords, newcoords], newtri]}


• Thank you very much. Probably I need some time to undestand your code. Hope I didn't disturb your sunday trip to much, have a nice day... Apr 10 at 17:29
• @UlrichNeumann :) I symbolically represent the midpoint of each Line by the Line itself. (The Line@*Sort puts the points in a canonical order, so that ReplaceAll can be used later.) The Line elements are then mapped to coordinates of the midpoints (newcoords) and the new indices of those coordinates (md2i). Then we construct the new triangles more or less by hand: Each vertex becomes a triangle with the adjacent midpoints, and the triangle of the midpoints is appended. Apr 10 at 17:45
• Very clever approach, have to elaborate... Thanks Apr 10 at 20:10