圆扇形碰撞 [英] Circle to Circle Segment Collision

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

问题描述

我在努力寻找一个坚如磐石的解决方案,以检测圆和圆弧之间的碰撞。想象一下,查看锥体场比赛的敌人,与各界重新利息presenting对象。

I'm struggling to find a rock solid solution to detecting collisions between a circle and a circle segment. Imagine a Field of View cone for a game enemy, with the circles representing objects of interest.

在底部的图表是我画了尝试,并制定出一些可能的情况下,但我敢肯定有更多的。

The diagram at the bottom is something I drew to try and work out some possible cases, but i'm sure there are more.

我明白如何快速exlude极端的情况下,我丢弃不与整个圆碰撞的任何目标,任何情况下,在主圆的中心为目标圆圈内的是自动真(E在图中)

I understand how to quickly exlude extreme cases, I discard any targets that don't collide with the entire circle, and any cases where the center of the main circle is within the target circle are automatically true (E in the diagram).

我在努力寻找,检查的情况下,剩下的一个好方法。我试着比较圆心和段外侧线的终点之间的距离,我已经试过了工作从主圆心目标圆心的角度,并确定这是否是段内,但是没有办法,似乎捕获所有的情况下。

I'm struggling to find a good way to check the rest of the cases. I've tried comparing distances between circle centers and the end points of the segments outer lines, and i've tried working out the angle of the center of the target circle from the center of the main circle and determining whether that is within the segment, but neither way seems to catch all cases.

具体而言,似乎去时髦如果目标圈靠近中心,但不触及它(E和B下面之间的某处),或者如果该段是比目标圆变窄(使中心是段内但两者边缘外的话)。

Specifically it seems to go funky if the target circle is close to the center but not touching it (somewhere between E and B below), or if the segment is narrower than the target circle (so that the center is within the segment but both edges are outside it).

有没有一种可靠的方法这样做?

Is there a reliable method for doing this?

额外的信息:该段由位置P,方向O(其大小是圆的半径),和一个视图大小描述,S

Extra info: The segment is described by position P, orientation O (whose magnitude is the circle radius), and a view size, S.

我最成功的尝试迄今为止参与确定矢量CA1和钙的角度,并检查是否向量a1和a2的角度之间或者他们的谎言。这适用于某些情况下,如上所述,但不情况靶圆是比段的大。

My most successful attempt to date involved determining the angles of the vectors ca1 and ca2, and checking if either of them lies between the angles of vectors a1 and a2. This works for some cases as explained above, but not situations where the target circle is larger than the segment.

编辑2 从下实现最佳的建议后,仍然有假阳性而我不能确定如何最好地消除。请参阅下面的粉红色的图。在右下方的圆圈是报告与该段相撞,因为它的边界重叠的两个半空间和主循环。

Edit 2 After implementing the best suggestion from below, there is still a false positive which I am unsure how best to eliminate. See the pink diagram below. The circle in the lower right is reporting as colliding with the segment because it's bounds overlap both half spaces and the main circle.

发现另一边的情况下(第4图像)之后,我看中了它结合了两个顶级的答案从下方似乎涵盖所有基地的做法。我将描述在这里是为了那些谁跟随。

After discovering another edge case (4th image), i've settled on an approach which combines the two top answers from below and seems to cover all bases. I'll describe it here for the sake of those who follow.

首先排除任何失败的快速圈到圈的测试。

First exclude anything that fails a quick circle-to-circle test.

然后测试对于圆和段的两个外线路之间的碰撞。如果倒是要么,返回true。

Then test for collision between the circle and the two outer lines of the segment. If it touches either, return true.

最后,做了几个利用圆的中心和两个外线路(如由加雷下文)点对半空间的测试。如果通过了​​这两项的很,否则返回false。

Finally, do a couple of point-to-halfspace tests using the center of the circle and the two outer lines (as described by Gareth below). If it passes both of those it's in, otherwise return false.

推荐答案

一个。检查它是否相交整个cirlce。
B.检查如果是交叉无论是直线段线。
C.如果不是,请检查圆心的夹角在于角度范围段(点积有利于本)。

A. Check if it is intersecting the whole cirlce.
B. Check if it is intersecting either of the straight segment lines.
C. If not, check if the angle between the circle centres lies in the angular range of the segment (dot product is good for this).

路口需要 A和&放大器; (B || C)

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

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