forked from SensibilityTestbed/indoor-localization
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trig.r2py
65 lines (45 loc) · 1.13 KB
/
trig.r2py
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
"""
<Program Name>
trig.r2py
<Purpose>
This is a script of some basic Trigonometric functions, and the
distance calculation by geo coordinate
"""
dy_import_module_symbols("math.r2py")
pi = 3.14159265358979323846
# converts decimal degrees to radians
def deg2rad(deg):
return (deg * pi / 180)
# converts radians to decimal degrees
def rad2deg(rad):
return (rad * 180 / pi)
TERMS = 11
def factorial(x):
result = 1
for num in range(x):
result *= (num + 1)
return result
def choose(x):
numerator = 1.0
denominator = 1.0
for num in range(x+1, x * 2 + 1):
numerator *= num
for num in range(1, x+1):
denominator *= num
return numerator / denominator
def cos(x):
cosx = ((math_e ** complex(0, x)) + (math_e ** complex(0, -x))) / 2
return cosx.real
def sin(x):
sinx = ((math_e ** complex(0, x)) - (math_e ** complex(0, -x))) / complex(0, 2)
return sinx.imag
def tan(x):
return sin(x)/cos(x)
def asin(x):
taylorsum = 0.0
for n in range(TERMS):
taylorsum += choose(n) * x ** (2 * n + 1) / (4 ** n * (2 * n + 1))
return taylorsum
def acos(x):
return pi / 2 - asin(x)
# -*- mode: python;-*-