这是我想要的:
http://postimage.org/image/9pq8m79hx/
我知道 O 点和 X 点的坐标。是否有可能使用 iOS 方法找到 V 角(从北方向的角度)?
是的。
#import <math.h>
float a = -1 * atan2(y1 - y0, x1 - x0);
if (a >= 0) {
a += M_PI / 2;
} else if (a < 0 && a >= -M_PI / 2) {
a += M_PI / 2;
} else {
a += 2 * M_PI + M_PI / 2;
}
if (a > 2 * M_PI) a -= 2 * M_PI;
现在a
将在区间中包含以弧度为单位的角度0...2 PI
。
甚至不需要任何 iOS 特定的 API。请记住:iOS 仍然具有 libc 的所有功能。
不确定user529758的回答是否解决了这个问题,我读到的是将东更改为0度,将北更改为0度。下面的代码有效 - 关键线是第 4 行,从东到北变化 0 度
-(CGFloat) bearingFromNorthBetweenStartPoint: (CGPoint)startPoint andEndPoint:(CGPoint) endPoint {
// get origin point of the Vector
CGPoint origin = CGPointMake(endPoint.x - startPoint.x, endPoint.y - startPoint.y);
// get bearing in radians
CGFloat bearingInRadians = atan2f(origin.y, origin.x);
// convert to bearing in radians to degrees
CGFloat bearingInDegrees = bearingInRadians * (180.0 / M_PI);
// convert the bearing so that it takes from North as 0 / 360 degrees, rather than from East as 0 degrees
bearingInDegrees = 90 + bearingInDegrees;
// debug comments:
if (bearingInDegrees >= 0)
{
NSLog(@"Bearing >=0 in Degrees %.1f degrees", bearingInDegrees );
}
else
{
bearingInDegrees = 360 + bearingInDegrees;
NSLog(@"Bearing in Degrees %.1f degrees", bearingInDegrees );
}
return bearingInDegrees;
}