Open main menu

CDOT Wiki β

10th Floor/programming

Revision as of 15:32, 8 October 2010 by Corey Angus (talk | contribs) (sphere collision)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Collision

  • Sphere to Sphere collision
    • Each sphere is described by an x and y co-ordinate located in the very center, as well as a radius.
    • If the distance between each sphere is less than the sum of their radius's, then a collision has occurred.

Sphere to Sphere Collision

int collision_sphere (x_sphere1, y_sphere1, r_sphere1, x_sphere2, y_sphere2, r_sphere2){
  int collision = 0;
  double distance = √(x_sphere1 - x_sphere2)² + (y_sphere1 - y_sphere2)²; // calculate distance
  if ((r_sphere1 + r_sphere2) > distance){ // compare to sum of radius
    collsion = 1;
  }
  return collsion;
}