问题描述
我正在尝试生成圆柱表面的顶部/底部.我可以在此处获取侧面:生成圆柱面使用np.outer .我想再次使用np.outer来保持一致性.我以为我理解了链接中的答案,但是,如果我理解正确,那么以下方法应该起作用:
I am trying to generate the top/bottom of a cylindrical surface. I was able to obtain the lateral surface here: Generating a Cylindrical Surface with np.outer. I would like to use np.outer again for consistency. I thought I understood the answers in the link however if I understood correctly then the following should work:
R = 5
h = 5
u = np.linspace(0, 2*np.pi, 100)
x = R * np.outer(np.ones(np.size(u)), np.cos(u))
y = R * np.outer(np.ones(np.size(u)), np.sin(u))
z = h * np.outer(np.ones(np.size(u)), np.ones(np.size(u)))
但是在我的图中,没有生成表面.我仍然没有正确使用np.outer吗?为什么没有生成表面?
however in my plots, no surface is generated. Am I still not using np.outer correctly? Why is no surface generated?
推荐答案
没有可见的磁盘,因为您创建的所有点到中心和曲面的距离都完全相同,并且跨过内圆"和外圆"圆"无限薄.为了查看磁盘,半径需要在0和您想要的值(示例中为5)之间变化.
There is no visible disk because all the points which you are creating have exactly the same distance to the center and surface which spans between "inner circle" and "outer circle" is infinitely thin. In order to see the disk, radius needs to vary between 0 and your desired value (5 in the example).
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
R = np.linspace(0, 5, 100)
h = 5
u = np.linspace(0, 2*np.pi, 100)
x = np.outer(R, np.cos(u))
y = np.outer(R, np.sin(u))
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x,y,h) # z in case of disk which is parallel to XY plane is constant and you can directly use h
fig.show()
这篇关于3D中的Python 2D圆形曲面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!