# Building a border from an array of vertices

**URL:** <https://community.freefem.org/t/building-a-border-from-an-array-of-vertices/1253>\
**Category:** General Discussion\
**Created:** [October 12, 2021, 2:47pm UTC](https://community.freefem.org/t/building-a-border-from-an-array-of-vertices/1253 "2021-10-12T14:47:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![salah](https://avatars.discourse-cdn.com/v4/letter/s/977dab/32.png) [@salah](https://community.freefem.org/u/salah)\
**Post date:** [October 12, 2021, 2:47pm UTC](https://community.freefem.org/t/building-a-border-from-an-array-of-vertices/1253/1 "2021-10-12T14:47:52Z")

</div>

Hello FreeFEM Community,

In an attempt to perform some border surgery to get rid of kinks while moving domains I want to rebuild the border of a 2D mesh from a set of vertices (the connectivity of the border - the vertices causing problem). Is there a way to do this using FreeFem features? The closest thing I found in the documentation is the curve function which is used with isoline and can’t find enough details on it to understand its usage.

Thank you for your help.  
Salah

---

<div class="post-metadata">

**Author:** ![fivanci](https://avatars.discourse-cdn.com/v4/letter/f/e95f7d/32.png) [@fivanci](https://community.freefem.org/u/fivanci)\
**Post date:** [October 13, 2021, 1:00am UTC](https://community.freefem.org/t/building-a-border-from-an-array-of-vertices/1253/2 "2021-10-13T01:00:33Z")

</div>

Hi !  
Yes, if you have an **ordered** array of vertex coordinates, namely  
`(vx_0,vy_0),(vx_1,vy_1),...,(vx_n,vy_n)` where `(vx_0,vy_0)==(vx_n,vy_n)`  
in order to ensure that the loop is closed, you can reconstruct the loop (the border) as piecewise linear plane curve which has these vertices and in that order using `border(...)` and `buildmesh(...)`.

I cannot really find this in the documentation but I am sure I saw it somewhere (maybe somewhere in the `examples` in installation). Anyway, minimal working example might be something like

```auto
int nn=10;
real[int,int] vtxCoords(nn,nn); // double array of (x,y) vertex coordinates
// e.g., equidisntant points on circle (note, positive orientation)
for(int k=0; k<nn-1; ++k){
        vtxCoords(0,k) = cos(k*2*pi/(nn-1)); 
        vtxCoords(1,k) = sin(k*2*pi/(nn-1));
}
// to ensure loop is closed
vtxCoords(0,nn-1)=vtxCoords(0,0); 
vtxCoords(1,nn-1)=vtxCoords(1,0);

border bdry(t=0,vtxCoords.n-1){ P.x=vtxCoords(0,t); P.y=vtxCoords(1,t); label=1; };
plot(bdry(vtxCoords.n-1),dim=2,wait=1,cmm="boundary");
mesh Th = buildmesh(bdry(vtxCoords.n-1),fixedborder=true); 
plot(Th,wait=1,cmm="mesh");

```

_Note that you have to ensure positive orientation._ FYI, in `border(...){...}`, you can also add `P.z=...` if dealing with space curves, otherwise, `P.z=0` is assumed.

if

---

<div class="post-metadata">

**Author:** ![salah](https://avatars.discourse-cdn.com/v4/letter/s/977dab/32.png) [@salah](https://community.freefem.org/u/salah)\
**Post date:** [October 13, 2021, 8:02am UTC](https://community.freefem.org/t/building-a-border-from-an-array-of-vertices/1253/3 "2021-10-13T08:02:40Z")

</div>

Hello Fivanci,

Thank you so much for your reply and the working example! It works! and my mesh is kink free. I had no idea the command border is this powerful.

Thanks again, and have a good day ^^

Salah
