【问题标题】:Python 2D circular surface in 3DPython 2D 3D 圆形曲面
【发布时间】:2017-05-11 21:09:07
【问题描述】:

我正在尝试生成圆柱面的顶部/底部。我能够在这里获得侧面:Generating a Cylindrical Surface with np.outer。我想再次使用 np.outer 以保持一致性。我以为我理解了链接中的答案,但是如果我理解正确,那么以下内容应该可以工作:

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 吗?为什么没有生成曲面?

【问题讨论】:

    标签: python numpy 3d geometry surface


    【解决方案1】:

    没有可见的圆盘,因为您正在创建的所有点到中心的距离完全相同,并且跨越“内圆”和“外圆”之间的表面无限薄。为了看到圆盘,半径需要在 0 和您想要的值(示例中为 5)之间变化。

    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()
    

    【讨论】:

      猜你喜欢
      • 2013-11-09
      • 2018-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多