答案 0 :(得分:1)
为避免360/0转换出现问题,您可以使用下一个条件计算周期
if (Cos(Bearing) * Cos(POI) + Sin(Bearing) * Sin(POI) > Cos(Threshold)) then
POI direction lies in range Bearing +- Threshold
答案 1 :(得分:0)
这是我现在的解决方案。在努力简化它的同时。欢迎提出建议。
public static boolean isBearingWithinRange(double heading, double alertHeading, double threshold) {
boolean status = false;
double leftThresholdMin = heading - threshold;
double leftThresholdMax = FULL_CIRCLE;
double rightThresholdMin = 0.0d;
double rightThresholdMax = 0.0d;
double total = heading + threshold;
if(total > FULL_CIRCLE) {
rightThresholdMax = threshold - (FULL_CIRCLE - heading);
if((alertHeading >= leftThresholdMin && alertHeading <= leftThresholdMax) ||
(alertHeading >= rightThresholdMin && alertHeading <= rightThresholdMax)) {
status = true;
}
} else if(heading < threshold) {
double diff = (threshold - heading);
leftThresholdMin = FULL_CIRCLE - diff;
rightThresholdMax = threshold + heading;
if((alertHeading >= leftThresholdMin && alertHeading <= leftThresholdMax) ||
(alertHeading >= rightThresholdMin && alertHeading <= rightThresholdMax)) {
status = true;
}
} else {
rightThresholdMax = heading + threshold;
if(alertHeading >= leftThresholdMin && alertHeading <= rightThresholdMax) {
status = true;
}
}
return status;
}