解决圆圈碰撞 [英] Resolving a Circle-Circle Collision

查看:137
本文介绍了解决圆圈碰撞的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写将圆形矩形碰撞检测(交叉)扩展到包括对碰撞的回应。圆形边和圆形矩形相当直接。但是圈子让我难倒了。例如,在离散事件模拟中,让两个圆圈发生碰撞,一个红色和一个绿色。我们可能会遇到以下情况:





紧接着它们发生碰撞后,我们可以:



这里RIP和GIP是前一个时钟周期中圆圈的位置。在当前的时钟周期,冲突在RDP和GDP检测到。然而,当两个圆圈位于RCP和GCP时,两个圆圈之间发生冲突。在时钟刻度上,红色圆圈向右移动RVy并向右移动RVx;绿色圆圈向下移动GVy,向左移动GVx。 RVy不等于GVy; RVx也不等于GVx。





碰撞发生在圆心之间的距离小于或等于圆的半径之和时,也就是在上图中,d < ; =(Rr + Gr)。在碰撞中,d< (Rr + Gr),我们需要在调整圆的速度分量之前将DP定位回CP。在d ==(Rr + Gr)的情况下,由于DP位于CP,因此不需要重新定位。

然后就是这个问题:我该如何回到CP。一些作者建议,应用下图中p值的一半。 .imgur.com / IFfut.pngalt =渗透>



对我来说,这显然是错误的。它假定两个圆的速度矢量相等,在这个例子中,情况并非如此。我认为渗透与计算有关,但是如何避开我。我确实知道这个问题可以改写为我们想为Gcdy和GCdx解决的正确的类似三角形问题。



碰撞本身将被建模为弹性,而数学惯性交换已经到位。唯一的问题是将圆定位在碰撞位置。

解决方案

这就是问题所在:我该怎么做。



很可能您想知道如何在调整圆的速度分量之前将DP放回到CP。

所以有两个问题,如何确定CP(发生碰撞的地方)以及如何调整从那一点开始的圆圈运动。第一部分有一个相当简单的解决方案(允许不同的半径和速度分量),但第二部分取决于弹性或非弹性响应是否建模。在你写的评论中:


碰撞将被建模为弹性。交换惯性
的数学已经到位。问题是在哪里定位圆圈。


鉴于我只想解决第一个问题,解决确切的位置发生碰撞的地方。假设两个圆的均匀运动,知道碰撞发生的确切时间就足够了,即圆的中心之间的距离等于它们的半径之和。

通过匀速运动,可以通过从另一个圆圈(绿色)的速度中减去其速度,将一个圆圈(红色)视为静止。实际上,我们将第一个圆的中心视为固定的,并且只考虑第二个圆进入(均匀)运动。



现在确切的碰撞时间是由求解一个二次方程。假设V =(GVx-RVx,GVy-RVy)是圆的相对运动,并且令P =(GIPx-RIPx,GIPy-RIPy)在碰撞之前的瞬时中它们的相对位置。我们通过定义:相对位置P的线性路径的动画:

P(t)= P + t * V

并询问该直线与半径Rr + Gr原点周围的圆相交时,或者是何时:

(Px + t * Vx)^ 2 +(Py + t * Vy)^ 2 =(Rr + Gr)^ 2

这是一个未知时间t的二次方程, 。情况是这样的(碰撞发生在位置CP之前或之前)会出现一个积极的实际解决方案(通常有两个解决方案,一个在CP之前,另一个在后,但可能是放牧接触给出双根)。您需要的解决方案(根)是较早的解决方案,其中t(即即时RIP,GIP位置为零)的解决方案较小。


I am writing software that extends Circle-Rectangle collision detection (intersection) to include responses to the collision. Circle-edge and circle-rectangle are rather straight-forward. But circle-circle has me stumped.

For example, let two circles collide, one red and one green, in a discrete event simulation. We might have the following situation:

Immediately after they collide we could have:

Here RIP and GIP were the locations of the circles at the previous clock tick. At the current clock tick, the collision is detected at RDP and GDP. However, the collision occurred between clock ticks when the two circles were at RCP and GCP. At the clock tick, the red circle moves RVy downward and RVx rightward; the green circle moves GVy downward and GVx leftward. RVy does not equal GVy; nor does RVx equal GVx.

The collision occurs when the distance between the circle centers is less than or equal to the sum of the circles' radii, that is, in the preceding figure, d <= ( Rr + Gr ). At a collision where d < ( Rr + Gr ), we need to position the DPs back to the CPs before adjusting the circles' velocity components. In the case of d == ( Rr + Gr ), no repositioning is required since the DPs are at the CPs.

This then is the problem: how do I make the move back to the CPs. Some authors have suggested that one-half of the penetration, given by p in the following figure, be applied.

To me that is just plain wrong. It assumes that the velocity vectors of the two circles are equal that, in this example, is not the case. I think penetration has something to do with the computation but how eludes me. I do know that the problem can be recast as a problem of right similar triangles in which we want to solve for Gcdy and GCdx.

The collision itself will be modeled as elastic, and the math for the exchange of inertia is already in place. The only issue is where to position the circles at collision.

解决方案

"This then is the problem: how do I make the move."

It is likely that you want to know how "to position the DPs back to the CPs before adjusting the circles' velocity components."

So there are two issues, how to determine the CPs (where the collision occurs) and how to adjust the circles' motion going forward from that point. The first part has a rather easy solution (allowing for different radii and velocity components), but the second part depends on whether an elastic or inelastic response is modelled. In a Comment you write:

The collision will be modeled as elastic. The math for the exchange of inertia is already in place. The problem is where to position the circles.

Given that I'm going to address only the first issue, solving for the exact position where the collision occurs. Assuming uniform motion of both circles, it is sufficient to know the exact time at which collision occurs, i.e. when does the distance between the circles' centers equal the sum of their radii.

With uniform motion one can treat one circle (red) as motionless by subtracting its velocity from that of the other circle (green). In effect we treat the center of the first circle as fixed and consider only the second circle to be in (uniform) motion.

Now the exact time of collision is found by solving a quadratic equation. Let V = (GVx-RVx, GVy-RVy) be the relative motion of the circles, and let P = (GIPx-RIPx,GIPy-RIPy) their relative positions in the "instant" prior to collision. We "animate" a linear path for the relative position P by defining:

P(t) = P + t*V

and ask when this straight line intersects the circle around the origin of radius Rr+Gr, or when does:

(Px + t*Vx)^2 + (Py + t*Vy)^2 = (Rr + Gr)^2

This is a quadratic equation in unknown time t, all other quantities involved being known. The circumstances are such that (with collision occurring at or before position CP) a positive real solution will exist (typically two solutions, one before CP and one after, but possibly a grazing contact giving a "double root"). The solution (root) t you want is the earlier one, the one where t (which is zero at "instant" RIP,GIP positions) is smaller.

这篇关于解决圆圈碰撞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆