0
\$\begingroup\$

i am implementing a billiard simulation game and i have a question about collision response.

As integrator, i am using Semi-Implicit Euler,

ball.setVelocity(ball.getVelocity().add(ball.getAcceleration().multiply(dt)));
ball.setPosition(ball.getPosition().add(ball.getVelocity().multiply(dt)));

Before integrating, i am calculating acceleration :

this.setAcceleration(this.getForce().multiply(1 / this.getMass()));

dt is time frame here, and acceleration, velocity, force and position are Vector class. (operations as add, multiply... are standard vector operations).

My question is - when i initially hit ball with cue, i am giving force -k*x (Hooke's law) to ball. But when it collides with other ball, i can only find formulas that calculate new position and new velocity, but my force will stay same. But how to change force here in both balls (it will change velocity and position later in SE Euler).

I appreciate any answer!

\$\endgroup\$
1
\$\begingroup\$

You usually don't look at forces when trying to get the new velocity of an object after collision, since it's in the field of kinematics. You only need momentum.

The momentum of an object can be calculated using \$m \cdot v\$, where m is the mass and v is the velocity. Collisions are basically just momentum transferring from object A to B. The formulas can be pretty involving, but if you don't want to be that realistic about this, then you could simply transfer a constant amount (like 90%) of the momentum to simulate the effect. You can tweak this value if it doesn't feel right.

So, you'll basically need to do these steps for each ball involved in the collision separately:

  • Calculate the momentum of the current object.
  • Get the velocity difference of the current object and the other object, then multiply it by the mass of the other object.
  • If the result is larger, than the current momentum, then all of the momentum of the current object can be trabsferred into the other object, if it's smaller, then only as much as the result (think about it, if you throw a ball at a truck, then it will stop, so all of the momentum was transferred to the truck, but if the truck hits the ball, then it can't go faster, than the truck itself and the truck won't stop).
  • increase the momentum of the other object and decrease the momentum of the current object and calculate the speed from the new momentums (velocity = momentum / mass)
| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Most changes in velocity are computed instantaneously (which is a good approximation of how snooker balls behave in reality). The equations for your physics calculations should also never change position.

The physics of impact resolution only deals with changes in velocity, and for spheres, can be computed very easily:

When a collision is detected, compute the relative velocity(Vrel) for each ball involved:

Vrel = velB - VelA
contactVel = Vrel dot collisionNormal

This is used to: Compute the resultant impulse vector(J) which is :

e = min(Rest_a, Rest_b) //(Rest being how "bouncy" a ball is (should be close to 1))


J = -(1+e) * contactVel
J/= (Ma^-1 + Mb^-1)

Ja = J * collisionNormal
Jb = -Ja

VelA += Ja/Ma
VelB += Jb/Mb

Then later you do:

posA += VelA * dt;

There is no reason to change the position of a ball, during collision resolution, as an impulse is a third order differential, and as such must reduce itself to a second order differential in order to change position.

dx/dt = v (velocity is a 1st order differential)
dv/dt = a (acceleration is a second order)
da/dt = J (instantaneous Force(impulse) is 3rd order)
J/dt = F (force applied over 1 seconds).

Thus, the result of an impact is not a change in position, but an instantaneous change in acceleration (we know it isn't really instantaneous, but it's a decent approximation). Once this impulse is used, it is discarded.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.