## Friday, 11 October 2013

### Leap Motion control of 3D data

Using the sample scripts from Leap Motion API I started looking into interacting with 3D scientific data in real time. With some simulated transient absorption data.

Here is the basic python script that controlled the plot.

import Leap, sys
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
from scipy import special
from mpl_toolkits.mplot3d import axes3d
import numpy as np

t1 = np.linspace(-10,-2,num=9)
t = np.append(t1,np.linspace(-1,1,num=9))
t = np.append(t,np.linspace(2,10,num=9))
T = np.append(t,np.linspace(20,100,num=9))
L = np.linspace(400,800)

l,t = np.meshgrid(L,T)

A = np.exp(-(l-650)**2/(2*50**2))+0.3*np.exp(-(l-550)**2/(2*50**2))

A1 = 0.01
T1 = 20.0
mu = 0.0
w = 0.2
y0 = 0

d = (w/(2*np.sqrt(2*np.log(2))))
K = A1*1/2*np.exp(-t/T1)*np.exp((mu+(d**2)/(2*T1))/T1)*(1+special.erf((t-(mu+(d**2)/T1))/(np.sqrt(2)*d))) + y0

Psi = K*A

fig = plt.figure(figsize=(16,10))
ax.plot_wireframe(l, t, Psi, linewidth=0.5)
ax.set_zlim(0.0,0.012)
plt.ion()
plt.show()


Then using the Leap motion listener every new frame I collected the yaw and height, rotated the plot and then redraw it.

y_height = hand.palm_position[1]
direction = hand.direction
rot = y_height-180
plt.draw()