Vector field animation


In [ ]:
import k3d
import numpy as np
import time 

plot = k3d.plot()

Nx,Ny = 10,10

x = np.linspace(-1,1,Nx,dtype=np.float32)
y = np.linspace(-2,2,Ny,dtype=np.float32)

x,y = np.meshgrid(x,y)
z = np.zeros_like(x)

origins = np.vstack([x.flatten(),y.flatten(),z.flatten()]).T
vectors = 0.5*(np.vstack([np.zeros_like(x.flatten()),
                          np.zeros_like(x.flatten()),
                          np.ones_like(x.flatten())] )).T
phi0 = np.linspace(0,2*np.pi,vectors.shape[0])
labels = [str(i) for i in range(vectors.shape[0])]
vector_plot = k3d.vectors(origins.astype(np.float32), vectors.astype(np.float32))

plot += vector_plot
plot.display()

In [ ]:
plot.camera_auto_fit = False
plot.grid_auto_fit = False

for phi in np.linspace(0,2*np.pi,55):
    r = 0.1
    vector_plot.vectors = np.stack([r*np.cos(phi+phi0),
                                    r*np.sin(phi+phi0),
                                    0.4*np.ones_like(phi0)]).T
    time.sleep(0.05) # have to wait for data update