最佳碰撞检测

huangapple go评论46阅读模式
英文:

Optimal Collision Detection

问题

我一直在尝试找到一种最佳方法来检测碰撞,用于我最近正在开发的应用程序,以下是在最简单的情境下的问题:

鼠标按下左键时的鼠标位置被保存到一个指针中,然后当释放左键时,将其链接到一个链表结构中(由于Undo-Redo系统的实现便利性,链表结构优于简单的数组),例如在上面的图像中,列表中有3个不同的项目:始终为空的头部和2个指针。

黄点之间的连线是通过简单地在每个连续点之间绘制线段来实现的。

当前不需要的碰撞算法检查每个黄点与红线之间的碰撞,并将被判定为碰撞的点标记为蓝色。

我想要的是实际检测红线和绿线的每个交点(如上所示),而通过当前使用的算法是不可能的,我也没有进一步改进它所需的必要条件。

我要求任何愿意帮助的人只是指引我一些可能用于实现我寻求的结果的碰撞检测算法。

提前感谢。

如果我没有被自己的感知所欺骗,射线投射算法听起来可以胜任这项工作,但如果有其他选择,我也想听听。

英文:

I've been trying to find an optimal way to detect collision for an application I've been developing lately, here's the problem in the simplest context:

最佳碰撞检测

The mouse positions in which the left mouse button was pressed are saved to a pointer which then when the left mouse button is released, is linked into a linked list structure (A Linked List Structure was preferred to a simple array because of the beneficial implementation ease of an Undo-Redo system) for example in the image above there are 3 different items in the list being: The always empty head and 2 pointers.

The lines between the yellow points are achieved by simply drawing line segments between every consecutive point.

最佳碰撞检测

The current and unwanted collision algorithm checks for collision between every yellow point and red line and colors the ones which were deduced to have been colliding into blue.

最佳碰撞检测

What I want is to actually detect every intersection point of a red and a green line (Shown above) which by the means of the currently employed algorithm is impossible and I lack the necessities to further improve it.

What I ask of anyone willing to help is only to refer me to a couple of collision-detection algorithms which might be used to achieve the results I seek.

Thanks in advance.

If I was not deceived by my own perception a ray casting algorithm sounds like it could do the job but I wanted to hear some alternatives as well if there are any.

答案1

得分: 0

我之前怎么就没有想到这个问题呢,但是我刚刚通过检查红线与由连续的黄点标记的线段之间的碰撞来修复了它。

最佳碰撞检测

详细说明:

每对连续的黄点形成一条线段,可以通过多种方法推导出其函数,然后通过将函数设置为特定的y值(对于水平线)或将f(x)中的x变量设置为特定的x值(对于垂直线)来解出函数的交点。

英文:

I don't know how this never occurred to me before, but I just fixed it by checking collisions between the red lines and and the line segments marked by the consecutive yellow dots.

最佳碰撞检测

Elaboration:

Each consecutive yellow dot pair forms a line segment which's function can be derived by many means, I then solve for the intersection points of the function by setting either the function to a certain y value (for the horizontal lines) or setting the x variable in f(x) to a certain x value (for the vertical lines).

huangapple
  • 本文由 发表于 2023年5月25日 01:16:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76325977.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定