In [ ]:
from numpy import pi, cos, sin, linspace, meshgrid
import ipyvolume.pylab as p3
def möbius(draw=True, show=True, num=40, endpoint=True,
uv=True, wireframe=False, texture=None):
# http://paulbourke.net/geometry/toroidal
u = linspace(0, 2 * pi, num=num, endpoint=endpoint)
v = linspace(-0.4, 0.4, num=num, endpoint=endpoint)
u, v = meshgrid(u, v)
x = cos(u) + v * cos(u / 2) * cos(u)
y = sin(u) + v * cos(u / 2) * sin(u)
z = v * sin(u / 2)
if draw:
if texture:
uv = True
kwargs = dict(wrapx=not endpoint, wrapy=not endpoint,
wireframe=wireframe, texture=texture)
if uv:
kwargs.update(dict(u=u/(2*pi), v=v/(2*pi)))
mesh = p3.plot_mesh(x, y, z, **kwargs)
if show:
p3.squarelim()
p3.show()
return mesh
else:
return x, y, z, u, v
mesh = möbius()
In [ ]: