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