1

有谁知道如何确定同一个圆的两个扇区是否相交?

假设我有一个扇形 A,用起始角 A1 和结束角 A2 表示,还有一个扇形 B,用起始角 B1 和结束角 B2 表示。所有角度范围为 0..2*PI 弧度(或 0..360 度)。

如何确定角A是否与角B相交?

我尝试了两个矩形相交问题的变体,如下所示:

if(a1 <= b2 && a2 >= b1) {
    // the sectors intersect
} else {
    // the sectores doesn't intersect
}

只要没有扇区越过 0 度点,此方法就可以。但是,如果任何一个扇区越过它,计算就会变得不正确。

根本问题在于创建定向(基于航向)增强现实应用程序。扇区 A 是对象,而扇区 B 是视口。获得角度如下:

A0 = bearing of the object
A1 = A0 - objectWidthInRadians
A2 = A0 + objectWidthInRadians

B0 = heading of the user (device)
B1 = B0 - viewportWidthInRadians
B2 = B0 + viewportWidthInRadians

提前致谢。

4

1 回答 1

1

你真正关心的是轴承的最短差是否小于碰撞范围:

// absolute difference in bearings gives the path staying within the 0..2*pi range
float oneWay = abs(A0 - B0);

// .. but this may not be the shortest, so try the other way around too
float otherWay = 2 * pi - oneWay;

if ( min(oneWay, otherWay) < (objectWidthInRadians + viewPortWidthInRadians) )
{
    // object is visible...
}

请注意,您的width定义有点奇怪(似乎真的是半角),并且为A1etc 显示的计算实际上并没有夹在规定的[0..2*pi]范围内......

于 2010-08-25T08:55:50.613 回答