Ejemplo n.º 1
0
def klein_bottle(draw=True, show=True, figure8=False, endpoint=True, uv=True, wireframe=False, texture=None, both=False, interval=1000):
    """Show one or two Klein bottles"""
    import ipyvolume.pylab as p3
    # http://paulbourke.net/geometry/klein/
    u = np.linspace(0, 2 * pi, num=40, endpoint=endpoint)
    v = np.linspace(0, 2 * pi, num=40, endpoint=endpoint)
    u, v = np.meshgrid(u, v)
    if both:
        x1, y1, z1, u1, v1 = klein_bottle(endpoint=endpoint, draw=False, show=False)
        x2, y2, z2, u2, v2 = klein_bottle(endpoint=endpoint, draw=False, show=False, figure8=True)
        x = [x1, x2]
        y = [y1, y2]
        z = [z1, z2]
    else:
        if figure8:
            #u -= np.pi
            #v -= np.pi
            a = 2
            s = 5
            x = s * (a + cos(u / 2) * sin(v) - sin(u / 2) * sin(2 * v)/2) * cos(u)
            y = s * (a + cos(u / 2) * sin(v) - sin(u / 2) * sin(2 * v)/2) * sin(u)
            z = s * (sin(u / 2) * sin(v) + cos(u / 2) * sin(2 * v)/2)
        else:
            r = 4 * (1 - cos(u) / 2)
            x = 6 * cos(u) * (1 + sin(u)) \
                + r * cos(u) * cos(v) * (u < pi) \
                + r * cos(v + pi) * (u >= pi)
            y = 16 * sin(u) + r * sin(u) * cos(v) * (u < pi)
            z = r * sin(v)
    if draw:
        if texture:
            uv = True
        if uv:
            mesh = p3.plot_mesh(x, y, z, wrapx=not endpoint, wrapy=not endpoint, u=u/(2*np.pi), v=v/(2*np.pi), wireframe=wireframe, texture=texture)
        else:
            mesh = p3.plot_mesh(x, y, z, wrapx=not endpoint, wrapy=not endpoint, wireframe=wireframe, texture=texture)
        if show:
            if both:
                p3.animation_control(mesh, interval=interval)
            p3.squarelim()
            p3.show()
        return mesh
    else:
        return x, y, z, u, v
Ejemplo n.º 2
0
# coordinate frame axes line segment tip arrows
Xfv = Xf[:, 1, :] - Xf[:, 0, :]
Yfv = Yf[:, 1, :] - Yf[:, 0, :]
Zfv = Zf[:, 1, :] - Zf[:, 0, :]
arrowcols = np.zeros((k, 3, 3))
arrowcols[0:k, 0, 0] = 1.0
arrowcols[0:k, 1, 1] = 1.0
arrowcols[0:k, 2, 2] = 1.0
q = p3.quiver(Xf[:, 1, :],
              Yf[:, 1, :],
              Zf[:, 1, :],
              Xfv[:, :],
              Yfv[:, :],
              Zfv[:, :],
              size=10,
              size_selected=5,
              color=arrowcols,
              color_selected='gray')

# cylinder body surface
s = p3.plot_surface(Xc, Yc, Zc, color='orange')

# pass ipyvolume objects to animation controller and show
p3.animation_control([Lx, Ly, Lz, q, s], interval=100)
p3.show()

# In[ ]:

p3.save("shape_xform.html", offline=True)
import ipyvolume.pylab as p3
import numpy as np

fig = p3.figure()
q = p3.quiver(*stream.data[:, 0:50, :200], color="red", size=7)
p3.style.use("dark")  # looks better
p3.animation_control(q, interval=200)
p3.show()
import ipyvolume.pylab as p3
import numpy as np

fig = p3.figure()
q = p3.quiver(*stream.data[:,0:50,:200], color="red", size=7)
p3.style.use("dark") # looks better
p3.animation_control(q, interval=200)
p3.show()