# Distance Checking of Static Objects

**URL:** <https://discourse.processing.org/t/distance-checking-of-static-objects/17519>\
**Category:** Coding Questions\
**Created:** [February 2, 2020, 11:13pm UTC](https://discourse.processing.org/t/distance-checking-of-static-objects/17519 "2020-02-02T23:13:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zavierboyles](https://avatars.discourse-cdn.com/v4/letter/z/b5a626/32.png) [@zavierboyles](https://discourse.processing.org/u/zavierboyles)\
**Post date:** [February 2, 2020, 11:13pm UTC](https://discourse.processing.org/t/distance-checking-of-static-objects/17519/1 "2020-02-02T23:13:42Z")

</div>

Hi. I’m trying to draw an array of 9 flowers in such a way that there is no overlap and the centres are on within the boundaries of the canvas.  
I’ve come up with a method so that the flowers are at least spawning far enough away from the previous flower in the array. My only problem now is how to check the currently generating flower against all the other flowers in the array that have been generated so far. This function is essentially a pregeneration in setup() where the actual drawing is done later in draw() using buttonPressed.

```auto
float randomAngle;
float randomMultiplier;

void spawnFlowers() {
  flowers[0] = new Flower(int(random(3, 11)), width/2, height/2);
  for (int i = 1; i < flowers.length; i++) {
    randomAngle = random(0, TWO_PI);
    randomMultiplier = random(2, 4);
    float x = flowers[i-1].x + randomMultiplier*flowers[i-1].radius*cos(randomAngle);
    float y = flowers[i-1].y + randomMultiplier*flowers[i-1].radius*sin(randomAngle);
    while (x < 0 || x > width || y < 0 || y > height) { //Check if flower is within canvas boundary
      randomAngle += PI/18;
      x = flowers[i-1].x + randomMultiplier*flowers[i-1].radius*cos(randomAngle);
      y = flowers[i-1].y + randomMultiplier*flowers[i-1].radius*sin(randomAngle);
    }
    flowers[i] = new Flower(int(random(3, 11)), x, y);
    showing[i] = 0;
  }
}

```

---

<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:** [February 4, 2020, 8:34am UTC](https://discourse.processing.org/t/distance-checking-of-static-objects/17519/2 "2020-02-04T08:34:26Z")

</div>

To check you need a new function and for loop over all other positions so far

Use dist() command- see reference
