author | Henek |
Tue, 28 Dec 2010 23:53:37 +0100 | |
changeset 4748 | ce9b48de1f52 |
parent 4476 | 4bf74e158f44 |
child 4976 | 088d40d8aba2 |
permissions | -rw-r--r-- |
3547 | 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" |
|
3922
44804043b691
iPad Video Out support (+less warnings +code update for latest SDL)
koda
parents:
3547
diff
changeset
|
11 |
#include "math.h" |
3547 | 12 |
|
13 |
||
14 |
CGFloat distanceBetweenPoints (CGPoint first, CGPoint second) { |
|
15 |
CGFloat deltaX = second.x - first.x; |
|
16 |
CGFloat deltaY = second.y - first.y; |
|
17 |
return sqrt(deltaX*deltaX + deltaY*deltaY ); |
|
18 |
} |
|
19 |
||
20 |
CGFloat angleBetweenPoints(CGPoint first, CGPoint second) { |
|
21 |
CGFloat height = second.y - first.y; |
|
22 |
CGFloat width = first.x - second.x; |
|
23 |
CGFloat rads = atan(height/width); |
|
24 |
return radiansToDegrees(rads); |
|
25 |
} |
|
26 |
||
27 |
CGFloat angleBetweenLines(CGPoint line1Start, CGPoint line1End, CGPoint line2Start, CGPoint line2End) { |
|
28 |
CGFloat a = line1End.x - line1Start.x; |
|
29 |
CGFloat b = line1End.y - line1Start.y; |
|
30 |
CGFloat c = line2End.x - line2Start.x; |
|
31 |
CGFloat d = line2End.y - line2Start.y; |
|
32 |
CGFloat rads = acos(((a*c) + (b*d)) / ((sqrt(a*a + b*b)) * (sqrt(c*c + d*d)))); |
|
33 |
return radiansToDegrees(rads); |
|
34 |
} |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
35 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
36 |
CGFloat CGPointDot(CGPoint a,CGPoint b) { |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
37 |
return a.x*b.x+a.y*b.y; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
38 |
} |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
39 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
40 |
CGFloat CGPointLen(CGPoint a) { |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
41 |
return sqrtf(a.x*a.x+a.y*a.y); |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
42 |
} |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
43 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
44 |
CGPoint CGPointSub(CGPoint a,CGPoint b) { |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
45 |
CGPoint c = {a.x-b.x,a.y-b.y}; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
46 |
return c; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
47 |
} |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
48 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
49 |
CGFloat CGPointDist(CGPoint a,CGPoint b) { |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
50 |
CGPoint c = CGPointSub(a,b); |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
51 |
return CGPointLen(c); |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
52 |
} |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
53 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
54 |
CGPoint CGPointNorm(CGPoint a) { |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
55 |
CGFloat m = sqrtf(a.x*a.x+a.y*a.y); |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
56 |
CGPoint c; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
57 |
c.x = a.x/m; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
58 |
c.y = a.y/m; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
59 |
return c; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
60 |
} |