Transparent Surface Section

../../_images/two_ribbons.png

This case uses a transparency to simulate two surfaces.

../../_images/cmap_two_ribbons.png

For this case, colormapping is based on the coordinate position of the initial surface, not the relative view direction. Thus, both the ‘front’ and ‘back’ surfaces have the same color (as compared to Inner/Outer Surface Colormap and Inner/Outer Surface Colormap 2) . Only the shading is based on the view direction of the axes so that both ‘front’ and ‘back’ surfaces are appropriately shaded.

import numpy as np
from matplotlib import pyplot as plt
import s3dlib.surface as s3d
import s3dlib.cmap_utilities as cmu

#.. Trianry colormap used for dual geometry.

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

def twistFunction(rtz,twists=6) :
    r,t,z = rtz
    # Note: sliced surface needed due to discontinuity @ t=0 if twists is odd
    thickness = 0.33
    w = thickness*z 
    phi = 0.5*t*twists
    R = 1 + w * np.cos(phi)
    Z = w * np.sin(phi)
    return R,t,Z

# 2. Setup and map surfaces .........................................
cmap = cmu.stitch_color('firebrick', [1,1,1,0], 'teal',bndry=[0.4,0.6],name='red_0_cyan')

surface = s3d.CylindricalSurface.grid(6*10,3*90, 'r', cmap=cmap)
surface.map_cmap_from_op(lambda c : c[2])
surface.map_geom_from_op( twistFunction )

# 3. Construct figures, add surface, plot ...........................
minmax = (-.85,.85)

fig = plt.figure(figsize=plt.figaspect(1))
ax = plt.axes(projection='3d', aspect='equal')
ax.set(xlim=minmax, ylim=minmax, zlim=minmax)
ax.set_axis_off()
ax.view_init(azim=-70)

ax.add_collection3d(surface.shade(ax=ax).hilite(ax=ax))

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

Colormaps with transparency can be used to ‘clip’ a surface using the clip_alpha method. When using the same function as above, two surfaces may be constructed with binary colormaps which visually appear as the above single surface*. Using the following colormaps:

../../_images/cmap_two_ribbons_2.png

the two surfaces can now be colormapped using different binary colormaps to visualize both surfaces with back and front surfaces, as seen below:

../../_images/two_ribbons_2.png

For this case, the map_cmap_from_normals method uses the axes view direction after the geometric twist mapping has been applied.

import numpy as np
from matplotlib import pyplot as plt
import s3dlib.surface as s3d
import s3dlib.cmap_utilities as cmu

#.. Transparency colormap used for dual geometry, with front/back surfaces

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

def twistFunction(rtz,twists=6) :
    r,t,z = rtz
    # Note: sliced surface needed due to discontinuity @ t=0 if twists is odd
    thickness = 0.33
    w = thickness*z 
    phi = 0.5*t*twists
    R = 1 + w * np.cos(phi)
    Z = w * np.sin(phi)
    return R,t,Z

# 2. Setup and map surfaces .........................................
cmu.stitch_color('firebrick', [1,1,1,0], bndry=0.4, name='red_0'    )
cmu.stitch_color([1,1,1,0],   'teal',    bndry=0.6, name='0_cyan'   )
cmu.binary_cmap('crimson',    'mediumturquoise',    name='red_cyan' )
cmu.binary_cmap('mediumblue', 'gold',               name='blu_yell' )

rc_surface = s3d.CylindricalSurface.grid(6*10,3*90, 'r', cmap='red_0')
rc_surface.map_cmap_from_op(lambda c : c[2]).clip_alpha(.1)
rc_surface.map_geom_from_op( twistFunction )

by_surface = s3d.CylindricalSurface.grid(6*10,3*90, 'r', cmap='0_cyan')
by_surface.map_cmap_from_op(lambda c : c[2]).clip_alpha(.1)
by_surface.map_geom_from_op( twistFunction )

# 3. Construct figures, add surface, plot ...........................
minmax = (-.85,.85)

fig = plt.figure(figsize=plt.figaspect(1))
ax = plt.axes(projection='3d',aspect='equal')
ax.set(xlim=minmax, ylim=minmax, zlim=minmax)
ax.set_axis_off()
ax.view_init(azim=-70)

rc_surface.map_cmap_from_normals(direction=ax,cmap='red_cyan')
by_surface.map_cmap_from_normals(direction=ax,cmap='blu_yell')
surface = rc_surface + by_surface
ax.add_collection3d(surface.shade(ax=ax).hilite(ax=ax))

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


* Note: When a surface is a composite, the native coordinates are xyz-coordinates. Therefore, for the twisted example using a composite of two surfaces, the operation must use xyz-coordinates. The code for creating the composite surface is shown below:

def xyz_twistFunction(xyz) :
    rtz = s3d.CylindricalSurface.coor_convert(xyz,False)
    RTZ = twistFunction(rtz)
    XYZ = s3d.CylindricalSurface.coor_convert(RTZ,True)
    return XYZ

cmap = cmu.stitch_color('firebrick', [1,1,1,0], bndry=0.4, name='red_0')
cmap = cmu.stitch_color([1,1,1,0],   'teal',    bndry=0.6, name='0_cyan')

red_surface = s3d.CylindricalSurface.grid(6*10,3*90, 'r', cmap='red_0')
red_surface.map_cmap_from_op(lambda c : c[2]).clip_alpha(.1)
cyn_surface = s3d.CylindricalSurface.grid(6*10,3*90, 'r', cmap='0_cyan')
cyn_surface.map_cmap_from_op(lambda c : c[2]).clip_alpha(.1)
surface = red_surface + cyn_surface
surface.map_geom_from_op( xyz_twistFunction )