Implicit plot

Marching cubes is an example of using frontend (client side) for doing computations. In this case a function of three variables is sampled on 3d equidistant grid and send to an k3d.marching_cubes object which will do the visualization. Note that: - data exchanged between frontend and backend is big - browser javascript does mesh computation - level is a single scalar parameter which can be passed to the frontend for data exploration - it is possible to use jslink for interaction without a Python kernel].

[1]:
import k3d
import numpy as np
import time
plot = k3d.plot()


T = 1.6
from numpy import sin,cos,pi
r = 4.77
zmin,zmax = -r,r
xmin,xmax = -r,r
ymin,ymax = -r,r
Nx,Ny,Nz = 37,37,37

x = np.linspace(xmin, xmax, Nx, dtype=np.float32)
y = np.linspace(ymin, ymax, Ny, dtype=np.float32)
z = np.linspace(zmin, zmax, Nz, dtype=np.float32)
x,y,z = np.meshgrid(x,y,z,indexing='ij')
p = 2 - (cos(x + T*y) + cos(x - T*y) + cos(y + T*z) + cos(y - T*z) + cos(z - T*x) + cos(z + T*x))
plt_iso = k3d.marching_cubes(p,compression_level=9,xmin=xmin, xmax=xmax,
                         ymin=ymin, ymax=ymax,
                         zmin=zmin, zmax=zmax, level=0.0,
                        flat_shading=False)
plot += plt_iso
plot.display()
[2]:
from ipywidgets import FloatSlider, jslink
w = FloatSlider(min=-2,max=5,value=-2)
l = jslink((plt_iso,'level'),(w,'value'))
w
[ ]: