Building a border from an array of vertices

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.

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

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

border bdry(t=0,vtxCoords.n-1){ P.x=vtxCoords(0,t); P.y=vtxCoords(1,t); label=1; };
mesh Th = buildmesh(bdry(vtxCoords.n-1),fixedborder=true); 

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.


1 Like

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 ^^