cocoaTouch/otherSrc/CGPointUtils.c
changeset 2725 89908847b155
parent 2678 334016e8d895
child 3385 361bd29293f4
equal deleted inserted replaced
2724:601158aaa201 2725:89908847b155
    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 }