#Circle collisions

1 messages · Page 1 of 1 (latest)

pine seal
#

I'm trying to simulate circles that have gravity and collide with each other. The gravity simulation works, but the collisions don't, and each of the circles that collide has NaN coordinates. This is my code that dolls with collisions:

autumn kelpBOT
#

<@&987246487241105418> please have a look, thanks.

tacit abyss
#

This code is overly complicated. Start breaking things up into smaller methods.

  public static boolean hasCollision(Circle a, Circle b){
    double dist = Math.hypot(a.center().x() - b.center().x(), a.center().y() - b.center().y());
    double minDist = a.radius() + b.radius();
    return dist <= minDist;
  }