# Interaction of objects parameters

**URL:** <https://discourse.processing.org/t/interaction-of-objects-parameters/4750>\
**Category:** Coding Questions\
**Created:** [October 22, 2018, 1:28pm UTC](https://discourse.processing.org/t/interaction-of-objects-parameters/4750 "2018-10-22T13:28:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![LizrichVonEinzbern08](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@LizrichVonEinzbern08](https://discourse.processing.org/u/LizrichVonEinzbern08)\
**Post date:** [October 22, 2018, 1:28pm UTC](https://discourse.processing.org/t/interaction-of-objects-parameters/4750/1 "2018-10-22T13:28:24Z")

</div>

```auto
Particle p;
Particle p1;

void setup(){
  //fullScreen();
  size(640,320);
  p = new Particle();
  p1 = new Particle();
}

void draw(){
  background(150);
  p.display();
  p1.display();
}
class Particle{
  float x = random(0, width);
  float y = random(0, height);
  float r = random(0,30);
  float xSpeed = 1;
  float ySpeed = 1;
  
  void display(){
    stroke(255);
    strokeWeight(5);
    ellipse(x,y,r,r);
    x =+ x + xSpeed;
    y =+ y + ySpeed;
    
    p.update(p1);
  }
  
  
  void update(Particle f1){
    float d = dist(x,y,f1.x, f1.y);
    
    if(d <= r + f1.r){
      if(f1.x == x){
        f1.x = -1 + f1.x;
      }else if(f1.y == y){
        f1.y = -1 * f1.y;
      }else if(x >= width){
        f1.x = -1 + f1.x;     
      }else if(f1.x >= width){
        f1.x = -1 + f1.x;  
      }else if(y >= height){
        f1.y = -1 * f1.y;      
      }else if(f1.y >= height){
        f1.y = -1 * f1.y;
      }
    }
  }
}

```

I was wondering how i could do the interaction of both ellipses to one another and with the environment can occur inside an object. P.S. I’m new here. 😉

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [October 22, 2018, 3:23pm UTC](https://discourse.processing.org/t/interaction-of-objects-parameters/4750/2 "2018-10-22T15:23:32Z")

</div>

What do you mean by interaction?

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [October 24, 2018, 5:22pm UTC](https://discourse.processing.org/t/interaction-of-objects-parameters/4750/3 "2018-10-24T17:22:30Z")

</div>

> [@LizrichVonEinzbern08](#):
>
> the interaction of both ellipses to one another

Do you mean ellipse-ellipse collision detection?

This is actually one of the few topics left out of Thompson’s collision guide…

…and the information out there on stackoverflow / math.stackexchange is very muddled. The key questions before we look at an answer:

1. are they ellipses, or are they circles (width = height).
2. what will they be colliding with, specifically – rectangles, circles…?
3. do you want to rotate them? ellipses are axis-aligned in Processing by default – and that is much easier to compute a collision for than an arbitrary rotated ellipse.
