+ 1

Elastic Collision - Algorithm Question

I've created a html which simjlates elastic collisions of balls in 2d plane. But the problem is that if I simulates this, some bounces, but some sticks together. How can I make them not stcik together? https://code.sololearn.com/W1paBmheDxWP/?ref=app

25th Feb 2019, 7:43 AM
Dri111
Dri111 - avatar
5 Respuestas
+ 1
I coded up a small example of what I meant, line 66 in particular: https://code.sololearn.com/WHqhV9hD7wTw/?ref=app It's not physically accurate but good enough usually, though you can see some spazzing. If you want to be super accurate you have to check the intersection point of the two circles before you update them (make a line in the direction of ball a, use the point-line-distance algo to figure out how far b is away from a, and see if the distance is <2r; then do math accordingly) Also my trig might be a bit off. I didn't double check it but some of the collisions look wrong. Sorry if it is, just use your trig instead
26th Feb 2019, 5:27 PM
Schindlabua
Schindlabua - avatar
+ 7
It's because one ball gets inside another and ends up colliding infinitely, mind your speed!
25th Feb 2019, 8:09 AM
Valen.H. ~
Valen.H. ~ - avatar
+ 1
You could move one of the colliding balls over in the direction of it's velocity so they're 2*radius apart and not inside each other.
25th Feb 2019, 12:05 PM
Schindlabua
Schindlabua - avatar
0
but if i even let them to not collide with same object once more until they aren't colliding, same thing happend
25th Feb 2019, 8:39 AM
Dri111
Dri111 - avatar
0
And this is the Result , Schindlabua https://code.sololearn.com/W2AjFdzUAc21/?ref=app
26th Feb 2019, 6:10 AM
Dri111
Dri111 - avatar