python三维圆曲面_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()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值