I'm generating coordinates of a bi-cone model in spherical coordinates. I'm using a series of nested for loops, as show here:
theta_in = 30.0 * np.pi/180.0
theta_out = 60.0 * np.pi/180.0
phi = 2*np.pi # rotation
R = 1.0
sampling = 100
theta = np.linspace(theta_in,theta_out,sampling)
phi = np.linspace(0,phi,sampling)
r = np.linspace(-R,R,sampling)
x = []
y = []
z = []
for ri in r:
for pi in phi:
for ti in theta:
xi = ri*np.cos(pi)*np.sin(ti)
yi = ri*np.sin(pi)*np.sin(ti)
zi = ri*np.cos(ti)
x.append(xi)
y.append(yi)
z.append(zi)
This generates the following desired output:
The use of these nested for loops to generate coordinate lists is not very efficient. My question is: what would be the most efficient way to do this while possibly avoiding the use of nested for loops?
