python

  其实我是想生成一堆散点平均分布在球空间中(实心的),然后求出球心的大概坐标

  这是一种生成方式:

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

u, v = np.mgrid[0:2*np.pi:50j, 0:2*np.pi:50j]
# print(u)
h, w = u.shape
r = 1.
xs = r * np.random.rand(h, w) * np.sin(v) * np.cos(u)
ys = r * np.random.rand(h, w) * np.sin(v) * np.sin(u)
zs = r * np.random.rand(h, w) * np.cos(v)
ax.scatter(xs, ys, zs)
plt.show()

  虽然我看起来不像是平均分布的样子:

原文地址:https://www.cnblogs.com/darkchii/p/12757880.html