Double PlanetoidΒΆ

../../_images/planetoid.png
import numpy as np
from matplotlib import pyplot as plt
import s3dlib.surface as s3d

#.. Earth-Moon double planetoid
#.. influenced by M.C.Escher - Double Planetoid
#.. https://mcescher.com/gallery/mathematical/

# 1. Define function to examine .....................................
ttlcolor =  [0.502, 0.200, 0.278, 0.4] 
fgbgcolor = 'lightgrey'
elev, azim = 58,25
light_direction = [1,-1,1 ]
illum = s3d.rtv(light_direction,elev,azim)

def Tetrahedron(rez) :
    # need xyz native coordinate surface ....
    t = s3d.SphericalSurface(basetype='tetra')
    surface = s3d.Surface3DCollection(t.vertexCoor, t.fvIndices)
    surface.triangulate(rez)
    surface.name = 'tetrahedron'
    return surface

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

# .. modified.. added image color and geom mapping to both surfaces.
surface1 = Tetrahedron(rez)
surface1.map_color_from_image('data/earth.png')
surface1.map_geom_from_image('data/elevation.png',0.25)

surface2 = Tetrahedron(rez)
surface2.map_color_from_image('data/moon.png')
surface2.map_geom_from_image('data/moon_elev.png', 0.1, cref='h', hzero=-0.80)

surface2.transform(rotate=s3d.eulerRot(180,180))
surface = surface1 + surface2
surface.shade(direction=illum).hilite(0.5,direction=illum)

disk = s3d.PolarSurface(4,color='k')
disk.transform(rotate=s3d.eulerRot(-elev,-azim),scale=1.05) # <- modified scale

# 3. Construct figure, add surface, plot ............................

fig = plt.figure(figsize=plt.figaspect(1), facecolor=fgbgcolor)
text = fig.text(0.97, 0.52, 'S3Dlib.org', color=ttlcolor, ha='right',
    va='center', rotation=90, fontsize=55, fontweight='bold'  )
ax = plt.axes(projection='3d', aspect='equal')
minmax = ( -0.7,0.7 )  # <-- modified limits
ax.set(xlim=minmax, ylim=minmax, zlim=minmax )
ax.set_axis_off()
ax.view_init(elev, azim)
ax.set_facecolor(fgbgcolor)
ax.set_proj_type('ortho')

ax.add_collection3d(surface)
ax.add_collection3d(disk)

fig.tight_layout(pad=0)
plt.show()