python - Plotting surface of implicitly defined volume -


having volume implicitly defined

x*y*z <= 1  

for

-5 <= x <= 5  -5 <= y <= 5  -5 <= z <= 5  

how go plotting outer surface using available python modules, preferably mayavi?

i aware of function mlab.mesh, don't understand input. requires 3 2d arrays, don't understand how create having above information.

edit:

maybe problem lies unsufficient understanding of meshgrid()-function or mgrid-class of numpy. see have use them in way, not grasp purpose or such grid represents.

edit:

i arrived @ this:

import numpy np  mayavi import mlab x, y, z = np.ogrid[-5:5:200j, -5:5:200j, -5:5:200j] s = x*y*z  src = mlab.pipeline.scalar_field(s)  mlab.pipeline.iso_surface(src, contours=[1., ],) mlab.show() 

this results in isosurface (for x*y*z=1) of volume though, not quite looking for. looking method draw arbitrary surface, "polygon in 3d" if there such thing.

i created following code, plots surface (works mayavi, too). need modify code particular problem, need understand why , how 3d surface defined 3 2d-arrays? these arrays (x, y , z) represent?

import numpy np matplotlib import pyplot plt mpl_toolkits.mplot3d import axes3d, axes3d  phi, theta = np.mgrid[0:np.pi:11j, 0:2*np.pi:11j] x = np.sin(phi) * np.cos(theta) y = np.sin(phi) * np.sin(theta) z = np.cos(phi)  fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.plot_wireframe(x,y,z) fig.show() 

the outer surface, implicitly defined by

x*y*z = 1, 

cannot defined explicitly globally. see this, consider x , y given, then:

z = 1/(x*y), 

which not defined x = 0 or y = 0. therefore, can define surface locally domains not include singularity, e.g. domain

0 < x <= 5 0 < y <= 5 

z indeed defined (a hyperbolic surface). similarly, need plot surfaces other domains, until have patched together

-5 <= x <= 5 -5 <= y <= 5 

note surface not defined x = 0 , y = 0, i.e. axis of coordinate system, cannot patch surfaces globally defined surface.

using numpy , matplotlib, can plot 1 of these surfaces follows (adopted http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html#surface-plots):

from mpl_toolkits.mplot3d import axes3d matplotlib import cm import matplotlib.pyplot plt import numpy np  fig = plt.figure() ax = fig.gca(projection='3d')  x = np.arange(0.25, 5, 0.25) y = np.arange(0.25, 5, 0.25) x, y = np.meshgrid(x, y) z = 1/(x*y)  surf = ax.plot_surface(x, y, z, rstride=1, cstride=1, cmap=cm.coolwarm,         linewidth=0, antialiased=false) ax.set_zlim(0, 10) ax.set_xlabel('x') ax.set_ylabel('y') ax.set_zlabel('z')     fig.colorbar(surf, shrink=0.5, aspect=5) plt.show() 

i'm not familiar mayavi, assume creating meshes numpy work same.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -