# Extract border from 2D mesh

**URL:** <https://community.freefem.org/t/extract-border-from-2d-mesh/1806>\
**Category:** General Discussion\
**Created:** [June 10, 2022, 2:15pm UTC](https://community.freefem.org/t/extract-border-from-2d-mesh/1806 "2022-06-10T14:15:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bachnguyen0106](https://avatars.discourse-cdn.com/v4/letter/b/59ef9b/32.png) [@bachnguyen0106](https://community.freefem.org/u/bachnguyen0106)\
**Post date:** [June 10, 2022, 2:15pm UTC](https://community.freefem.org/t/extract-border-from-2d-mesh/1806/1 "2022-06-10T14:15:17Z")

</div>

Hi everyone,

I was trying to extract the border from a 2D mesh. The only function that i could find on the FreeFem Documentation is only applied for a 3D mesh (mesh3, extractborder). I hope someone could help me on this topic, i was trying to find the solution for a long time, the border that i want to extract could be from a simple square or maybe more difficult from a random shape. The reason i want to extract the border is to define the initial condition for a simulation of the traffic flow.

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![julienG](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/julieng/32/222_2.png) [@julienG](https://community.freefem.org/u/julienG)\
**Post date:** [June 12, 2022, 11:06am UTC](https://community.freefem.org/t/extract-border-from-2d-mesh/1806/2 "2022-06-12T11:06:07Z")

</div>

Maybe with an empty mesh: [see here](https://doc.freefem.org/references/functions.html#emptymesh)

---

<div class="post-metadata">

**Author:** ![bachnguyen0106](https://avatars.discourse-cdn.com/v4/letter/b/59ef9b/32.png) [@bachnguyen0106](https://community.freefem.org/u/bachnguyen0106)\
**Post date:** [June 13, 2022, 2:19pm UTC](https://community.freefem.org/t/extract-border-from-2d-mesh/1806/3 "2022-06-13T14:19:32Z")

</div>

Thank you but what i do really need was how to extract a part of the border, to set the initial limitation. For example it could be one edge of a square, half of the circle or random edge from a random shape. Because in my project, i already have the totally border extracted now all i need is just a part of it.

Thanks a lot for your help.

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [June 15, 2022, 1:00pm UTC](https://community.freefem.org/t/extract-border-from-2d-mesh/1806/4 "2022-06-15T13:00:42Z")

</div>

I think in curvature.edp example you get the good function:

```auto
curvature.edp:real l12=extractborder(Th,ll,b12);

```

see [FreeFem-sources/curvature.edp at master · FreeFem/FreeFem-sources · GitHub](https://github.com/FreeFem/FreeFem-sources/blob/master/examples/plugin/curvature.edp)

---

<div class="post-metadata">

**Author:** ![bachnguyen0106](https://avatars.discourse-cdn.com/v4/letter/b/59ef9b/32.png) [@bachnguyen0106](https://community.freefem.org/u/bachnguyen0106)\
**Post date:** [July 4, 2022, 2:09pm UTC](https://community.freefem.org/t/extract-border-from-2d-mesh/1806/5 "2022-07-04T14:09:40Z")

</div>

Thank you for your reponse, i have tried your code and try to apply it into my project, but it didn’t work in my case. Because in my project, the whole border was taken from a random picture. The problem here is there is no way to identify the label of the edge that we want to extract. The function ‘extractborder’ require label of the edge to be able to extract. I was thinking about using matrix to identify the label of the edge wanted but I didn’t find any informations about this on any documents. I hope you can help me solve this problem.

Thank you for your help

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [July 7, 2022, 7:01am UTC](https://community.freefem.org/t/extract-border-from-2d-mesh/1806/6 "2022-07-07T07:01:24Z")

</div>

I am sure they are a way to know with boudany to extract ot,hernies you problem, algorithm is not correct ,

You can sens directly tour problem and data to me, I will try.
