Spiral Cloud SurfaceΒΆ
Clouds within a domain are generated from 3-D functions, f(x,y,z). Surfaces are determined at a constant cloud value within the domain. This example used the function in the Spirals Surface example, evaluated for cloud values plus and minus 0.142 .
import math
from scipy import special as sp
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import patches
import s3dlib.surface as s3d
import s3dlib.pntcloud as ptc
import s3dlib.cmap_utilities as cmu
# 1. Define function to examine .....................................
def Exyz(xyz):
p,l,isCos = 1,2,True
r, theta, z = s3d.CylindricalSurface.coor_convert(xyz)
sr2 = math.sqrt(2)
Em = math.factorial(p)/math.factorial(p+l) # M(-n,a+1,x)
L = sp.genlaguerre(p,l)
E = Em*( ((sr2*r)**l) * L(2*r**2) * np.exp(-(r**2)) )
if isCos: E = E* (np.cos(l*theta-z))
else: E = E* (np.sin(l*theta-z))
return E
# 2. Setup and map surface .........................................
drez,scol = 5, ['lightsalmon', 'palegoldenrod'] #.. for 3-D surfaces
pg_wht = cmu.hsv_cmap_gradient('salmon','white')
wht_ls = cmu.hsv_cmap_gradient('white','goldenrod')
cmap = cmu.stitch_cmap(pg_wht,wht_ls) #.. for 3-D point cloud
dmn = [ [-2,2], [-2,2], [-2*np.pi,2*np.pi] ] #.. evaluation domain
Eo = 0.142
fval = [-Eo,Eo]
cloudObj = ptc.Point3DCloud(drez).domain(dmn)
cloudObj.map_vals_from_op(Exyz,cmap)
surface = cloudObj.valsurf(*fval,color=scol)
surface.triangulate(1)
c,v,n = cloudObj.get_color_for_val(fval)
# 3. Construct figures, add surfaces, and plot ....................
fig = plt.figure(figsize=(10,4))
xlim,ylim,zlim = dmn
# ....................
fig.text(.27,0.95,str(surface),ha='center', fontsize='small')
ax = fig.add_subplot(121, projection='3d', aspect='equal', focal_length=0.25)
ax.set(xlim=xlim, ylim=ylim, zlim=zlim, xlabel='x',ylabel='y',zlabel='z')
ax.view_init(20,-60)
ax.add_collection3d( surface.shade(ax=ax).fade())
s3d.add_boxCorner(ax,dmn)
hnd = [ patches.Patch(label='value = '+str(fval[0]), color=scol[0] ) ,
patches.Patch(label='value = '+str(fval[1]), color=scol[1] ) ]
ax.legend(handles=hnd)
# ....................
fig.text(.7,0.95,str(cloudObj),ha='center', fontsize='small')
ax = fig.add_subplot(122, projection='3d', aspect='equal', focal_length=0.25)
ax.set(xlim=xlim, ylim=ylim, zlim=zlim, xlabel='x',ylabel='y',zlabel='z')
ax.view_init(20,-60)
cloudObj.add_to3d(ax,*n,span=.5)
s3d.add_boxCorner(ax,dmn)
scmp = cloudObj.cBar_ScalarMappable
cbar = plt.colorbar(scmp, ax=ax, shrink=0.8, pad=.1 )
cbar.set_label('cloud values', rotation=270, labelpad = 15)
# ....................
fig.tight_layout(pad=3)
plt.show()
