# Find if a node is on a given border

**URL:** https://community.freefem.org/t/find-if-a-node-is-on-a-given-border/1928
**Category:** General Discussion
**Created:** [August 3, 2022, 12:44am UTC](https://community.freefem.org/t/find-if-a-node-is-on-a-given-border/1928 "2022-08-03T00:44:35Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![larismartins](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/larismartins/32/2712_2.png) [@larismartins](https://community.freefem.org/u/larismartins)
#### Post date: [August 3, 2022, 12:44am UTC](https://community.freefem.org/t/find-if-a-node-is-on-a-given-border/1928/1 "2022-08-03T00:44:35Z")

</div>

Hello,  
I’ve built a mesh using the border function

```auto
border f0(t=0,1){P.x=nodes(1,0)*t + nodes(0,0)*(1-t);P.y=nodes(1,1)*t + nodes(0,1)*(1-t); label=11;};
 border f1(t=0,1){P.x=nodes(2,0)*t + nodes(1,0)*(1-t);P.y=nodes(2,1)*t + nodes(1,1)*(1-t); label=22;};
 border f2(t=0,1){P.x=nodes(0,0)*t + nodes(2,0)*(1-t);P.y=nodes(0,1)*t + nodes(2,1)*(1-t); label=33;};

```

Now, I have a vector or coordinates and I would like to find if a certain coord belogs to one of the borders f0, f1 or f2.

How can I do this?

---

<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: [August 3, 2022, 10:04am UTC](https://community.freefem.org/t/find-if-a-node-is-on-a-given-border/1928/2 "2022-08-03T10:04:38Z")

</div>

The problem is some node ca be on 2 border.

but P1 finite element function is def on vertices of mesh,

so on mesh Th,

```auto
  fespace Vh(Th,P1):;
 varf von11(u,v) = on(11,u=1); // set 1 on border 1 
 Vh u11; u11[]=von11(0,Vh);

// now u11[][i] == 1 if the vertex i is on border 11.

```

---

<div class="post-metadata">

### Author: ![larismartins](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/larismartins/32/2712_2.png) [@larismartins](https://community.freefem.org/u/larismartins)
#### Post date: [August 3, 2022, 10:02pm UTC](https://community.freefem.org/t/find-if-a-node-is-on-a-given-border/1928/3 "2022-08-03T22:02:58Z")

</div>

Actually, I’m working with P1Edge and I know the coordinates for those degrees of freddom. Then, I would like to know which border they belong to

---

<div class="post-metadata">

### Author: ![larismartins](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/larismartins/32/2712_2.png) [@larismartins](https://community.freefem.org/u/larismartins)
#### Post date: [August 3, 2022, 10:06pm UTC](https://community.freefem.org/t/find-if-a-node-is-on-a-given-border/1928/4 "2022-08-03T22:06:38Z")

</div>

```auto
func Pm = P1edge; 
fespace LambdaH(calP, Pm);

```

```auto
real[int, int] coordDofLambda(nDoFl0K,2);
 
 for(int i=0; i<nDoFl0K; i++){
 for(int j=0;j<nDoFl0;j++){
   if(locationMatrix(K,i) = j){
    coordDofLambda(i,0) = coordDoFl0(i,0);
    coordDofLambda(i,1) = coordDoFl0(i,1);
   }
  }
 }
 //cout << coordDofLambda << "\n";

```

```auto
border f0(t=0,1){P.x=nodes(1,0)*t + nodes(0,0)*(1-t);P.y=nodes(1,1)*t + nodes(0,1)*(1-t); label=11;};
 border f1(t=0,1){P.x=nodes(2,0)*t + nodes(1,0)*(1-t);P.y=nodes(2,1)*t + nodes(1,1)*(1-t); label=22;};
 border f2(t=0,1){P.x=nodes(0,0)*t + nodes(2,0)*(1-t);P.y=nodes(0,1)*t + nodes(2,1)*(1-t); label=33;};

 Th[K] = buildmesh(f0(1) + f1(1) + f2(1));
 Th[K] = trunc(Th[K], abs(u0 -K) < 1e-5, split=subMesh);

 int NbTrianglesLocal = Th[K].nt;
 int[int] localLabels = [22,33,11];

```

So, given the coords in coordDofLambda, I would like to know which border they belong to

---

<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: [August 6, 2022, 2:08pm UTC](https://community.freefem.org/t/find-if-a-node-is-on-a-given-border/1928/5 "2022-08-06T14:08:16Z")

</div>

to get the coordinate and the label of each dof of the P1edge Finite Element you can do:

```auto
mesh Th=square(2,2);

func Pm = P1edge; 
fespace Lh(Th, Pm);

varf von(u,v) = on(1,2,3,4,u=label);
Lh onl,xl=x,yl=y;
onl[]=von(0,Lh,tgv=1); // to have the labelof the dof.
cout << onl[] <<endl; 

cout << xl[] << " " << yl[]<< endl;

// xl[] , yl[] the coordinitae of dof
// onl[] the label of dot 

```
