-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathsrc.py
More file actions
76 lines (64 loc) · 2.28 KB
/
src.py
File metadata and controls
76 lines (64 loc) · 2.28 KB
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
import numpy as np
import scipy.special as ss
def cartToSph(x,y,z):
'''
[r, theta, phi] = cartToSph(x, y, z) converts the cartesian
coordinate system to the spherical coordinate system according to
the following definition:
r distance from the origin to the point in the interval
[0, \infty)
theta elevation angle measured between the positive z-axis and
the vector in the interval [0, pi]
phi azimuth angle measured between the positive x-axis and
the vector in the interval [0, 2*pi)
'''
r = np.sqrt(x**2 + y**2 + z**2)
theta = np.arctan2(np.sqrt(x**2 + y**2), z)
phi = np.arctan2(y , x)
return [r, theta, phi]
def sphToCart(r,theta,phi):
'''
[x,y,z] = sphToCart(r,theta,phi)
for converting from spherical to cartesian coordinates
r is radius,
theta is angle of elevation (0 at positive z axis, pi at negative z axis)
phi is angle of azimuth (0 at positive x axis, increase counterclockwise)
'''
x = r*np.sin(theta)*np.cos(phi)
y = r*np.sin(theta)*np.sin(phi)
z = r*np.cos(theta)
return [x,y,z]
def get_legendre(n,m,x):
'''
Returns an array dimensions len(N) by 1 with the
value of the m-th degree term of the n-th order
associated legendre polynomial evaluated at x.
Inputs:
n: a sequence of integers
m: a single integer, for now.
x: the argument to legenre polynomial
Output:
P
'''
P = []
for i in range(0,len(n)):
# use scipy.special to computePmn(x)
#into an m+1 x n+1 array for every value
#0...m, 0...n.
a,b = ss.lpmn(m,n[i],x)
#select the value at the m,n of interest
P.append(a[m,n[i]])
return P
def norm(sensor_location):
'''
return the pythagorean distance from the sensor location
to the origin.
'''
x = sensor_location[0]
y = sensor_location[1]
z = sensor_location[2]
return np.sqrt(x**2 + y**2 + z**2)
if __name__ == "__main__":
sensor_location = [0,0,-2000]
[r,theta,phi] = cartToSph(sensor_location)
print(r,theta,phi)