Interaction of objects parameters

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. :wink:

What do you mean by interaction?

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.