15 |
15 |
16 CGFloat distanceBetweenPoints (CGPoint first, CGPoint second) { |
16 CGFloat distanceBetweenPoints (CGPoint first, CGPoint second) { |
17 CGFloat deltaX = second.x - first.x; |
17 CGFloat deltaX = second.x - first.x; |
18 CGFloat deltaY = second.y - first.y; |
18 CGFloat deltaY = second.y - first.y; |
19 return sqrt(deltaX*deltaX + deltaY*deltaY ); |
19 return sqrt(deltaX*deltaX + deltaY*deltaY ); |
20 }; |
20 } |
21 |
21 |
22 CGFloat angleBetweenPoints(CGPoint first, CGPoint second) { |
22 CGFloat angleBetweenPoints(CGPoint first, CGPoint second) { |
23 CGFloat height = second.y - first.y; |
23 CGFloat height = second.y - first.y; |
24 CGFloat width = first.x - second.x; |
24 CGFloat width = first.x - second.x; |
25 CGFloat rads = atan(height/width); |
25 CGFloat rads = atan(height/width); |
26 return radiansToDegrees(rads); |
26 return radiansToDegrees(rads); |
27 //degs = degrees(atan((top - bottom)/(right - left))) |
|
28 } |
27 } |
29 |
28 |
30 CGFloat angleBetweenLines(CGPoint line1Start, CGPoint line1End, CGPoint line2Start, CGPoint line2End) { |
29 CGFloat angleBetweenLines(CGPoint line1Start, CGPoint line1End, CGPoint line2Start, CGPoint line2End) { |
31 |
|
32 CGFloat a = line1End.x - line1Start.x; |
30 CGFloat a = line1End.x - line1Start.x; |
33 CGFloat b = line1End.y - line1Start.y; |
31 CGFloat b = line1End.y - line1Start.y; |
34 CGFloat c = line2End.x - line2Start.x; |
32 CGFloat c = line2End.x - line2Start.x; |
35 CGFloat d = line2End.y - line2Start.y; |
33 CGFloat d = line2End.y - line2Start.y; |
36 |
|
37 CGFloat rads = acos(((a*c) + (b*d)) / ((sqrt(a*a + b*b)) * (sqrt(c*c + d*d)))); |
34 CGFloat rads = acos(((a*c) + (b*d)) / ((sqrt(a*a + b*b)) * (sqrt(c*c + d*d)))); |
38 |
|
39 return radiansToDegrees(rads); |
35 return radiansToDegrees(rads); |
40 } |
36 } |