Surface color from a Cloud, IΒΆ

../../_images/surf_func_valscold.png
import numpy as np
import matplotlib.pyplot as plt
import s3dlib.surface as s3d
import s3dlib.pntcloud as ptc
import math
from scipy import special as sp

# 1. Define function to examine .....................................

def Exyz(xyz):        #... for the cloudObj values
    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

def deflate(rtp) :    #... for the surface geometry
    r,t,p = rtp
    scale = 0.4
    Rz = np.cos(p)
    Rxys = (1-scale)*np.sin(p) + scale*np.cos(4*t)
    R = r*np.sqrt( Rz**2 + Rxys**2)
    return .9*R,t,p

# 2. Setup and map surface .........................................
rez,drez,cmap  = 6,3,'jet'
domain = [  [-2,2], [-2,2], [-2*np.pi,2*np.pi] ]     #.. evaluation domain

cloudObj = ptc.Point3DCloud(drez,cmap=cmap,domain=domain)
cloudObj.map_cmap_from_op(Exyz)            # map values with color

surface = s3d.SphericalSurface(rez)
surface.map_geom_from_op(deflate).transform(scale=[2,2,2*np.pi])
surface.map_vertvals_from_cloud(cloudObj)  # default colormapped from cloud

# 3. Construct figures, add surfaces, and plot ....................
xlim,ylim,zlim = cloudObj.get_domain()
fig = plt.figure(figsize=(10,4))
title = 'Surface VALUED from a function values COLORED cloud'
fig.text(.50,.90,title,ha='center',va='center',fontsize='x-large')
fig.text(.25,.01,str(surface), ha='center',va='bottom',fontsize='small')
fig.text(.70,.01,str(cloudObj),ha='center',va='bottom',fontsize='small')
# ....................
ax = fig.add_subplot(121, projection='3d', aspect='equal')
ax.set(xlim=xlim, ylim=ylim, zlim=zlim, xlabel='x',ylabel='y',zlabel='z')
ax.view_init(20)
ax.add_collection3d(surface.shade(flat=False).hilite(flat=False))
s3d.add_boxCorner(ax,domain)
scmp = surface.cBar_ScalarMappable
cbar = plt.colorbar(scmp, ax=ax,  shrink=0.8, pad=.1 )
cbar.set_label('surface values', rotation=270, labelpad = 15)
# ....................
ax = fig.add_subplot(122, projection='3d', aspect='equal')
ax.set(xlim=xlim, ylim=ylim, zlim=zlim, xlabel='x',ylabel='y',zlabel='z')
ax.view_init(20)
cloudObj.add_to3d(ax,0.15,0.85,span=.5)
s3d.add_boxCorner(ax,domain)
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()