圆-圆碰撞预测 [英] Circle-Circle Collision Prediction
问题描述
我知道如何检查两个圆是否相交.但是,有时圆圈移动得太快,最终会避免在下一帧发生碰撞.
I'm aware of how to check if two circles are intersecting one another. However, sometimes the circles move too fast and end up avoiding collision on the next frame.
我目前对该问题的解决方案是检查前一个位置和当前位置之间的任意次数的圆-圆碰撞.
My current solution to the problem is to check circle-circle collision an arbitrary amount of times between the previous position and it's current position.
有没有一种数学方法可以计算出两个圆相撞所需的时间?如果我能够得到那个时间值,我可以将圆圈移动到当时的位置,然后在那个点碰撞它们.
Is there a mathematical way to find the time it takes for the two circle to collide? If I was able to get that time value, I could move the circle to the position at that time and then collide them at that point.
恒速
推荐答案
我假设圆的运动是线性的.假设圆 A 的中心位置由向量方程 Ca = Oa + t*Da
其中
I'm assuming the motion of the circles is linear. Let's say the position of circle A's centre is given by the vector equation Ca = Oa + t*Da
where
Ca = (Cax, Cay)
是当前位置Oa = (Oax, Oay)
是起始位置t
是经过的时间Da = (Dax, Day)
是单位时间的位移(速度).
Ca = (Cax, Cay)
is the current position
Oa = (Oax, Oay)
is the starting position
t
is the elapsed time
Da = (Dax, Day)
is the displacement per unit of time (velocity).
对于圆 B 的中心也是如此:Cb = Ob + t*Db
.
Likewise for circle B's centre: Cb = Ob + t*Db
.
然后你想找到 t 使得 ||Ca - Cb||= (ra + rb)
其中 ra
和 rb
分别是圆 A 和 B 的半径.
Then you want to find t such that ||Ca - Cb|| = (ra + rb)
where ra
and rb
are the radii of circles A and B respectively.
两边平方:||Ca-Cb||^2 = (ra+rb)^2
和扩展:(Oax + t*Dax - Obx - t*Dbx)^2 + (Oay + t*Day - Oby - t*Dby)^2 = (ra + rb)^2
从中你应该得到一个可以求解 t 的二次多项式(如果存在这样的 t).
From that you should get a quadratic polynomial that you can solve for t (if such a t exists).
这篇关于圆-圆碰撞预测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!