查找 2D 平面上的 2 个物体是否会发生碰撞的算法

发布于 2024-09-12 07:49:00 字数 281 浏览 3 评论 0原文

我试图根据以下信息确定 Object1 是否会与 Object2 发生碰撞:

1) 对象的边界框(使用边界框碰撞检测)

2) 对象的速度

3) 对象的当前位置(x, y 坐标)

4) 对象' 方向(上、下、左或右)

对于一些图像,想象一下物体在 2D 网格上移动,它们只能在该网格的线上移动。

因此,鉴于上述信息,我需要一种高效且可读的算法来确定这些对象是否会发生碰撞。我所说的高效是指恒定的时间,并且最小化计算所花费的时间。伪代码或链接都可以。

I'm trying to determine whether Object1 will collide with Object2 given the following information:

1) Objects' bounding boxes (uses bounded-box collision detection)

2) Objects' speeds

3) Object's current locations (x, y coordinate)

4) Objects' directions (Up, Down, Left, or Right)

For a bit of imagery, imagine the objects traveling on a 2D grid, and they can only move on the lines of that grid.

So given the above information, I need an efficient, but readable algorithm to determine whether those objects will collide. By efficient I mean constant time with time spent on computations minimized. Psuedocode or a link is fine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

森罗 2024-09-19 07:49:00

首先,找到框在 X 轴上重叠的时间间隔。
其次,找出方框在 Y 轴上重叠的时间间隔。
最后,检查两个时间间隔是否重叠。如果是这样,则两个间隔中的最早时间点就是它们将要碰撞的时刻。

First, find the time interval during which the boxes will overlap on the X axis.
Second, find the time interval during which the boxes will overlap on the Y axis.
Finally, check if the two time intervals overlap. If so, the earliest point in time that is in both intervals is the moment they are going to collide.

情栀口红 2024-09-19 07:49:00

最好的方法是计算出:

  1. x 坐标重叠的线性时间范围(可能永远不会)
  2. y 坐标重叠的线性时间范围(可能永远不会)

然后测试两个时间范围是否重叠相交。这将作为额外的奖励给你碰撞时间。

总体而言,这将是一个简单的恒定时间操作。

Your best approach is to work out:

  1. The linear time range (possibly never) in which the x co-ordinates will overlap
  2. The linear time range (possibly never) in which the y co-ordinates will overlap

And then test if the two time ranges intersect. This will as an added bonus give you the collision time.

This will be a simple constant time operation overall.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文