分体电视python3d绘图旋转_Python:如何围绕z轴旋转曲⾯并进⾏三
祝领导生日快乐祝福语维绘图?
温的成语好吧,我想你真的是要求绕⼀个轴旋转⼀个⼆维曲线来创建⼀个曲⾯。我有CAD背景,所以我就是这样解释的。
我的数学不是最棒的,所以请原谅任何晦涩难懂的术语。不幸的是,你必须完成剩下的数学运算来得到⽹格的所有点。在
以下是您的代码:#import for 3d
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
将arange更改为捕捉端点的linspace,否则arange将丢失数组末尾的3.0:
^{pr2}$
因为rho是你在每个z⾼度的半径,我们需要计算这个半径周围的x,y点。在这之前,我们必须弄清楚在这个半径上的什么位置可以得到x,y坐标:#steps around circle from 0 to 2*pi(360degrees)
#reshape at the end is to be able to u np.dot properly
revolve_steps = np.linspace(0, np.pi*2, 600).reshape(1,600)
获得圆周围点的三⾓法是:
x=r*cos(θ)
y=r*sin(θ)
对你来说r是你的rho,θ是旋转步数
通过使⽤美国运输部要做矩阵乘法,你得到⼀个2d数组,其中x和y的⾏将对应于ztheta = revolve_steps
#convert rho to a column vector
rho_column = shape(600,1)
中度脱水
x = rho_column.s(theta))
y = rho_column.dot(np.sin(theta))
# expand z into a 2d array that matches dimensions of x and y arrays..
# i shgrid
zipf
zs, rs = np.meshgrid(z, rho)形容自信的成语>荷花样子
#plotting
fig, ax = plt.subplots(subplot_kw=dict(projection='3d'))
fig.tight_layout(pad = 0.0)
#transpo zs or you get a helix not a revolve.
# you could add rstride = int or cstride = int kwargs to control the mesh density
ax.plot_surface(x, y, zs.T, color = 'white', shade = Fal)
电力专业大学排名
#view orientation
ax.elev = 30 #30 degrees for a typical isometric view
ax.azim = 30
#turn off the axes to cloly mimic picture in original question
ax.t_axis_off()
plt.show()
#ps 600x600x600 pts takes a bit of time to render
我不确定是否已在最新版本的matplotlib中修复,但设置三维打印的纵横⽐时使⽤:ax.t_aspect('equal')