首页 文章

增强现实承载/ Headers /方位角混淆 . (iphone ARKit代码)

提问于
浏览
8
- (float)angleFromCoordinate:(CLLocationCoordinate2D)first toCoordinate:(CLLocationCoordinate2D)second {

//first is origin

//second is point

float longitudinalDifference = second.longitude - first.longitude;
float latitudinalDifference = second.latitude - first.latitude;
float possibleAzimuth = (M_PI * .5f) - atan(latitudinalDifference / longitudinalDifference);

if (longitudinalDifference > 0)
{
    return possibleAzimuth;
}
else if (longitudinalDifference < 0)
{
   return possibleAzimuth + M_PI; 
} 
else if (latitudinalDifference < 0) 
{
       return M_PI; 
    }

    return 0.0f;
}

上面的代码(取自开源ARkit项目)计算从兴趣点到原点(用户位置)的角度 . 给定以弧度计算的方位角(航向),在AR app im建筑物中,我可以使用以下代码检测点是否在其视口内:

- (BOOL)viewportContainsCoordinate:(ARCoordinate *)coordinate {

double centerAzimuth = self.centerCoordinate.azimuth;
double leftAzimuth = centerAzimuth - VIEWPORT_WIDTH_RADIANS / 2.0;

if (leftAzimuth < 0.0) {
    leftAzimuth = 2 * M_PI + leftAzimuth;
}

double rightAzimuth = centerAzimuth + VIEWPORT_WIDTH_RADIANS / 2.0;

if (rightAzimuth > 2 * M_PI) {
    rightAzimuth = rightAzimuth - 2 * M_PI;
}

BOOL result = (coordinate.azimuth > leftAzimuth && coordinate.azimuth < rightAzimuth); //THIS LINE

if(leftAzimuth > rightAzimuth) {
    result = (coordinate.azimuth < rightAzimuth || coordinate.azimuth > leftAzimuth);
}

double centerInclination = self.centerCoordinate.inclination;
double bottomInclination = centerInclination - VIEWPORT_HEIGHT_RADIANS / 2.0;
double topInclination = centerInclination + VIEWPORT_HEIGHT_RADIANS / 2.0;

//check the height.
result = result && (coordinate.inclination > bottomInclination && coordinate.inclination < topInclination);

//NSLog(@"coordinate: %@ result: %@", coordinate, result?@"YES":@"NO");

return result;
}

问题是我完全不了解它是如何专门在它检查坐标(兴趣点)方位角(航向)是否在原点 Headers 的左右方位角点之间的视口范围内的线上 .

所以举一个我的误解的例子 - 以度为单位,如果坐标(兴趣点)计算到90度原点的方位,然后原点视图端口面向它自己的坐标270度,这将意味着用户正在关注这一点,但我不明白为什么代码仍然有效,因为它检查坐标方位角是否在起源视口内,我认为这将是例如250 - (270) - 290度 . 显然,与原点相关的坐标方位角为90,因此它应该是假的 .

任何帮助了解这里真正发生的事情非常感谢 .

1 回答

  • 0

    我认为你可以使用像这样的功能

    #define degreesToRadians(x) (M_PI * x / 180.0)
    

    这样你就可以根据度数和弧度更加清晰 . 希望对你有帮助..

相关问题