Friday, 23 August 2013

Efficient collision detection between balls (ellipses)

Efficient collision detection between balls (ellipses)

I'm running a simple sketch in an HTML5 canvas using Processing.js that
creates "ball" objects which are just ellipses that have position, speed,
and acceleration vectors as well as a diameter. In the draw function, I
call on a function called applyPhysics() which loops over each ball in a
hashmap and checks them against each other to see if their positions make
them crash. If they do, their speed vectors are reversed.
Long story short, the number of calculations as it is now is (number of
balls)^2 which ends up being a lot when I get to into the hundreds of
balls. Using this sort of check slows down the sketch too much so I'm
looking for ways to do smart collisions some other way.
Any suggestions? Using PGraphics somehow maybe?

No comments:

Post a Comment