-
Notifications
You must be signed in to change notification settings - Fork 1
/
math.ew
85 lines (51 loc) · 1.45 KB
/
math.ew
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
global function is_even(integer test_integer)
return (and_bits(test_integer, 1) = 0)
end function
global function point_distance(atom x1,atom y1 , atom x2, atom y2)
atom x, y
--x = power(floor(x1) - floor(x2), 2)
--y = power(floor(y1) - floor(y2), 2)
x = power(x1 - x2, 2)
y = power(y1 - y2, 2)
return sqrt(x + y)
end function
constant HALFPI = PI/2
global function atan2(atom y, atom x)
if x > 0 then
return arctan(y/x)
elsif x < 0 then
if y < 0 then
return arctan(y/x) - PI
else
return arctan(y/x) + PI
end if
elsif y > 0 then
return HALFPI
elsif y < 0 then
return -(HALFPI)
else
return 0
end if
end function
object junk
junk = {{},{}}
for j = 360 to 0 by -1 do
junk[1] = append(junk[1], sin(j*PI/180) )
junk[2] = append(junk[2], cos(j*PI/180) )
end for
constant sin_loTRUE2up = junk[1], cos_loTRUE2up = junk[2]
--public float getAngleTo(Location l) {
-- return (float) (180-Math.atan2(l.x - this.x, l.y - this.y)*180/Math.PI);
--}
global function get_angle_to(atom x, atom y, atom x2, atom y2)
return (180- atan2(x2 - x ,y2 - y) *180/PI)
end function
--public float toRotmgAngle(float angle) {
--return (float) ((angle - 90) / (360 / Math.PI / 2));
--}
global function toRotmgAngle(atom angle)
return ((angle-90) / (360/PI/2) )
end function
global function degtorad(atom angle)
return (angle * (PI/180))
end function