创造一个革命的表面 [英] Creating a Surface of Revolution

查看:37
本文介绍了创造一个革命的表面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个磁盘的 3d 图,这是代码:

I have a 3d plot of a disk, here is the code:

ri = 100
ra = 300
h=20

# input xy coordinates
xy = np.array([[ri,0],[ra,0],[ra,h],[ri,h],[ri,0]])
# radial component is x values of input
r = xy[:,0]
# angular component is one revolution of 30 steps
phi = np.linspace(0, 2*np.pi, 50)
# create grid
R,Phi = np.meshgrid(r,phi)
# transform to cartesian coordinates
X = R*np.cos(Phi)
Y = R*np.sin(Phi)
# Z values are y values, repeated 30 times
Z = np.tile(xy[:,1],len(Y)).reshape(Y.shape)


fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='3d')

ax.set_zlim(0,200)
ax.plot_surface(X, Y, Z, alpha=0.5, color='grey', rstride=1, cstride=1)

我得到了这个不错的情节:

I get this nice plot:

另外我有这个情节:

代码是:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl

arr = np.array([[100, 15],
               [114.28, 17],
               [128.57, 18],
               [142.85, 19],
               [157.13, 22],
               [171.13, 24],
               [185.69, 25],
               [199.97, 27],
               [214.25, 28],
               [228.53, 30],
               [242.81, 31],
               [257.09, 35],
               [271.37, 36],
               [288.65, 37],
               [300, 38]])

#interpolating between the single values of the arrays
new_x = np.concatenate([np.linspace(arr[i,0],arr[i+1,0], num=50)
                        for i in range(len(arr)-1)])

new_y = np.interp(new_x, arr[:,0], arr[:,1])
t=np.arange(700)
p = plt.scatter(new_x,new_y,c=t, cmap="jet")

#inserting colorbar
cax, _ = mpl.colorbar.make_axes(plt.gca(), shrink=0.8)
cbar = mpl.colorbar.ColorbarBase(cax, cmap='jet', label='testvalues',
                       norm=mpl.colors.Normalize(15, 40))
plt.show()

现在我的问题:有没有办法将这个 2d 图形绘制到我的 3d 环境中?此外,是否可以通过围绕中点旋转这条线(点)来创建一个表面?我以与磁盘相同的方式尝试过,但我失败了,因为我认为我需要一个封闭的轮廓?这是一张可以更好地理解我想要的图片:

Now my question: Is there a way to plot this 2d graph into my 3d environment? Further is it possible to create a surface out of this line (points) by rotating them around the middlepoint ? I tried it the same way like I did it with my disk but I failed because I think I need a closed contour ? Here is a picture to understand better what I want:

推荐答案

我不确定您希望如何包含 2d 绘图,因此这里是您如何将其作为一个表面进行旋转.

I'm not sure how you want to include your 2d plot, so here's how you do it as a surface of revolution.

你的new_x对应径向距离,new_y对应高度.所以我们需要生成一组角度来生成圆锥":

Your new_x corresponds to radial distance, new_y corresponds to height. So we need to generate an array of angles for which to generate the "cone":

from matplotlib import cm

tmp_phi = np.linspace(0,2*np.pi,50)[:,None] # angle data
linesurf_x = new_x*np.cos(tmp_phi)
linesurf_y = new_x*np.sin(tmp_phi)
linesurf_z = np.broadcast_to(new_y, linesurf_x.shape)

linesurf_c = np.broadcast_to(t, linesurf_x.shape) # color according to t
colors = cm.jet(linesurf_c/linesurf_c.max()) # grab actual colors for the surface
ax.plot_surface(linesurf_x, linesurf_y, linesurf_z, facecolors=colors,
                rstride=1, cstride=1)

结果:

这篇关于创造一个革命的表面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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