Python中椭球体的创建

2024-10-01 15:36:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我遇到了一个有关绘制椭球体的问题。在

我要绘制的椭球体如下所示:

x**2/16 + y**2/16 + z**2/16 = 1.

所以我看到了很多关于椭圆空隙的计算和绘图的参考文献,在多个问题中提到了笛卡尔-球面或反之亦然的计算。在

我遇到了一个有计算器的网站,但我不知道如何成功地执行这个计算。我也不确定linspaces应该设置为什么。我已经看到了我在那里的默认值,但由于我以前没有使用这些库的经验,我真的不知道从中可以得到什么。在

^{pr2}$

Tags: 绘图网站绘制经验参考文献计算器椭圆球面
1条回答
网友
1楼 · 发布于 2024-10-01 15:36:17

你的椭球不只是一个椭球,它是一个球体。在

注意,如果你用下面写的x,y和z的代换公式,你会得到一个恒等式。一般来说,在不同的坐标系(在本例中为球形)中绘制这样的旋转曲面要比尝试求解隐式方程更容易(除非您采取一些对策,否则在大多数绘图程序中最终会出现锯齿状)。在

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np

phi = np.linspace(0,2*np.pi, 256).reshape(256, 1) # the angle of the projection in the xy-plane
theta = np.linspace(0, np.pi, 256).reshape(-1, 256) # the angle from the polar axis, ie the polar angle
radius = 4

# Transformation formulae for a spherical coordinate system.
x = radius*np.sin(theta)*np.cos(phi)
y = radius*np.sin(theta)*np.sin(phi)
z = radius*np.cos(theta)

fig = plt.figure(figsize=plt.figaspect(1))  # Square figure
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x, y, z, color='b')

{1美元^

相关问题 更多 >

    热门问题