Figure 8 Klein BottleΒΆ

../../_images/klein_figure81.png

A detailed description of a Figure 8 immersion Klein Bottle is found in Wikipedia where the functional definition is located. Also, Jos Leys has an animation construction of the figure on YouTube .

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

#.. Figure 8 Klein Bottle

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

def fig8(rtp) :
    r,t,p = rtp
    R=2
    v = 2*p
    Q = ( R + np.cos(t/2)*np.sin(v) - np.sin(t/2)*np.sin(2*v) )
    x = Q*np.cos(t)
    y = Q*np.sin(t)
    z = np.sin(t/2)*np.sin(v) + np.cos(t/2)*np.sin(2*v)
    return x,y,z

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

surface = s3d.SphericalSurface(rez,basetype='octa_c',color='burlywood')
surface.map_geom_from_op( fig8, returnxyz=True )

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

fig = plt.figure(figsize=plt.figaspect(1))
fig.text(0.975,0.975, "Figure 8 Immersion of the Klein Bottle", \
    ha='right', va='top', fontsize='larger', multialignment='right')
ax = plt.axes(projection='3d', aspect='equal')
minmax = (-2,2)
ax.set(xlim=minmax, ylim=minmax, zlim=minmax)
ax.set_axis_off()
ax.view_init(elev=35, azim=-60)

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

fig.tight_layout()
plt.show()