在球体表面创建一组随机点
我编写了一个代码来在同心球表面上生成一组随机点,在每个球上我会根据我想要的同心球表面的数量生成一定数量的点,如下面编写的代码所示,您可以尝试运行它,也许可以更好地理解手头的问题:
class point:
def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z
R_list=(0.001 , 0.002, 0.003 , 0.004 ,0.005)
num_points = 1000/len(R_list)
LD1 = 0.05
LD23 = 0.025
obj_points = []
condition = True
for R in R_list:
while len(rpoints) < num_points:
theta = np.random.uniform(-math.pi, math.pi)
phi = np.random.uniform(-math.pi, math.pi)
pi = R * math.cos(theta) * math.sin(phi) + (LD1 / 2), R * math.sin(theta) * math.sin(phi) + (
LD23 / 2), R * math.cos(phi) + (LD23 / 2)
obj_points.append(point(pi[0], pi[1], pi[2]))
# plott array
lt = len(obj_points)
Vis_arr = np.zeros((lt, 3))
n = 0
for n in range(0, lt-1 ):
Vis_arr[n][0] = obj_points[n].x
Vis_arr[n][1] = obj_points[n].y
Vis_arr[n][2] = obj_points[n].z
# scattering of points
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# scattering of points
ax.scatter3D(Vis_arr[:, 0], Vis_arr[:, 1], Vis_arr[:, 2], marker="o")
# graph output fully no evolution
plt.show()
我怀疑这是创建点数组时的错误,但我无法检测到问题的确切原因。
i wrote a code to generate a set of random points on the surface of concentric spheres,where on each sphere I would generate a certain number of points depending on how many concentric sphere surfaces I want as seen in the code written below,you can try to run it and maybe get a better understanding of the issue at hand:
class point:
def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z
R_list=(0.001 , 0.002, 0.003 , 0.004 ,0.005)
num_points = 1000/len(R_list)
LD1 = 0.05
LD23 = 0.025
obj_points = []
condition = True
for R in R_list:
while len(rpoints) < num_points:
theta = np.random.uniform(-math.pi, math.pi)
phi = np.random.uniform(-math.pi, math.pi)
pi = R * math.cos(theta) * math.sin(phi) + (LD1 / 2), R * math.sin(theta) * math.sin(phi) + (
LD23 / 2), R * math.cos(phi) + (LD23 / 2)
obj_points.append(point(pi[0], pi[1], pi[2]))
# plott array
lt = len(obj_points)
Vis_arr = np.zeros((lt, 3))
n = 0
for n in range(0, lt-1 ):
Vis_arr[n][0] = obj_points[n].x
Vis_arr[n][1] = obj_points[n].y
Vis_arr[n][2] = obj_points[n].z
# scattering of points
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# scattering of points
ax.scatter3D(Vis_arr[:, 0], Vis_arr[:, 1], Vis_arr[:, 2], marker="o")
# graph output fully no evolution
plt.show()
but when I run the code a random point appears out of nowhere:
I suspect that this is an error in creating the arrays of points but I cant detect the exact reason of the problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码中有两个错误:
应该是:
和
应该是:
You have two errors in your code:
should be:
and
should be: