Face Color Array¶
Multiple face colors can be set using a list of colors for the color or facecolor argument during surface instantiation. For the case when the length of the list is not equal to the number of faces, the face colors are repeatedly assigned the sequential colors in the list, in the order of the faces. This will result in an apparently random coloring of the faces for larger surface rez assignments. To preserve the face colors for the base surface, use a rez=0 followed by applying the triangulate method. Further geometric mapping can then be applied.
import numpy as np
import matplotlib.pyplot as plt
import s3dlib.surface as s3d
#.. Comparison among rez for instantiation and triangulation
# 1. Define function to examine .....................................
def radius_one(rtp) :
r,t,p = rtp
return np.ones_like(r),t,p
# 2. Setup and map surfaces .........................................
rez=2
color6 = ['C0','C1','C2','C3','C4','C5']
surfaces = [None]*3
surfaces[0] = s3d.SphericalSurface(color=color6)
surfaces[0].name = 'rez=0'
surfaces[1] = s3d.SphericalSurface(rez,color=color6)
surfaces[1].name = 'rez='+str(rez)
surfaces[2] = s3d.SphericalSurface(color=color6).triangulate(rez)
surfaces[2].name = 'rez=0, triangulate('+str(rez)+')\n map_geom(radius=1)'
surfaces[2].map_geom_from_op(radius_one)
# 3. Construct figure, add surface, plot ............................
minmax = (-0.7,0.7)
fig1 = plt.figure(figsize=[9,3.2])
for i,surface in enumerate(surfaces) :
ax = fig1.add_subplot(131+i, projection='3d', aspect='equal')
ax.set(xlim=minmax, ylim=minmax, zlim=minmax )
ax.set_axis_off()
ax.set_title(surface.name)
ax.add_collection3d(surface.shade(0.3))
fig1.tight_layout(pad=2)
plt.show()
For the case using ‘platonic’ surfaces, the color of each platonic surface face is transferred directly to each of the subdivided face triangles. As a result, the center and right spheres for the above figure will be identical, without random coloring.
For the ‘dodeca’ platonic surface, although colors are identical, using trianglate after creating the surface with rez=0 will produce non-uniformly shaped triangles, as shown in the figure below:
For this figure, the surfaces are constructed using the following script:
surfaces[0] = s3d.SphericalSurface(color=color6)
surfaces[0].name = 'rez=0'
surfaces[1] = s3d.SphericalSurface(rez,color=color6)
surfaces[1].name = 'rez='+str(rez)
surfaces[2] = s3d.SphericalSurface(color=color6).triangulate(rez)
surfaces[2].name = 'rez=0, triangulate('+str(rez)+')\n map_geom(radius=1)'
surfaces[2].map_geom_from_op(radius_one)
# 3. Construct figure, add surface, plot ............................
minmax = (-0.7,0.7)