In [ ]:
import k3d
import numpy as np
from numpy import sin,cos,pi
from ipywidgets import interact, interactive, fixed
import ipywidgets as widgets
import time
import math

plot = k3d.plot()

T = 1.618033988749895
r = 4.77
zmin,zmax = -r,r
xmin,xmax = -r,r
ymin,ymax = -r,r
Nx,Ny,Nz = 77,77,77

x = np.linspace(xmin,xmax,Nx)
y = np.linspace(ymin,ymax,Ny)
z = np.linspace(zmin,zmax,Nz)
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)).astype(np.float32)

iso = k3d.marching_cubes(p, level=0.0, color=k3d.nice_colors[0], bounds=[xmin, xmax, ymin, ymax, zmin, zmax])

plot += iso
plot.display()
In [ ]:
iso.opacity = 0.7
ax = np.logspace(0, np.log10(xmax - xmin + 1), Nx, endpoint=True) + xmin - 1
ay = np.logspace(0, np.log10(ymax - ymin + 1), Nx, endpoint=True) + ymin - 1
az = np.logspace(0, np.log10(zmax - zmin + 1), Nx, endpoint=True) + zmin - 1

x,y,z = np.meshgrid(ax,ay,az,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)).astype(np.float32)

iso2 = k3d.marching_cubes(p, level=0.0, color=1,
                          spacings_x=(ax[1:] - ax[:-1]).astype(np.float32),
                          spacings_y=(ay[1:] - ay[:-1]).astype(np.float32),
                          spacings_z=(az[1:] - az[:-1]).astype(np.float32),
                          bounds=[xmin, xmax, ymin, ymax, zmin, zmax],
                          opacity=0.15,
                          wireframe=True)
plot += iso2
In [ ]:
plot.camera = plot.get_auto_camera(0.5, 0, 20)
In [ ]: