CGPoint pointA = [self.appDelegate.points[0] CGPointValue];//first point
CGPoint pointB = [self.appDelegate.points[1] CGPointValue];// second point
CGPoint pointC = [self.appDelegate.points[2] CGPointValue];//third point
CGFloat slopeAB = (pointB.y - pointA.y)/(pointB.x - pointA.x);//slope ab
CGFloat slopeBC = (pointC.y - pointB.y)/(pointC.x - pointB.x);//slope bc
self.ang=(slopeAB-slopeBC)/(1+(slopeAB)*(slopeBC));//slope
CGFloat finalAngle = atanf(self.ang);// angle tan inverse slope
CGFloat angle = (finalAngle * (180.0/M_PI));
NSLog(@"The angle is: %.2f degrees",angle);
答案 0 :(得分:1)
使用atan2()
功能。从手册页:
#include <math.h> double atan2(double y, double x);
atan2()函数计算反正切的主值
y/x
,使用两个参数的符号来确定。的象限 返回值。
要为三个点执行此操作,您需要两次调用atan2()
:一次查找AB的角度,一次查找BC的角度。取两者之间的差异来找出AB和BC之间的角度:
double angle_ab = atan2(pointA.y - pointB.y, pointA.x - pointB.x);
double angle_cb = atan2(pointC.y - pointB.y, pointC.x - pointB.x);
double angle_abc = angle_ab - angle_cb;
请注意,这是假设B是&#34;中心&#34;您感兴趣的角度点。如果我错误地调整,请适当调整。