2
我遇到了一些与我的雷达视图有关的问题,我非常接近有解决方案,但我无法弄清楚什么是错误的。我为此创建了一个雷达视图类。问题是,当我浏览周围的位置时,由几个白色点表示的位置全部散布在雷达视图的对角线上,从左上角开始到右下角。在增强现实应用中实现雷达视图
这是我如何计算点的坐标根据位置的方位和我自己的方位之间的区别:
-(float)calculateDelta:(double*)currentAzimuth withLoc:(ARGeoLocation *)location{
double deltaAzimuth;
deltaAzimuth = ABS(location.locationAzimuth - *currentAzimuth);
if (*currentAzimuth < 0.0)
*currentAzimuth = 2*M_PI + *currentAzimuth;
else if (*currentAzimuth > 2*M_PI)
*currentAzimuth = *currentAzimuth - 2*M_PI;
deltaAzimuth = location.locationAzimuth - *currentAzimuth;
if (deltaAzimuth < 0.0)
deltaAzimuth = 2*M_PI + deltaAzimuth;
else if (deltaAzimuth > 2*M_PI)
deltaAzimuth = deltaAzimuth - 2*M_PI;
return deltaAzimuth;
}
-(float)calculateXPointWithLoc:(ARGeoLocation *)loc andDelta:(float)delta{
float angle = radiansToDegrees(delta);
float dpx = ([myPos distanceFromLocation:loc.geoLocation]*20)/DISTANCE_FILTER;
if(0<=angle<=90)
return self.center.x + sin(angle)*dpx;
else if(90<angle<=180)
return self.center.x + cos(angle-90)*dpx;
else if(180<angle<=270)
return self.center.x - cos(270-angle)*dpx;
else if(270<angle<360)
return self.center.x - sin(360-angle)*dpx;
}
-(float)calculateYPointWithLoc:(ARGeoLocation *)loc andDelta:(float)delta{
float angle = radiansToDegrees(delta);
float dpx = ([myPos distanceFromLocation:loc.geoLocation]*20)/DISTANCE_FILTER;
if(0<=angle<=90)
return self.center.y - cos(angle)*dpx;
else if(90<angle<=180)
return self.center.y + sin(angle-90)*dpx;
else if(180<angle<=270)
return self.center.y + sin(270-angle)*dpx;
else if(270<angle<360)
return self.center.y - cos(360-angle)*dpx;
}
以上DPX表示该位置应该有来自像素的距离雷达视图的中心。 最后这些数据我在雷达上更新点,也有存储在阵列“自留地”在类radarView事实的UIView:
-(void)updateRadar:(double*)currentAzimuth andRange:(float)range{
float x,y;
int i=0;
float deltaAz;
for(ARGeoLocation *loc in coordinates){
deltaAz = [self calculateDelta:currentAzimuth withLoc:loc andRange:range];
x = [self calculateXPointWithLoc:loc andDelta:deltaAz];
// NSLog(@"x: %f",x);
y = [self calculateXPointWithLoc:loc andDelta:deltaAz];
// NSLog(@"y: %f",y);
[[plots objectAtIndex:i] setFrame:CGRectMake(x, y, DIAMETER_PLOT, DIAMETER_PLOT)];
i++;
}
}
是否有任何人谁已经经历创造了雷达的看法?
你完成上述功能吗? – pankaj