Implicit equation and Mayavi

2019-05-11 14:06发布

问题:

How to plot implicit equation F(x,y,z)=0 with Mayavi? I tried with

import scipy as np
x, y, z = np.mgrid[-3:3:100j, -3:3:100j, -3:3:100j]
F = x**2/3**2 + y**2/2**2 + z**2/4**2 - 1

from enthought.mayavi import mlab
mlab.contour3d(F)
mlab.show()

but I don't get a part of ellipsoid. If I use parametrization and mesh then it's ok, but don't know how to plot it implicitly.

回答1:

Use contours = [0] to get the surface F(x,y,z) = 0:

import numpy as np
from enthought.mayavi import mlab

x, y, z = np.ogrid[-3:3:100j, -3:3:100j, -3:3:100j]
F = x**2/3**2 + y**2/2**2 + z**2/4**2 - 1
mlab.contour3d(F, contours = [0])
mlab.show()



标签: python mayavi