For a given , examplary simple, triangular meshregion

<< NDSolve`FEM`
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}}]}]

enter image description here

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!

  • $\begingroup$ 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. $\endgroup$
    – user21
    Apr 11 at 5:29
  • $\begingroup$ @user21 Thanks, I tried MeshRefinementFunction but didn't succeed. My goal is to keep the original mesh. $\endgroup$ Apr 11 at 6:03

1 Answer 1


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_] :> 
       Polygon[{#[[1]], Line@Sort@{#[[1]], #[[2]]}, 
           Line@Sort@{#[[3]], #[[1]]}}] & /@ 
        NestList[RotateLeft, pts, 2], 
       Polygon[Line@*Sort /@ Partition[pts, 2, 1, 1]]] /. mp2i // 
{mreg, MeshRegion[Join[mcoords, newcoords], newtri]}

enter image description here

  • $\begingroup$ 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... $\endgroup$ Apr 10 at 17:29
  • $\begingroup$ @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. $\endgroup$
    – Michael E2
    Apr 10 at 17:45
  • $\begingroup$ Very clever approach, have to elaborate... Thanks $\endgroup$ Apr 10 at 20:10

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.