2024-05-18 04:28:38 发布
网友
使用Python,我想用一种颜色画一个球体,在这个球体上画一个spherical caps。帽由它们的中心点(角phi,theta)和半径给出。在
phi
theta
这有可能吗,也许用MayaVi?在
使用matplotlib:
def plot_spherical_cap(ax, b, opening_angle, radius=1.0): r = elevation phi = numpy.linspace(0, 2 * numpy.pi, 30) theta = numpy.linspace(0, opening_angle, 20) X = r * numpy.stack([ numpy.outer(numpy.cos(phi), numpy.sin(theta)), numpy.outer(numpy.sin(phi), numpy.sin(theta)), numpy.outer(numpy.ones(numpy.size(phi)), numpy.cos(theta)), ], axis=-1) # rotate X such that [0, 0, 1] gets rotated to `c`; # <https://math.stackexchange.com/a/476311/36678>. a = numpy.array([0.0, 0.0, 1.0]) a_x_b = numpy.cross(a, b) a_dot_b = numpy.dot(a, b) if a_dot_b == -1.0: X_rot = -X else: X_rot = ( X + numpy.cross(a_x_b, X) + numpy.cross(a_x_b, numpy.cross(a_x_b, X)) / (1.0 + a_dot_b) ) ax.plot_surface( X_rot[..., 0], X_rot[..., 1], X_rot[..., 2], rstride=3, cstride=3, color='#1f77b4', alpha=0.5, linewidth=0 ) return
使用matplotlib:
相关问题 更多 >
编程相关推荐