好了,所以我認爲你確實需要圍繞軸旋轉2d曲線來創建曲面。我來自CAD背景,所以我就是這樣解釋的。 我不是數學中最偉大的人,所以原諒任何笨重的術語。不幸的是,你必須做數學的其餘部分來獲得網格的所有點。
赫雷什您的代碼:
#import for 3d
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
變化人氣指數到linspace其捕獲端點否則人氣指數將缺少3.0在陣列的末尾:
z = np.linspace(-3, 3, 600)
rho = np.cosh(z) # take constant b = 1
因爲RHO是你在半徑我們需要每個z高度來計算該半徑周圍的x,y點。而在此之前,我們在對半徑什麼位置獲得X,Y座標弄清楚:
#steps around circle from 0 to 2*pi(360degrees)
#reshape at the end is to be able to use np.dot properly
revolve_steps = np.linspace(0, np.pi*2, 600).reshape(1,600)
讓周圍一圈點的觸發方式是:
X = R * COS(THETA )
Y = R * SIN(THETA)
你r爲你的RHO和θ是revolve_steps
使用np.dot做矩陣乘法你得到一個二維數組又回到了X的行和y將對應於z的
theta = revolve_steps
#convert rho to a column vector
rho_column = rho.reshape(600,1)
x = rho_column.dot(np.cos(theta))
y = rho_column.dot(np.sin(theta))
# expand z into a 2d array that matches dimensions of x and y arrays..
# i used np.meshgrid
zs, rs = np.meshgrid(z, rho)
#plotting
fig, ax = plt.subplots(subplot_kw=dict(projection='3d'))
fig.tight_layout(pad = 0.0)
#transpose 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 = False)
#view orientation
ax.elev = 30 #30 degrees for a typical isometric view
ax.azim = 30
#turn off the axes to closely mimic picture in original question
ax.set_axis_off()
plt.show()
#ps 600x600x600 pts takes a bit of time to render
我不知道,如果它被固定在matplotlib的最新版本,但與設置3D繪圖的長寬比:
ax.set_aspect('equal')
沒有工作非常出色。你可以找到解決方案this stack overflow question
是不是旋轉只是矩陣乘法? – Fabricator