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