# How to get external boundary from multiple overlapping meshes?

**URL:** <https://community.freefem.org/t/how-to-get-external-boundary-from-multiple-overlapping-meshes/3855>\
**Category:** General Discussion\
**Created:** [April 11, 2025, 7:55am UTC](https://community.freefem.org/t/how-to-get-external-boundary-from-multiple-overlapping-meshes/3855 "2025-04-11T07:55:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![AJMC2002](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/ajmc2002/32/3098_2.png) [@AJMC2002](https://community.freefem.org/u/AJMC2002)\
**Post date:** [April 11, 2025, 7:55am UTC](https://community.freefem.org/t/how-to-get-external-boundary-from-multiple-overlapping-meshes/3855/1 "2025-04-11T07:55:17Z")

</div>

I’m generating individual meshes for rectangular pipes (using `square(...)`) and combining them with `+`. I’d like to extract the external boundary of the union of these meshes to create a mesh without internal overlaps or duplicated boundaries. Is there a recommended way to do this, or do I need to reconstruct everything from `border` definitions?

```auto
real L = 10.0; // vertical pipe
real H = 8.8; // horizontal pipe
real framed = 0.0635; // frame pipe dia. (2.5 in)
real branchd = 0.0254; // branch pipe dia. (1 in)
real spacing = 2.5; // distance between branch centers
real offset = 1.25; // distance from top-bot to first-last branch

int nbranches = int((L - 2*offset)/spacing) + 1;

func mesh addrect(real a, real b, real w, real h) {
    int nx = 10;
    int ny = 10;
    return square(nx, ny, [a + w*x, b + h*y]);
}

mesh Th = addrect(0, 0, H, framed); // bottom
Th = Th
    + addrect(0, L - framed, H, framed) // top
    + addrect(0, 0, framed, L) // left
    + addrect(H - framed, 0, framed, L); // right

for (int i = 0; i < nbranches; ++i) {
    real ypos = offset + i * spacing;
    Th = Th + addrect(0, ypos - branchd/2, H, branchd);
}

plot(Th, wait=1, cmm="Piping mesh");

```
