author | koda |
Sun, 17 Apr 2011 22:38:24 +0200 | |
changeset 5155 | f2165724605c |
parent 4976 | 088d40d8aba2 |
child 6832 | fae8fd118da9 |
permissions | -rw-r--r-- |
3547 | 1 |
/* |
4976 | 2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
3 |
* Copyright (c) 2009-2011 Vittorio Giovara <vittorio.giovara@gmail.com> |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
3547 | 8 |
* |
4976 | 9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
3547 | 13 |
* |
4976 | 14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
17 |
* |
|
18 |
* File created on 03/10/2010. |
|
3547 | 19 |
*/ |
20 |
||
4976 | 21 |
|
3547 | 22 |
#include "CGPointUtils.h" |
3922
44804043b691
iPad Video Out support (+less warnings +code update for latest SDL)
koda
parents:
3547
diff
changeset
|
23 |
#include "math.h" |
3547 | 24 |
|
25 |
||
26 |
CGFloat distanceBetweenPoints (CGPoint first, CGPoint second) { |
|
27 |
CGFloat deltaX = second.x - first.x; |
|
28 |
CGFloat deltaY = second.y - first.y; |
|
29 |
return sqrt(deltaX*deltaX + deltaY*deltaY ); |
|
30 |
} |
|
31 |
||
32 |
CGFloat angleBetweenPoints(CGPoint first, CGPoint second) { |
|
33 |
CGFloat height = second.y - first.y; |
|
34 |
CGFloat width = first.x - second.x; |
|
35 |
CGFloat rads = atan(height/width); |
|
36 |
return radiansToDegrees(rads); |
|
37 |
} |
|
38 |
||
39 |
CGFloat angleBetweenLines(CGPoint line1Start, CGPoint line1End, CGPoint line2Start, CGPoint line2End) { |
|
40 |
CGFloat a = line1End.x - line1Start.x; |
|
41 |
CGFloat b = line1End.y - line1Start.y; |
|
42 |
CGFloat c = line2End.x - line2Start.x; |
|
43 |
CGFloat d = line2End.y - line2Start.y; |
|
44 |
CGFloat rads = acos(((a*c) + (b*d)) / ((sqrt(a*a + b*b)) * (sqrt(c*c + d*d)))); |
|
45 |
return radiansToDegrees(rads); |
|
46 |
} |
|
4476
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 |
CGFloat CGPointDot(CGPoint a,CGPoint b) { |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
49 |
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
|
50 |
} |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
51 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
52 |
CGFloat CGPointLen(CGPoint a) { |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
53 |
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
|
54 |
} |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
55 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
56 |
CGPoint CGPointSub(CGPoint a,CGPoint b) { |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
57 |
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
|
58 |
return c; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
59 |
} |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
60 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
61 |
CGFloat CGPointDist(CGPoint a,CGPoint b) { |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
62 |
CGPoint c = CGPointSub(a,b); |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
63 |
return CGPointLen(c); |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
64 |
} |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
65 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
66 |
CGPoint CGPointNorm(CGPoint a) { |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
67 |
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
|
68 |
CGPoint c; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
69 |
c.x = a.x/m; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
70 |
c.y = a.y/m; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
71 |
return c; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
72 |
} |