Thanks to those who helped me with my previous question. I will help others too where I can. In the meantime I have a general question whether anyone has had success connecting Mathematica to the LeapMotionTM device on a Mac? If so, please could you show me how you did this? I have followed instructions on the following page but got Java errors, and I use OSX not Windows:


The only modifications I made to the instruction code was to change the directory symbols from "\\" to "/", though I have tried both formats.


ReinstallJava[CommandLine -> "java", JVMArguments -> 
LeapSDK]"]; (*etc...*)

I have programmed the LeapMotion in Processing but would prefer to prototype some ideas in Mathematica as I can understand the math better with that before rewriting in Processing. Thanks.

  • $\begingroup$ It would probably be helpful to post up those java errors. $\endgroup$ – Gordon Coale Oct 10 '14 at 15:24
  • $\begingroup$ Java::excptn: A Java exception occurred: java.lang.NoClassDefFoundError: Could not initialize class com.leapmotion.leap.LeapJNI at com.leapmotion.leap.Controller.<init> (Controller.java:39) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source).JavaNew::fail: "Error calling constructor for class "com.leapmotion.leap.Controller" $\endgroup$ – awyr_agored Oct 10 '14 at 16:00

I have spent a little time accessing the methods of the Java linker file for LeapMotion with Mathematica based on the work of others:


Following their instruction, it is possible to access methods using Methods[] which returns a list of classes and methods. It is possible to follow the inheritance using this:

controller = JavaNew["com.leapmotion.leap.Controller"]

Code posted by Jari Kirma on the Wolfram Community site (link above) for creating methods to access finger position vectors:

getFrameData = 
  Module[{getFrame, getFingerList, getVector, makeRule, fun}, 
  ... (* etc *)

I have modified the code that was posted by Jari Kirma on the Wolfram Community site to illustrate the finger tips alongside their vector positions using Grid[], as well as a model of the LeapMotionTM on the desk:

Dynamic[{((tipPosition /. #) & /@ (fingers /. getFrameData[controller])) // MatrixForm,
  (*Display model of LeapMotion on the desk*)
  Gray, Cuboid[{-25, -13, -17}, {25, 13, 17}],

  (*model finger tips*)
  Red, Sphere[{1, -1, 1} #[[{1, 3, 2}]], 15]} & /@ ((tipPosition /. #) & /@ (fingers /. getFrameData[controller])),
     AxesLabel -> Automatic, PlotRange -> {{-200, 200}, {-200, 200}, {0, 400}}]}, 
UpdateInterval -> 0.05]
Frame -> All]

enter image description here

Decreasing the UpdateInterval value to less than 0.05 did not seem to speed up the graphics frame rate. Could this be a bottle neck in the device? Also, I have not used the AxesLabel option correctly as it does not appear on the 3D graphic, unless this is not an option for Graphics3D[]?

Also, please correct any of the above such as syntax conventions if possible.



I solved the connection problem I was having by adding InstallJava to the code written on the afore mentioned web site. I am not sure why ReinstallJava did not work on its own without having to use InstallJava too.

Run this code first (straight out of the Wolfram website):

ReinstallJava[CommandLine -> "java", 
   JVMArguments -> 

This is the part that's a little different:

InstallJava[]; (* does not work if this is not included *)
controller = JavaNew["com.leapmotion.leap.Controller"];
controller@isConnected[] (* test to see if LeapMotion is tied into Mathematica *)
  • $\begingroup$ Sure, people who search for "mathematica LeapMotion" might end up here so feel free to add some measurements/code to your answer :) $\endgroup$ – C. E. Oct 11 '14 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.