project_files/HedgewarsMobile/Classes/CGPointUtils.c
author koda
Sun, 26 Sep 2010 23:48:03 +0200
changeset 3910 dd47efbdec46
parent 3547 02875b1145b7
child 3922 44804043b691
permissions -rw-r--r--
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     1
/*
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     2
 *  CGPointUtils.c
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     3
 *  PinchMe
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     4
 *
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     5
 *  Created by Jeff LaMarche on 8/2/08.
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     6
 *  Copyright 2008 __MyCompanyName__. All rights reserved.
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     7
 *
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     8
 */
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     9
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    10
#include "CGPointUtils.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    11
#include <math.h>
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    12
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    13
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    14
CGFloat distanceBetweenPoints (CGPoint first, CGPoint second) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    15
    CGFloat deltaX = second.x - first.x;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    16
    CGFloat deltaY = second.y - first.y;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    17
    return sqrt(deltaX*deltaX + deltaY*deltaY );
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    18
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    19
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    20
CGFloat angleBetweenPoints(CGPoint first, CGPoint second) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    21
    CGFloat height = second.y - first.y;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    22
    CGFloat width = first.x - second.x;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    23
    CGFloat rads = atan(height/width);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    24
    return radiansToDegrees(rads);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    25
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    26
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    27
CGFloat angleBetweenLines(CGPoint line1Start, CGPoint line1End, CGPoint line2Start, CGPoint line2End) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    28
    CGFloat a = line1End.x - line1Start.x;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    29
    CGFloat b = line1End.y - line1Start.y;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    30
    CGFloat c = line2End.x - line2Start.x;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    31
    CGFloat d = line2End.y - line2Start.y;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    32
    CGFloat rads = acos(((a*c) + (b*d)) / ((sqrt(a*a + b*b)) * (sqrt(c*c + d*d))));
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    33
    return radiansToDegrees(rads);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    34
}