简体   繁体   English

查找两个位置之间的角度

[英]Find angle between Two Position

I have Latitude and Longitude of two position. 我有纬度和经度两个位置。

I already find out distance between this two position. 我已经找出了这两个位置之间的距离。

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];

Now i want to find out angle between this two position. 现在我想找出这两个位置之间的角度。

In center there is one user position and i want to display other user location in that Cicle at apporipate angle. 在中心有一个用户位置,我想以适当的角度显示该Cicle中的其他用户位置。

Thanks for help. 感谢帮助。

在此处输入图片说明

maybe this will help you 也许这会帮助你

- (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;    

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM