How to fix circles overlap in collision response?

南笙酒味 提交于 2019-12-08 05:48:31

问题


Since in the digital world a real collision almost never happens, we will always have a situation where the "colliding" balls overlap.

How to put back balls in situation where they collide perfectly without overlap?

I would solve this problem with a posteriori approach (in two dimensions).

In short I have to solve this equation for t:

Where:

  • is a number that answers to the question: how many frames ago did the collision happen perfectly?
  • is the center of the first ball
  • is the center of the second ball
  • and

    are their velocities.

but the solution from WolframAlpha is too complicated (I changed the name of the velocities but essentially does not change anything).


回答1:


It looks complicated because it's the full solution, not just the simplified polynomial form of it. Multiply everything out and gather the constant, t, and t^2 terms, and you'll find that it becomes just at^2 + bt + c = 0. From there you can just use the quadratic formula.

Also, if you want to keep things simple, do them with vector math. There's no reason here to separate out the x and y coordinates; vector addition and dot products are all you need.

Finally, all that matters is the relative position and relative velocity. Pretend one circle is at the origin and stationary, and apply the difference to the other ball. That doesn't change the answer, but it does reduce the number of variables you're wrangling.



来源:https://stackoverflow.com/questions/18683179/how-to-fix-circles-overlap-in-collision-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!