# Create unstructured mesh region with specified discretisation of one border

**URL:** https://community.freefem.org/t/create-unstructured-mesh-region-with-specified-discretisation-of-one-border/2049
**Category:** General Discussion
**Created:** [October 9, 2022, 4:11pm UTC](https://community.freefem.org/t/create-unstructured-mesh-region-with-specified-discretisation-of-one-border/2049 "2022-10-09T16:11:55Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Flavio](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/flavio/32/1178_2.png) [@Flavio](https://community.freefem.org/u/Flavio)
#### Post date: [October 9, 2022, 4:11pm UTC](https://community.freefem.org/t/create-unstructured-mesh-region-with-specified-discretisation-of-one-border/2049/1 "2022-10-09T16:11:55Z")

</div>

Hi,

I am trying to mesh a 2D rectangular region with unstructured elements but I would like to specify a distribution of grid points along one border.

I havve created the border and am using the `buildmesh` command. However, I can see that this command calls for an integer, i.e. the number of segments to discretise the border. How can I input an array containing the coordinate locations of the grid points? I have seen this is possible with the `square` command but that is for structured meshes.

thank you for your help

---

<div class="post-metadata">

### Author: ![aszaboa](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/aszaboa/32/2918_2.png) [@aszaboa](https://community.freefem.org/u/aszaboa)
#### Post date: [October 10, 2022, 5:30am UTC](https://community.freefem.org/t/create-unstructured-mesh-region-with-specified-discretisation-of-one-border/2049/2 "2022-10-10T05:30:57Z")

</div>

The keyword `triangulate` allows you to create a mesh from a given set of point. I think you could combine `buildmesh`+`triangulate`: create a mesh using `buildmesh`, throw away the point at the boundary, set them to the value you want, and create the final mesh with `triangulate`.

---

<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: [October 10, 2022, 8:40am UTC](https://community.freefem.org/t/create-unstructured-mesh-region-with-specified-discretisation-of-one-border/2049/3 "2022-10-10T08:40:36Z")

</div>

Please have a look to the following code, I think this is what you are looking for…

> int Npts = 100 ;  
> // Number of points on the perimeter  
> int nBPTS = 6;  
> real[int,int] BPts(nBPTS,2);// Array of information about the border  
> // BPts(i,0) x-coordinate  
> // BPts(i,1) y-coordinate  
> int[int] Labels(nBPTS); // Labels  
> BPts(0,0) = 0.0 ; BPts(0,1)=0.0; Labels[0] = 0;  
> BPts(1,0) = 0.40; BPts(1,1)=0.0; Labels[1] = 0;  
> BPts(2,0) = 1.0 ; BPts(2,1)=1.0; Labels[2] = 0;  
> BPts(3,0) = 0.0 ; BPts(3,1)=2.0; Labels[3] = 0;  
> BPts(4,0) = -1.0; BPts(4,1)=1.0; Labels[4] = 0;  
> BPts(5,0) = -0.5; BPts(5,1)=0.1; Labels[5] = 0;  
> //  
> real[int] length(BPts.n); int[int] ptsArr(BPts.n);  
> real perim=0.0;  
> //  
> for(int ii=0; ii\<BPts.n; ii++){ int ie = (ii==BPts.n-1? 0: ii+1);  
> length[ii] = sqrt( (BPts(ie,0)-BPts(ii,0))^2 + (BPts(ie,1)-BPts(ii,1))^2 );  
> perim+=length[ii]; }  
> for(int ii=0; ii\<BPts.n; ii++) ptsArr[ii] = int(Npts\*length[ii]/perim);  
> //  
> border a(t=0,1;ii){ label=Labels[ii];  
> int ib = ii; int ie = (ib==BPts.n-1? 0: ib+1);  
> x = BPts(ib,0) + (BPts(ie,0)-BPts(ib,0))\*t ;  
> y = BPts(ib,1) + (BPts(ie,1)-BPts(ib,1))\*t ; }  
> //  
> mesh Th = buildmesh (a(ptsArr));  
> plot(Th);
