0
votes

I'm trying to detect and handle collision between several circular objects with irregular shape.

enter image description here

I assume, that I have to use the pixel-perfect collision detection. Am I right (I suppose it is not very efficient)?

But how to calculate the results of collision? I want to simulate "bounce" of object.

enter image description here

It is easy to calculate a "bounce" angle with regular shape. But in such case? How to proceed? Is there any well known approach?

1

1 Answers

2
votes

Any algorithm handling collision needs to work with a precise definition of the curve itself, instead of just its pixel format, which is not vectorized and cannot be stretched or transformed properly on 2D space anyway.

In the 3D world, typical approach is to divide all surfaced into triangles. So to compute collision it's equivalent to compute the distance of the center of the circle to each triangle, which has well established algorithm and math representation. Now to reduce this into 2D, I'd argue that you need to

  1. Translate your arbitrary shape efficiently into connected straight lines
  2. Compute the distance of the center to each straight line

to determine collision. Note in this way you can also nicely handle the bounce case, where the collide-in angle == bounce-out angle.

There are several ways to accelerate this process. A common way is to round each part of the irregular shape into a "circle" (2D) or "sphere (3D). If the outer circle/sphere isn't colliding with your circle, the lines contained in it wouldn't be, either.

You could read computer graphics to know more about such stuff.