ios检测线的angular度或程度

我是新来的iOS ,我正在尝试开发一个写意画应用程序,使用uibezierPath有一种方法来计算或接收总线的长度,即使我画了直线,弯曲或一个圆。 我在touchmove方法上使用addline,而我没有任何控制点。

touchesBegan方法里面,你可以使用这个代码

 { UITouch * touch = [touches anyObject]; CGPoint present = [touch locationInView:self]; CGPoint previous = [touch previousLocationInView:self]; CGFloat angle = [self getAngle:present :previous]; } - (float) getAngle:(CGPoint)a :(CGPoint)b { int x = ax; int y = ay; float dx = bx - x; float dy = by - y; CGFloat radians = atan2(-dx,dy); // in radians CGFloat degrees = radians * 180 / 3.14; // in degrees return angle; } 

您可以在任何方法中调用此方法来查找UIView两个CGPoints之间的angular度。

希望这有助于:-)

无论曲线还是直线,都可以find任意两点之间的距离。 (我不知道如何获得线的长度)。 如果直线是直线,则两点之间的距离应该等于直线的距离。

试试这个代码,

 - (double)getDistance:(CGPoint)one :(CGPoint)two { return sqrt((two.x - one.x)*(two.x - one.x) + (two.y - one.y)*(two.y - one.y)); } 

(sqrt)[(x2-x1) (x2-x1)+(y2-y1) (y2-y1)]是常用的方法。

希望这可以帮助 :-)