-
Notifications
You must be signed in to change notification settings - Fork 0
/
sphere.py
executable file
·70 lines (52 loc) · 1.8 KB
/
sphere.py
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
#!/usr/bin/env python3
import numpy as np
import matplotlib.pyplot as plt
import sys
print(sys.argv)
from optparse import OptionParser
# parse arguments
usage = "usage: %prog [options]"
parser = OptionParser(usage, description=__doc__)
parser.add_option("--d", dest="distance", type="float", default=None, help="distance from surface of the sphere")
parser.add_option("--r", dest="radius", type="float", default=1, help="Radius of the sphere")
parser.add_option("--samples", dest="samples", type="int", default=100, help="explicitly declare the Δtheta while iterating for different azimuthial values")
opts, args = parser.parse_args()
print("Options Loaded")
print("Arguments: {}".format(args))
print("Options: {}".format(opts))
def create_sphere(x0,y0,z0,r,samples=100):
phi = np.linspace(0,2*np.pi,samples)
theta = np.linspace(0,np.pi,samples)
phi, theta = np.meshgrid(phi,theta)
x = x0 + r*np.cos(phi)*np.sin(theta)
y = y0 + r*np.sin(phi)*np.sin(theta)
z = z0 + r * np.cos(theta)
return x,y,z
x,y,z = create_sphere(0,0,0,1)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x,y,z,rstride=1,cstride=1)
ax.set_xlim([-1,1])
ax.set_ylim([-1,1])
ax.set_zlim([-1,1])
plt.show()
"""
d:distance from the surface of a sphere
r:radius of the sphere in question
theta: at which angle is the source
simulating the angular acceptance of a half active sphere
"""
def calculate_effective_area(d,r,theta):
cone_angle = np.arccos(float(1/(1+r/d)))
return 2*np.pi*r**2*(1-np.sin(cone_angle + theta))
theta = np.linspace(0,np.pi,100)
d=0.1
r=0.2
values=np.array(theta)
for i,th in enumerate(theta):
values[i] = calculate_effective_area(d,r,th)
print(values[i])
fig2 = plt.figure()
ax = fig2.add_subplot(111)
ax.plot(values,theta)
plt.savefig("thetadependency.png")