# Using arrays to create a node and edge connector

**URL:** <https://discourse.processing.org/t/using-arrays-to-create-a-node-and-edge-connector/14464>\
**Category:** Coding Questions\
**Created:** [October 6, 2019, 12:20pm UTC](https://discourse.processing.org/t/using-arrays-to-create-a-node-and-edge-connector/14464 "2019-10-06T12:20:51Z")\
**Posts on this page:** 1\
**Showing post:** 19

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 29, 2019, 10:26pm UTC](https://discourse.processing.org/t/using-arrays-to-create-a-node-and-edge-connector/14464/19 "2019-10-29T22:26:10Z")

</div>

> [@johnsmith17](#):
>
> im trying to make each node connect to the nearest grid intersection

SEARCH the minimum, store it , then display it

```auto
 //Desenhar as Linhas
        else if(fase==2){
          for(int i = 0; i < listc1.size(); i++){
            minDist = 10000000;
            for(int j = 0; j < listc2.size(); j++){
              PVector vi = listc1.get(i);
              PVector vj = listc2.get(j);
                if(vi.dist(vj) < minDist){
                  minDist = vi.dist(vj);
                  linhaI = i;
                  linhaF = j;
                }
            }
          
          PVector vi = listc1.get(linhaI);
          PVector vj = listc2.get(linhaF);
          stroke(0);
          line(vi.x,vi.y,vj.x,vj.y);
          }
      fase++;
      cfase3++;
    }

```

> [@Limiting draw() to run a limited amount of times!](https://discourse.processing.org/t/limiting-draw-to-run-a-limited-amount-of-times/14809/18):
>
> Just changed i and j place haha Don’t know if it’s the best solution, but hey, it works! Edit: Did the auto-format thing :3 PVector v1, v2; //C = Comprimento, A = Altura int qc1, qc2; float c1 = 6, a1 = 6, c2 = 2, a2=2; ArrayList\<PVector\> listc1 = new ArrayList(); ArrayList\<PVector\> listc2 = new ArrayList(); int fase = 0, cfase1 = 0, cfase2 = 0, cfase3 = 0; float minDist = -100; int linhaI, linhaF; void setup() { size(200, 200); background(255); //Quantidade de Circulos Principais qc1…

---

_[View the full topic](https://discourse.processing.org/t/using-arrays-to-create-a-node-and-edge-connector/14464)._
