2013-03-28 46 views
0

我有兩個位置的經度和緯度。找到兩個位置之間的夾角

我已經找出了這兩個位置之間的距離。

CLLocation *locA = [[CLLocation alloc] initWithLatitude:[player.strLatitude floatValue] longitude:[player.strLongitude floatValue]]; 
CLLocation *locB = [[CLLocation alloc] initWithLatitude:app.lat longitude:app.lag]; 
CLLocationDistance distance = [locB distanceFromLocation:locA]; 
NSLog(@"Distance%f",distance); 
[locA release]; [locB release]; 

現在我想找出這兩個位置之間的角度。

在中心有一個用戶位置,我想以角度展示該Cicle中的其他用戶位置。

感謝您的幫助。

enter image description here

+0

你只是在尋找atan2f函數表示? –

+0

對不起,我不知道atan2f函數。你能提供一些鏈接嗎? – Impossible

+0

你忽略了小學數學課程......? – holex

回答

1

也許這將幫助你

- (CGFloat)angleBetweenLinesInRadians:(CGPoint)line1Start 
         line1End:(CGPoint)line1End 
         line2Start:(CGPoint)line2Start 
         line2End:(CGPoint)line2End 
{ 
CGFloat a = line1End.x - line1Start.x; 
CGFloat b = line1End.y - line1Start.y; 
CGFloat c = line2End.x - line2Start.x; 
CGFloat d = line2End.y - line2Start.y; 

CGFloat line1Slope = (line1End.y - line1Start.y)/(line1End.x - line1Start.x); 
CGFloat line2Slope = (line2End.y - line2Start.y)/(line2End.x - line2Start.x); 

CGFloat degs = acosf(((a*c) + (b*d))/((sqrt(a*a + b*b)) * (sqrt(c*c + d*d)))); 


return (line2Slope > line1Slope) ? degs : -degs;  

}

+0

我沒有4分,因爲你的功能建議。我有兩個位置(經度和緯度) – Impossible

相關問題