是否可以使用sympy绘制隐式三维方程?

时间:2015-03-14 22:08:44

标签: python matplotlib plot 3d sympy

有没有办法使用sympy绘制3变量隐式方程。通过文档,它只支持隐式2d图。或者是否有任何其他选项可以使用python绘制3d绘图,其中等式可以是来自用户的输入

1 个答案:

答案 0 :(得分:5)

我正在将我的评论转化为答案。我建议您使用mayavicontour3d执行此任务。您始终可以将隐式函数重写为f(x,y,z)=0。对于我们有x^2 + y^2 + z^2 = r^2的球体,可以将其重写为f(x,y,z) = x^2 + y^2 + z^2 - r^2 = 0

下面是一些例子

import numpy as np
from mayavi import mlab

mlab.clf()
x, y, z = np.mgrid[-3:3:50j, -3:3:50j, -3:3:50j]

# Plot a sphere of radius 1
values = x*x + y*y + z*z - np.sqrt(3)
mlab.contour3d(x, y, z, values, contours=[0])
mlab.axes()

# Plot a torus
R = 2
r = 1
values = (R - np.sqrt(x**2 + y**2))**2 + z**2 - r**2
mlab.figure()
mlab.contour3d(x, y, z, values, contours=[0])
mlab.axes()

# Plot a Scherk's second surface
x, y, z = np.mgrid[-4:4:100j, -4:4:100j, -8:8:100j]
values = np.sin(z) - np.sinh(x)*np.sinh(y)
mlab.figure()
mlab.contour3d(x, y, z, values, contours=[0])
mlab.axes()
mlab.show()

这给出了结果

球形: Sphere plotted with Mayavi

圆环: Torus plotted with Mayavi

Scherk的第二个表面: Scherk's second surface plotted with Mayavi

相关问题