# Draw borders using vectors

**URL:** <https://community.freefem.org/t/draw-borders-using-vectors/1799>\
**Category:** General Discussion\
**Created:** [June 6, 2022, 12:54pm UTC](https://community.freefem.org/t/draw-borders-using-vectors/1799 "2022-06-06T12:54:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aashish](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@Aashish](https://community.freefem.org/u/Aashish)\
**Post date:** [June 6, 2022, 12:54pm UTC](https://community.freefem.org/t/draw-borders-using-vectors/1799/1 "2022-06-06T12:54:56Z")

</div>

Hi Everyone,  
I am new at using FreeFem and could really use you help to understand the functionalities better  
i am working on the sample problem of electrostatics

[https://doc.freefem.org/models/static-problems.html#electrostatics](https://doc.freefem.org/models/static-problems.html#electrostatics)

I wanted to created the borders using the vector ex  
**border b(t=0, vectorX.n-1){P.x=vectorX[t]; P.y=vectorY[t];}**

Thanks

---

<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 7, 2022, 7:11am UTC](https://community.freefem.org/t/draw-borders-using-vectors/1799/2 "2022-06-07T07:11:37Z")

</div>

So border is to make continuous object, so you have to make linear interpolation like this (no tested)

```auto
 border bb(tt=0,xx.n-1) 
  {
   int i = min(int(tt),xx.n-2);
  real t = tt-i;   
  // i is the the index variable of the multi border loop 
    int ii = (i+1); real t1 = 1-t;
    cout << tt << " " << i << " " <<t << " / " << ii << endl;
    x = xx[i]*t1 + xx[ii]*t;
    y = yy[i]*t1 + yy[ii]*t;
    label = 0; 
  }

```

---

<div class="post-metadata">

**Author:** ![Aashish](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@Aashish](https://community.freefem.org/u/Aashish)\
**Post date:** [June 9, 2022, 12:16pm UTC](https://community.freefem.org/t/draw-borders-using-vectors/1799/3 "2022-06-09T12:16:21Z")

</div>

@frederichecht thanks for the reply  
Another quick question  
How are you defining xx and yy ?

Thanks

---

<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 10, 2022, 9:50am UTC](https://community.freefem.org/t/draw-borders-using-vectors/1799/4 "2022-06-10T09:50:18Z")

</div>

here I am lasy xx, and yy are yours vectors vectorX and vectorY

---

<div class="post-metadata">

**Author:** ![Aashish](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@Aashish](https://community.freefem.org/u/Aashish)\
**Post date:** [June 13, 2022, 8:12am UTC](https://community.freefem.org/t/draw-borders-using-vectors/1799/5 "2022-06-13T08:12:20Z")

</div>

No i understood that , what i was trying to ask was how you are defining the vectors ??

Because for border C0 which in example is defined as  
**border C0(t=0, 2_pi){x=5_cos(t); y=5\*sin(t);}**  
i am trying to generate the same structure by doing this -:  
real[int] vectorX0(7),vectorY0(7);

for(int t = 0;t\<2\*pi;t++){

cout\<\< “Value of t”\<\<t\<\<endl;

vectorX0[t] = 5_cos(t);  
vectorY0[t] = 5_sin(t);  
}

border C0(tt=0,vectorX0.n-1)  
{  
int i = (int(tt)%(vectorX0.n-1));  
real t = tt-i;  
// i is the the index variable of the multi border loop  
int ii = (i+1);  
real t1 = 1-t;  
x = vectorX0[i]\*t1 + vectorX0[ii]\*t;  
y = vectorY0[i]\*t1 + vectorY0[ii]\*t;  
label = 0;  
}

but it’s not forming the same circle shape as it was doing with the non-vector definition of border

is this correct way to generate the vector ??

---

<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, 12:47pm UTC](https://community.freefem.org/t/draw-borders-using-vectors/1799/6 "2022-06-15T12:47:21Z")

</div>

A full exemple to understand the small code

```auto
 real[int] xx(7),yy(7); 
 for(int t = 0;t<2*pi;t++){

 cout<< "Value of t "<<t<<endl;

 xx[t] = 5*cos(t);
 yy[t] = 5*sin(t);
 }

 
 border bb(tt=0,xx.n-1) 
  {
   int i = min(int(tt),xx.n-2);
  real t = tt-i;   
  // i is the the index variable of the multi border loop 
    int ii = (i+1); real t1 = 1-t;
    cout << tt << " " << i << " " <<t << " / " << ii << endl;
    x = xx[i]*t1 + xx[ii]*t;
    y = yy[i]*t1 + yy[ii]*t;
    label = 0; 
  }

  plot(bb(100));

```
