3D中的Python 2D圆形表面 [英] Python 2D circular surface in 3D

查看:20
本文介绍了3D中的Python 2D圆形表面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试生成圆柱表面的顶部/底部.我能够在这里获得侧面:

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

however in my plots, no surface is generated. Am I still not using np.outer correctly? 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).

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圆形表面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆