0
votes

I need the simplest solution for resolving 2D elastic collision between circles, each circle has equal mass with the others.

The environment is Android canvas in which the Y axis is growing towards down. Logic representation of the circle is class PlayerBall which has successful collision detection. PlayerBall has fields:

x and y position of center of the circle

velX and velY velocity vector of the circle movement represented as two scalar values which can be positive or negative.

diameter - diameter of the circle

public static void resolveCollision(PlayerBall ballOne, PlayerBall ballTwo) 
{
    double collisionAngle = Math.atan2(ballTwo.y - ballOne.y, ballTwo.x - ballOne.x); // angle for ball one
    // calculating new velocities between ballOne and ballTwo
    ...
    // setting the new velocities for both balls
    ballOne.setVelocity((float)ballOneVelX, (float)ballOneVelY);
    ballTwo.setVelocity((float)ballTwoVelX, (float)ballwTwoVelY);

}

I am expecting that velocities of the balls change according to formula defined in this article https://en.wikipedia.org/wiki/Elastic_collision#Two-dimensional_collision_with_two_moving_objects

1

1 Answers

1
votes

If you know the x and y velocity of both masses then you don't actually need the angle of collision. The resultant x and y forces on the balls can be calculated as a product of their respective masses, and velocities.

You can define this relationship by the formula:

V_xr1 = (V_x1 * (m1 - m2) + (2 * m2 * V_x2)) / (m1 + m1)

Where V_x1 represents the velocity purely in the x plane, m1 and m2 are the masses of the balls. This will give you the resultant x velocity. You can apply the same logic to calculate the resultant forces in the y direction.

let newVelX1 = (vel1.vX * (m1 - m2) + (2 * m2 * vel2.vX)) / (m1 + m2);
let newVelY1 = (vel1.vY * (m1 - m2) + (2 * m2 * vel2.vY)) / (m1 + m2);