Inner and Outer Composite Surface ColoringΒΆ
The four functional forms are those used in the Matplotlib comparison Ruled Surfaces examples. Changes to the surface and line objects in those examples are:
combining the two surface objects into one object
increased resolution of the surfaces and lines by using line rez, the surface creation using lrez, and triangulation of the composite object. Higher resolution reduces/eliminates the visual intersections of the two sub-surfaces.
applying a binary colormap based on the view to distinguish the front and back surfaces of the open sub-surfaces.
The binary colormaps used for the above figure are:
import numpy as np
from matplotlib import pyplot as plt
import s3dlib.surface as s3d
import s3dlib.cmap_utilities as cmu
#.. Composite Inner and Outer Ruled Coloring
# 1. Define function to examine .....................................
def func_one(t) :
theta = 2*np.pi*t
x1 = np.cos(theta)
y1 = np.sin(theta)
return x1,y1,t
def func_two(t) :
theta = 2*np.pi*t
x2 = np.cos(theta + np.pi)
y2 = np.sin(theta + np.pi)
return x2,y2,t
def func_three(t) :
theta = 2*np.pi*t
x1 = np.cos(theta)
y1 = np.sin(theta)
z1 = 0.1 * np.sin(6 * theta)
return x1,y1,z1
def func_four(t) :
theta = 2*np.pi*t
x2 = 0.6 * np.cos(theta)
y2 = 0.6 * np.sin(theta)
z2 = 2*np.ones(len(t)) # Note: arrays are the same size, not a scalar.
return x2,y2,z2
# 2. Setup and map line .............................................
cmu.binary_cmap('crimson', 'mediumturquoise', name='red_cyan' )
cmu.binary_cmap('mediumblue', 'gold', name='blu_yell' )
rez,lrez = 6,4
line_1 = s3d.ParametricLine(rez,func_one)
line_2 = s3d.ParametricLine(rez,func_two)
line_3 = s3d.ParametricLine(rez,func_three)
line_4 = s3d.ParametricLine(rez,func_four)
surface12 = line_1.get_surface_to_line(line_2,lrez=lrez)
surface34 = line_3.get_surface_to_line(line_4,lrez=lrez)
surface34.transform(scale=(1,1,.5))
# 3. Construct figure, add surface, and plot ........................
fig = plt.figure(figsize=(5,5))
ax = plt.axes(projection='3d', aspect='equal')
surface12.map_cmap_from_normals(direction=ax,cmap='red_cyan')
surface34.map_cmap_from_normals(direction=ax,cmap='blu_yell')
surface = surface12 + surface34
surface.triangulate(3) # need higher rez for surface intersections.
s3d.auto_scale(ax,surface,uscale=.85)
info = str(line_1)+'\n'+ str(surface12) +'\n'+str(surface)
fig.text(0.975,0.975, info,ha='right',va='top',fontsize='smaller')
ax.add_collection3d(surface.shade(ax=ax).hilite(ax=ax))
plt.show()
