简体   繁体   English

Python 2D 2D圆形表面

[英]Python 2D circular surface in 3D

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 . 我能够在这里获得侧面: 用np.outer生成圆柱面 I would like to use np.outer again for consistency. 我想再次使用np.outer来保持一致性。 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)))

however in my plots, no surface is generated. 但是在我的情节中,没有产生表面。 Am I still not using np.outer correctly? 我还没有正确使用np.outer吗? Why is no surface generated? 为什么没有表面生成?

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). 为了查看磁盘,半径需要在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()

创建了磁盘

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM