检测 2d 平面中的 2 个移动物体何时靠近

发布于 2024-10-06 07:16:12 字数 359 浏览 12 评论 0原文

假设我们有一个 2D 天空(10000x10000 坐标)。在天空中的任何地方,我们都可以拥有一架飞机,通过其位置(x, y)来识别。任何飞机都可以开始移动到另一个坐标(直线)。

有一个组件可以管理所有这些定位和移动。当飞机想要移动时,它会以(start_pos, speed, end_pos)的形式发送消息。我如何在组件中判断一架飞机何时会在另一架飞机的视线内移动(每架飞机都将其作为视线半径的属性)以便通知它。请注意,许多飞机可以同时移动。此外,该算法非常有效,它可以处理约 1000 个平面。


如果存在一些限制,那就限制了您的解决方案 - 它可能可以被删除。问题还没有解决。

Imagine we have a 2D sky (10000x10000 coordinates). Anywhere on this sky we can have an aircraft, identified by its position (x, y). Any aircraft can start moving to another coordinates (in straight line).

There is a single component that manages all this positioning and movement. When a aircraft wants to move, it send it a message in the form of (start_pos, speed, end_pos). How can I tell in the component, when one aircraft will move in the line of sight of another (each aircraft has this as a property as radius of sight) in order to notify it. Note that many aircrafts can be moving at the same time. Also, this algorithm is good to be effective sa it can handle ~1000 planes.


If there is some constraint, that is limiting your solution - it can probably be removed. The problem is not fixed.

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

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

发布评论

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

评论(5

十级心震 2024-10-13 07:16:12
  • 使用一条线代表飞行路径。
  • 将每条线转换为包含它的矩形。矩形的宽度由您对“接近”的定义决定(安全距离越大,矩形应该越宽)。
  • 对于每个新的飞行计划:
    • 检查新矩形是否与另一个矩形相交。
      • 如果是这样,计算每个平面何时到达碰撞点。如果时间差太小(并且您应该根据场景定义太小),则拒绝新的飞行计划。
  • Use a line to represent the flight path.
  • Convert each line to a rectangle embracing it. The width of the rectangle is determined by your definition of "close" (The bigger the safety distance is, the wider the rectangle should be).
  • For each new flight plan:
    • Check if the new rectangle intersects with another rectangle.
      • If so, calculate when will each plane reach the collision point. If the time difference is too small (and you should define too small according to the scenario), refuse the new flight plan.
成熟的代价 2024-10-13 07:16:12

如果你想处理时间方面(即处理飞机移动的事实),那么我认为一种潜在的简化是通过时间维度来提升问题(增加一个维度 - 因此,原始问题是二维的,成为 3D 问题)。

然后,问题就变成了找到直线与(倾斜的)圆柱体相交的点。找到所有可能的交点将是 n^2;不太确定这是否足够有效。

If you want to deal with the temporal aspect (i.e. dealing with the fact that the aircraft move), then I think a potentially simplification is lifting the problem by the time dimension (adding one more dimension - hence, the original problem, being 2D, becomes a 3D problem).

Then, the problem becomes a matter of finding the point where a line intersects a (tilted) cylinder. Finding all possible intersections would then be n^2; not too sure if that is efficient enough.

方圜几里 2024-10-13 07:16:12

请参阅 Wikipedia:Quadtree 了解数据结构,可以轻松找到哪些飞机靠近给定的飞机。它将使您免于进行 O(N^2) 的紧密度测试。

See Wikipedia:Quadtree for a data structure that will make it easy to find which airplanes are close to a given airplane. It will save you from doing O(N^2) tests for closeness.

泡沫很甜 2024-10-13 07:16:12

你有很好的答案,我只会评论一个方面,可能不正确,

  • 你说你的飞机以形式(start_pos,speed,end_pos)移动,
  • 如果所有飞机都有这样的,让我们称它们为飞行计划,那么你应该能够计算直接确定它们何时何地彼此相距一定距离,或者何时它们彼此相距最近,或者是否会碰撞/太近

所以,如果它们确实按照飞行计划并且不要偏离它们,你的问题是确定性的 - 它归结为求解一组方程,这对于大约 1000 架飞机来说并不是一项艰巨的任务。

如果您确实需要更快地求解这些方程,您可以采用其他答案中描述的技术,

  • 使用可以加速计算距离(四叉树、八叉树、kd 树)的高效结构,
  • 将问题拆分为仅针对某些相关的未来时间片
  • 优先级 求解方程求解距离变化最快的对的方程

当然,将时间转换为三维会将飞机从点变成线,最终您将搜索两条 3d 线之间最近的点(这里有一些 数学)

You have good answers, I'll comment only on one aspect and probably not correctly

  • you say that you aircrafts move in form (start_pos, speed, end_pos)
  • if all aircrafts have such, let's call them, flightplans then you should be able to calculate directly when and where they will be within certain distance from each other, or when will they be at closest point from each other or if the will collide/get too near

So, if they indeed move according to the flightplans and do not deviate from them your problem is deterministic - it boils down to solving a set of equations, which for ~1000 planes is not such a big task.

If you do need to solve these equations faster you can employ the techniques described in other answers

  • using efficient structures that can speedup calculating distances (quadtree, octree, kd-trees),
  • splitting the problem to solve the equations only for some relevant future timeslice
  • prioritize solving equations for pairs for which the distance changes most rapidly

Of course converting time to a third dimension turns the aircrafts from points into lines and you end up searching for the closest points between two 3d lines (here's some math)

心舞飞扬 2024-10-13 07:16:12

我实际上找到了这个问题的答案。

它位于实时碰撞检测一书中,p. 223. 它的名字也更好:与球体相交,其中 2D 球体是一个圆。在这里解释它并不是那么简单(而且我也可能违反了一些权利),但基本思想是将其中一个圆固定为一个点,将其半径添加到移动圆的半径上。移动方向的新方向是两个原始向量的和。

I actually found an answer to this question.

It is in the book Real-Time Collision Detection, p. 223. It's better named, as well: Intersecting Moving Sphere Against Sphere, where a 2D sphere is a circle. It's not so simple (and I may also violate some rights) to explain it here, but the basic idea is to fix one of the circles as a point, adding its radius to the radius of the moving one. The new direction for the moving one is the sum of the two original vectors.

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