cocoaTouch/otherSrc/CGPointUtils.c
changeset 2678 334016e8d895
child 2725 89908847b155
equal deleted inserted replaced
2677:83ad68ceef72 2678:334016e8d895
       
     1 /*
       
     2  *  CGPointUtils.c
       
     3  *  PinchMe
       
     4  *
       
     5  *  Created by Jeff LaMarche on 8/2/08.
       
     6  *  Copyright 2008 __MyCompanyName__. All rights reserved.
       
     7  *
       
     8  */
       
     9 
       
    10 #include "CGPointUtils.h"
       
    11 #include <math.h>
       
    12 
       
    13 #define degreesToRadian(x) (M_PI * x / 180.0)
       
    14 #define radiansToDegrees(x) (180.0 * x / M_PI)
       
    15 
       
    16 CGFloat distanceBetweenPoints (CGPoint first, CGPoint second) {
       
    17 	CGFloat deltaX = second.x - first.x;
       
    18 	CGFloat deltaY = second.y - first.y;
       
    19 	return sqrt(deltaX*deltaX + deltaY*deltaY );
       
    20 };
       
    21 
       
    22 CGFloat angleBetweenPoints(CGPoint first, CGPoint second) {
       
    23 	CGFloat height = second.y - first.y;
       
    24 	CGFloat width = first.x - second.x;
       
    25 	CGFloat rads = atan(height/width);
       
    26 	return radiansToDegrees(rads);
       
    27 	//degs = degrees(atan((top - bottom)/(right - left)))
       
    28 }
       
    29 
       
    30 CGFloat angleBetweenLines(CGPoint line1Start, CGPoint line1End, CGPoint line2Start, CGPoint line2End) {
       
    31 	
       
    32 	CGFloat a = line1End.x - line1Start.x;
       
    33 	CGFloat b = line1End.y - line1Start.y;
       
    34 	CGFloat c = line2End.x - line2Start.x;
       
    35 	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))));
       
    38 	
       
    39 	return radiansToDegrees(rads);
       
    40 }