3

我无法思考如何计算二维空间中移动圆的法线。我已经达到了我想计算物体速度(方向速度)的法线的程度,但这就是我的大学代数头脑过热的地方,我正在使用的任何二维圆中心点、半径、速度和位置。

最终,我想使用 Vector2.Reflect 方法从这个练习中获得更真实的物理效果。

提前谢谢。

编辑:添加了一些代码尝试建议(无济于事),可能误解了建议。在这里,我使用篮球和棒球,因此使用了底座和篮筐。我还有位置和速度,它们被添加到位置以创建运动。

if ((Vector2.Distance(baseMid, basketMid)) < baseRadius + basketRadius)
{
    Vector2 baseNorm = basketMid - baseMid;
    baseNorm.Normalize();
    Vector2 basketNorm = baseMid - basketMid;
    basketNorm.Normalize();
    baseVelocity = Vector2.Reflect(baseVelocity, baseNorm);
    basketVelocity = Vector2.Reflect(basketVelocity, basketNorm);
}

basePos.Y += baseVelocity.Y;
basePos.X += baseVelocity.X;
basketPos.Y += basketVelocity.Y;
basketPos.X += basketVelocity.X;
basketMid = new Vector2((basketballTex.Width / 2 + basketPos.X), (basketballTex.Height / 2 + basketPos.Y));
baseMid = new Vector2((baseballTex.Width / 2 + basePos.X), (baseballTex.Height / 2 + basePos.Y));
4

3 回答 3

5

首先是反射。如果我正确阅读了您的代码,则 Vector2.Reflect 的第二个参数是表面的法线。水平地板的法线为 (0,1),速度为 (4,-3) 的球击中它并以速度 (4,3) 飞走。那正确吗?如果这不正确,那么我们将不得不更改 if 语句的主体。(请注意,您可以通过设置 basketNorm = -baseNorm 来节省一些周期。)

现在物理。如前所述,当两个球相撞时,每个球都会反弹,就好像它撞到了与两个球体相切的玻璃墙一样,这是不现实的。想象一下打台球:一个快速的红球击中一个静止的蓝球死点。红球是否会反弹而将蓝球留在原来的位置?不,蓝球被撞飞了,红球失去了大部分速度(在完美的情况下都是如此)。一个炮弹和一个高尔夫球怎么样,它们都以相同的速度但方向相反,正面碰撞。他们会平等反弹吗?不,炮弹会继续,几乎没有注意到撞击,但高尔夫球会改变方向,飞得比来的更快。

要了解这些碰撞,您必须了解动量(如果您想要不完全弹性的碰撞,例如豆袋碰撞时,您还必须了解能量)。一本基础物理教科书将在前面的章节中介绍这一点。如果您只想能够模拟这些东西,请使用质心框架:

Vector2 CMVelocity = (basket.Mass*basket.Velocity + base.Mass*base.Velocity)/(basket.Mass + base.Mass);

baseVelocity -= CMVelocity;
baseVelocity = Vector2.Reflect(baseVelocity, baseNorm);
baseVelocity += CMVelocity;

篮子速度-= CMVelocity;
basketVelocity = Vector2.Reflect(basketVelocity, basketNorm);
篮子速度 += CMV 速度;
于 2010-02-09T19:19:16.647 回答
1

圆在其边缘给定点的法线将是从其中心到该点的方向。假设您在这里处理圆的碰撞,那么解决此问题的一种简单的“速记”方法是在碰撞时(当圆接触时),以下情况将成立:

设 A 为一个圆的中心,B 为另一个圆的中心。圆 A 的法线为 normalize(BA),圆 B 的法线为 normalize(AB)。这是真的,因为它们接触的点总是与两个圆的中心共线。

于 2010-02-06T05:11:24.560 回答
0

Caveat: I'm not going to assume that this is completely correct. Physics are not my specialty.

Movement has no effect on a normal. Typically, a normal is just a normalized (length 1) vector indicating a direction, typically the direction that a poly faces on a 3d object.

What I think you want to do is find the collision normal between two circles, yes? If so, one of the cool properties of spheres is that if you find the distance between the centers of them, you can normalize that to get the normal of the sphere.

What seems correct for 2d physics is that you take the velocity * mass (energy) of a sphere, and multiply that by the normalized vector to the other sphere. Add the result to the destination sphere's energy, subtract it from the original sphere's energy, and divide each, individually, by mass to get the resulting velocity. If the other sphere is moving, do the same in reverse. You can probably simplify the math down from there, of course, but it's late and I don't feel like doing it :)

If both spheres are moving, repeat the process for the other sphere (though you could probably simplify that equation to get some more efficient math).

This is just back-of-the-napkin math, but it seems to give the correct results. And, hey, I once derived Euler angles on my own, so sometimes my back-of-the-napkin math actually works out.

This also assumes perfectly elastic collisions.

If I'm incorrect, I'd be happy to find out where :)

于 2010-02-15T03:56:45.810 回答