如何在Python中绘制伪球面

问题描述 投票:0回答:1

目标是使用 meshgrid 和 numpy 库生成伪球体的三维图形,但我使用下面的代码生成的图形不完整

u = np.linspace(0, np.pi, 50)
v = np.linspace(0, 2*np.pi, 100)
x, y = np.meshgrid(u, v)

X = np.arccos(x)*np.cos(y)
Y = np.arccos(x)*np.sin(y)
Z = x-np.tan(x)

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

surf = ax.plot_surface(X, Y, Z, cmap='viridis')

在此输入图片描述

期望生成类似的数字

在此输入图片描述

python python-3.x geometry geometry-surface
1个回答
0
投票

您混淆了三角/反三角/双曲函数。 特别是,arccos(反余弦)不是 sech(1/cosh,其中 cosh 是双曲余弦)。同样,tan 和 tanh 是完全不同的函数。

我能得到的最接近原始代码的是https://mathworld.wolfram.com/Pseudosphere.html

中的方程(1)到(3)
import numpy as np
import matplotlib.pyplot as plt

u = np.linspace (-5, 5, 100 )
v = np.linspace( 0, 2 * np.pi, 100 )
x, y = np.meshgrid( u, v )

X = 1.0 / np.cosh( x ) * np.cos( y )
Y = 1.0 / np.cosh( x ) * np.sin( y )
Z = x - np.tanh( x )

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
surf = ax.plot_surface(X, Y, Z, cmap='viridis')
plt.show()

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.