I have following code below:
for i in range(N):
# Dispersed Source
theta = np.random.uniform(0, np.pi, 1)
phi = np.random.uniform(0, 2 * np.pi, 1)
R = np.random.uniform(0, Ro, 1)
x = R * np.sin(theta) * np.cos(phi)
y = R * np.sin(theta) * np.sin(phi) # ?
z = R * np.cos(theta)
x_vec, y_vec, z_vec, nu = particle_func(x, y, z)
particle_trace = go.Scatter3d(
x=x_vec,
y=y_vec,
z=z_vec,
mode='lines'
)
data.append(particle_trace)
for j in range(int(nu)):
x = x_vec[-1]
y = y_vec[-1]
z = z_vec[-1]
x_vec_1, y_vec_1, z_vec_1, nu1 = particle_func(x, y, z)
particle_trace_fiss = go.Scatter3d(
x=x_vec_1,
y=y_vec_1,
z=z_vec_1,
mode='lines'
)
data.append(particle_trace_fiss)
The problem is that the for loop needs to keep going as such:
for j in range(int(nu)):
x = x_vec[-1]
y = y_vec[-1]
z = z_vec[-1]
x_vec_1, y_vec_1, z_vec_1, nu1 = particle_func(x, y, z)
particle_trace_fiss = go.Scatter3d(
x=x_vec_1,
y=y_vec_1,
z=z_vec_1,
mode='lines'
)
data.append(particle_trace_fiss)
for k in range(int(nu1)):
x = x_vec_1[-1]
y = y_vec_1[-1]
z = z_vec_1[-1]
x_vec_2, y_vec_2, z_vec_2, nu2 = particle_func(x, y, z)
particle_trace_fiss = go.Scatter3d(
x=x_vec_2,
y=y_vec_2,
z=z_vec_2,
mode='lines'
)
data.append(particle_trace_fiss)
for l in range(int(nu2)):
x = x_vec_2[-1]
y = y_vec_2[-1]
z = z_vec_2[-1]
x_vec_3, y_vec_3, z_vec_3, nu3 = particle_func(x, y, z)
particle_trace_fiss = go.Scatter3d(
x=x_vec_3,
y=y_vec_3,
z=z_vec_3,
mode='lines'
)
data.append(particle_trace_fiss)
...
Because the value of nu is a random number or zero meaning that the number of loops could potentially go on forever. This implies, to me, that a while loop must be used but I'm not sure how I would implement this. I am not looking for a specific output per se, just that each x, y, and z vector "traces" are appended to the data.
Apologies if I missing clarity in my question, I will be happy to respond to any comments requesting clarification. All help is appreciated in advance, thanks!!
Aucun commentaire:
Enregistrer un commentaire