Composite Surface of Different Base SurfacesΒΆ

../../_images/sliced_earth.png
from matplotlib import pyplot as plt
import s3dlib.surface as s3d

#.. Different Sub-surface Type

# 1 & 2. Define functions, setup and map surfaces ...................
rez=7

exterior = s3d.SphericalSurface(rez, basetype='octa')
exterior.map_color_from_image('data/blue_marble.png')
exterior.clip( lambda xyz : xyz[0]<0 , usexyz=True )

interior = s3d.PolarSurface(5, basetype='squ', cmap="hot")
interior.map_cmap_from_op( lambda rtz : 1-rtz[0]  )
interior.transform( [ [0,0,-1], [0,1,0], [1,0,0] ] )

surface = interior + exterior

# 3. Construct figure, add surfaces, and plot ......................

fig = plt.figure(figsize=plt.figaspect(1), facecolor='black' )
desc = str(surface) + '\n' + str(exterior) + '\n' + str(interior)
fig.text(0.975,0.975, desc, ha='right', va='top', 
        fontsize='smaller', multialignment='right', color='white')
ax = fig.add_subplot(111, projection='3d', aspect='equal')
minmax = (-0.8,0.8)
ax.set(xlim=minmax, ylim=minmax, zlim=minmax)
ax.set_axis_off()
ax.set_facecolor('black')

ax.add_collection3d(surface)

fig.tight_layout()
plt.show()

And just to make it a little more interesting, add a couple more surfaces and use the clipping function found in the Clipping a Surface example.

../../_images/sliced_earth2.png

where the surface is now defined as:

# 2. Setup and map surfaces .........................................
rez=7

exterior = s3d.SphericalSurface(rez, basetype='octa')
exterior.map_color_from_image('data/blue_marble.png')
exterior.clip( revFace ).shade(.5,[0,0,1])

interior1 = s3d.PolarSurface(5, basetype='squ', cmap="hot")
interior1.map_cmap_from_op( lambda rtz : 1-rtz[0]  )
interior2 = copy.copy(interior1).transform( [ [0,0,-1], [0,1,0], [1,0,0] ] )
interior3 = copy.copy(interior1).transform( [ [1,0, 0], [0,0,1], [0,1,0] ] )
interior = interior1 + interior2 + interior3

cmap = cmu.hsv_cmap_gradient('orange','gold')
core = s3d.SphericalSurface(rez, basetype='octa', color='gold').transform(scale=.325)
core.map_cmap_from_normals(cmap).hilite(.5,[1,-1,1])

surface = interior + exterior + core