QUESTION: Given the position, velocity, and acceleration of two balls (Ball#1 and Ball#2). Is there a way to figure out when they will collide?
(The acceleration is constant and caused by friction)
WARNING I'm looking for a function that can take an input of two balls and their properties and then return the time they will collide. I'm not looking for the solution of stepping forward a tiny amount every frame and checking for collision. I want to be able to predict collisions very fast.
WHY?: The purpose is to make a highly efficient and "perfect" 8-ball pool physics engine.
NOTE: I already have a collision response system in place. Calculate x/y point that 2 moving balls will collide. However this method breaks down whenever friction is involved.
WHAT I'VE TRIED: I've tried to solve this problem myself and I will do my best to explain my method below.
To start, I took some help from the kinematic equations and created a function that gives me the position of the balls at any specified time. f(t)=ball position at time t
Then I put the functions for the positions of each of the two balls into the distance formula. The result is a new function that can give me the distance between the balls at any specified time. d(t)=distance between balls
The next step would be to check when the distance is 2r.
so, d(t)=2r
However, The function d(t) is not a simple function. It's a quartic function. d(t) = at^4 + bt^3 + ct^2 + dt + e). This means that I would have to solve a quartic equation to find the point of collision.
I know how to solve quartic functions, but I would rather not. (my program (Scratch) has no way of dealing with complex numbers)
Welp, that's it. I'll be here if you have any questions.
If I'm understanding correctly you are just looking for how to implement friction into your physics engine. If you are solely looking for "when" they will collide then maybe this guys CodePen will help, otherwise continue on.
Like you said calculate the distance between two balls by getting the distance. If the distance is
<=2r then call a response function. In the response function get the vector between the two balls and normalize it. Calculate the relative speed of the balls and then set their x and y velocity accordingly. In the update function of the class I am multiplying the velocity by0.993which is just a number I picked and liked. You can change it to change how much friction there appears to be.This example take
massinto account if you feel you want to use it. For this example the mass is the same for all balls so it's really unnecessary but you may choose to make the cueball a different mass so I added it. This example only shoots the cueball in one direction to keep the code small.Check out this wiki on Impulse Wikipedia Impulse and here's as good video on 2d collision using it YouTube
Just click anywhere on the canvas