author | antonc27 <antonc27@mail.ru> |
Fri, 14 Aug 2015 21:27:55 +0200 | |
branch | ios-revival |
changeset 11120 | 83c0d96f86ea |
parent 10108 | c68cf030eded |
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 |
|
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
6832
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3547 | 17 |
*/ |
18 |
||
4976 | 19 |
|
3547 | 20 |
#include "CGPointUtils.h" |
3922
44804043b691
iPad Video Out support (+less warnings +code update for latest SDL)
koda
parents:
3547
diff
changeset
|
21 |
#include "math.h" |
3547 | 22 |
|
23 |
||
24 |
CGFloat distanceBetweenPoints (CGPoint first, CGPoint second) { |
|
25 |
CGFloat deltaX = second.x - first.x; |
|
26 |
CGFloat deltaY = second.y - first.y; |
|
27 |
return sqrt(deltaX*deltaX + deltaY*deltaY ); |
|
28 |
} |
|
29 |
||
30 |
CGFloat angleBetweenPoints(CGPoint first, CGPoint second) { |
|
31 |
CGFloat height = second.y - first.y; |
|
32 |
CGFloat width = first.x - second.x; |
|
33 |
CGFloat rads = atan(height/width); |
|
34 |
return radiansToDegrees(rads); |
|
35 |
} |
|
36 |
||
37 |
CGFloat angleBetweenLines(CGPoint line1Start, CGPoint line1End, CGPoint line2Start, CGPoint line2End) { |
|
38 |
CGFloat a = line1End.x - line1Start.x; |
|
39 |
CGFloat b = line1End.y - line1Start.y; |
|
40 |
CGFloat c = line2End.x - line2Start.x; |
|
41 |
CGFloat d = line2End.y - line2Start.y; |
|
42 |
CGFloat rads = acos(((a*c) + (b*d)) / ((sqrt(a*a + b*b)) * (sqrt(c*c + d*d)))); |
|
43 |
return radiansToDegrees(rads); |
|
44 |
} |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
45 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
46 |
CGFloat CGPointDot(CGPoint a,CGPoint b) { |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
47 |
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
|
48 |
} |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
49 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
50 |
CGFloat CGPointLen(CGPoint a) { |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
51 |
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
|
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 CGPointSub(CGPoint a,CGPoint b) { |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
55 |
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
|
56 |
return c; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
57 |
} |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
58 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
59 |
CGFloat CGPointDist(CGPoint a,CGPoint b) { |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
60 |
CGPoint c = CGPointSub(a,b); |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
61 |
return CGPointLen(c); |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
62 |
} |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
63 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
64 |
CGPoint CGPointNorm(CGPoint a) { |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
65 |
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
|
66 |
CGPoint c; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
67 |
c.x = a.x/m; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
68 |
c.y = a.y/m; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
69 |
return c; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3922
diff
changeset
|
70 |
} |