+ 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
5 Respostas
+ 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
+ 7
It's because one ball gets inside another and ends up colliding infinitely, mind your speed!
+ 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.
0
but if i even let them to not collide with same object once more until they aren't colliding, same thing happend
0
And this is the Result , Schindlabua
https://code.sololearn.com/W2AjFdzUAc21/?ref=app