球碰撞问题 [英] Ball collision problems

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

问题描述

所以我有一个带有碰撞球的系统,通常可以正常工作,除非它们以相似的方向碰撞,相距小于 90 度.

So I have a system with colliding balls that generally works, except for when they collide with similar directions, less than 90 degrees apart.

这是因为上面的球试图与黄线碰撞,黄线应该是碰撞平面,但它把它发送到了错误的方向,它跟随"了另一个球.碰撞的一般算法是:

This is because the ball above tries to collide against the yellow line which is supposedly the collision plane, but it sends it off the wrong direction, and it "follows" the other ball. The general algorithm for the collision is:

dot = direction.surface;
parallel = surface * dot;
perpendicular = direction - parallel;
direction = perpendicular - parallel;

否定平行于表面法线方向的分量,即垂直于碰撞平面,垂直于表面法线的部分不变.

Which negates the component of the direction parallel to the surface normal, which is perpendicular to the collision plane, and the part perpendicular to the surface normal is unchanged.

有人知道解决这个问题吗?我做错了什么吗?

Does anyone know a fix for this? Have I done something wrong?

所以现在我添加了:

average = (ball1.velocity + ball2.velocity) / 2;
ball1.velocity -= average;
ball2.velocity -= average;

在进行上述计算之前和之后:

Before doing the calculations above, and after that:

ball1.velocity += average;
ball2.velocity += average;

根据@Beta 的回答,要进入正确的参考系.现在的问题是球的速度没有保持不变,因为它们都具有相同的速度和质量,但在碰撞后它们却不同.我不认为这是应该发生的,或者是吗?

To get in the right reference frame, according to @Beta's answer. The problem now is that the speeds of the balls aren't maintained, since they both have the same speeds and masses, yet after the collisions they're different. I do not think this is supposed to happen, or is it?

推荐答案

考虑将球从墙上弹开的一维问题.简单.

Consider the 1D problem of bouncing a ball off a wall. Simple.

现在看我从一架正在飞行的喷气式飞机的前舱壁上弹起一个球.球以 252 m/s 的速度向北移动,舱壁以 250 m/s 的速度向北移动.答案并不明显.但是转移到我的坐标系中(通过从所有东西中减去舱壁的速度 250 m/s),问题就变得微不足道了.解决它,然后将结果移回地面框架(通过添加 250 m/s 到一切),你就完成了.

Now watch me bounce a ball off the forward bulkhead of a jet plane in flight. The ball is moving north at 252 m/s, the bulkhead is moving north at 250 m/s. The answer is not obvious. But shift into my coordinate frame (by subtracting the velocity of the bulkhead, 250 m/s, from everything) and the problem is trivial. Solve it, then shift the result back into the ground frame (by adding 250 m/s to everything) and you're done.

现在是球以一定角度从墙上弹起的二维问题.简单的.(但请验证您的代码是否正确执行.)

Now the 2D problem of a ball bouncing off a wall at an angle. Simple. (But verify that your code does it correctly.)

现在两个球以相等和相反的动量碰撞(我现在假设它们具有相同的质量).你可以想象碰撞平面上有一堵黄色的墙,答案很容易得出.

Now two balls colliding with equal and opposite momenta (I'll assume they have the same mass, for now). You can imagine a yellow wall at the collision plane, and the answer comes easily.

现在两个球相撞,但速度加起来为零.仍然有一堵黄色的墙,但它在移动.好吧,通过从所有内容中减去球的速度的平均值 (sum/2) 来转移到墙的框架中,解决更简单的问题,然后通过将相同的速度加回到所有事物中来转移回来,你就完成了.

Now two balls colliding, but with velocities that do not add up to zero. There's still a yellow wall, but it's moving. Well, shift into the wall's frame by subtracting the average of the balls' velocities (sum/2) from everything, solve the simpler problem, then shift back by adding that same velocity back to everything, and you're done.

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

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