BlueThen commented on a Page, Canvas Balls  -  Nov 23, 2012

Conscious: Each cell in the grid would be the width and height of the largest ball's diameter. Then, you check the ball against the balls contained in each cell adjacent to the one it's in.

My ~2 year old Balls applet has an array for each ball that keeps track of which balls they've collided with. It can probably be more efficient to iterate over the balls, and check against balls you haven't already iterated against.

For example:

for (int i = 0; i < ballCount; i++) {
  for (int c = i+1; c < ballCount; c++) {
    // check ball i against ball c

Although, that's probably not as easy using a partitioning algorithm. Perhaps if you only checked against Balls with higher ID's/indexes in the main array?

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.