计算两个运动球将碰撞的x/y点 [英] Calculate x/y point that 2 moving balls will collide

查看:79
本文介绍了计算两个运动球将碰撞的x/y点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使(基本上)是一个简单的台球游戏,并且希望能够预测一杆击中另一个球后的去向.

I'm trying to make what is (essentially) a simple pool game, and would like to be able to predict where a shot will go once it hits another ball.

我相信第一部分是计算母球是否会击中任何东西,如果击中,它将碰撞到哪里.我可以计算直线和一个球的碰撞点,但是不能计算两个球.

The first part is, I believe, to calculate if the cueball will hit anything, and if it does, where it collides. I can work out collision points for a line and a ball, but not 2 balls.

因此,给定2个球的x/y位置和速度,我如何计算它们碰撞的点?

So given the x/y positions and velocities of 2 balls, how do I calculate the point at which they collide?

(PS:我知道我可以通过计算整个过程中每一步的两个球之间的距离来做到这一点,但我希望有一些更优雅,更理想的东西.)

(PS: Im aware I can do this by calculating the distance between the two balls every step along the way, but I was hoping for something a little more elegant and optimal.)

设置示例:尝试计算红点

Example of setup: trying to calculate the red dot

http://dl.dropbox.com/u/6202117/circle.PNG

推荐答案

一些注意事项:

  • 两个半径为r的球碰撞时,其中心相距2r.
  • 您的第一个球可以假定是直线移动(嗯,是第一个近似值,但以此为起点),您可以找到该路径与从第一个球到第二个球的方向之间的夹角alpha.
  • 你知道固定球的中心,不是吗?
  • When two balls, each of radius r collide their centers are 2r apart.
  • Your first ball can be assumed to travel in a straight line (well, first approximation, but start with this), and you can find the angle, alpha between this path and the direction from the first ball to the second.
  • You know the center of the stationary ball, no?

现在您要做一些几何了.

Now you have some geometry to do.

进行此构造:

  1. 将第一个(移动的)球的当前中心标记为点A.
  2. 将固定球的中心标记为点B.
  3. 构造线段AB.
  4. A沿运动方向构造射线R.
  5. B周围构造半径为2r的圆.
  6. B垂直于R的线段中删除一个线段,称为交点C.
  7. 您知道距离AB,并且可以找到ABR之间的夹角alpha,根据《锡涅斯定律》可以找到长度BC.
  8. 从该长度确定是否有0、1或2个解决方案.如果为0或1,就完成了.
  9. 构造点D,使圆与R的交点更靠近A,然后再次使用正弦定律找到距离AD.
  10. 碰撞点是BD
  11. 的中点
  1. Mark the current center of the first (moving) ball as point A.
  2. Mark the center of the stationary ball as point B.
  3. Construct line segment AB.
  4. Construct the ray, R, from A in the direction of movement.
  5. Construct a circle of radius 2r around B.
  6. Drop a segment from B perpendicular to R call the point of intersection C.
  7. You know the distance AB and you can find the angle alpha between AB and R, with the Law of Sines find the length of BC.
  8. From that length determine if there are 0, 1 or 2 solutions. If there are 0 or 1 you are done.
  9. Construct point D where the circle meets R closer to A, and use the Law of Sines again to find the distance AD.
  10. The point of collision is the midpoint of BD

现在您已经了解了一切.

and now you know everything.

以此为基础构建高效的代码.

Constructing efficient code from this is left as an exercise.

顺便说一句-如果两个球都在移动,则此构造将不起作用,但是您可以将其转换为一个静止的框架,以这种方式求解,然后再转换回去.只需确保在逆向转换后 后检查解决方案是否在允许的区域内即可.

BTW-- This construction won't work if both balls are moving, but you can transform into a frame where one is stationary, solve it that way, then transform back. Just be sure to check that the solution is in the allowed area after the reverse transformation...

/物理学家不能发表这样的评论.我试图抗拒.我真的做了.

/ Physicists can't not make comments like this. I tried to resist. I really did.

这篇关于计算两个运动球将碰撞的x/y点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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