Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hand rotationAngle matrix issue #188

Closed
Traksewt opened this issue Oct 16, 2014 · 3 comments
Closed

hand rotationAngle matrix issue #188

Traksewt opened this issue Oct 16, 2014 · 3 comments

Comments

@Traksewt
Copy link

I am porting some Leap Motion code from Java to Javascript. I have noticed that the hand.rotationAngle in JS has an issue where it takes a while to update to the new rotation. Other rotation axis are also incorrectly affected during this transition, so it appears there may be a mistake in the matrix calculations.

The yaw/pitch/roll functions appear to update to the new rotation correctly.

The problem can be reproduced here (modifying the loop.html example).

    <script>

      // to make working with angles easy
      window.TO_RAD = Math.PI / 180;
      window.TO_DEG = 1 / TO_RAD;

      var items = []; 
      var controller = Leap.loop({

        // frame callback is run before individual frame components
        frame: function(frame){
          var lastFrame = controller.frame(1);
          if (lastFrame.hands.length > 0 && frame.hands.length > 0) {
            var hand = frame.hands[0];
              var yRotationYaw = hand.yaw() - lastFrame.hands[0].yaw();
              var yRotationMatrix = hand.rotationAngle(lastFrame, [ 0, 1, 0 ]);
              yRotationYaw *= TO_DEG
            yRotationMatrix *= TO_DEG
            items.push(["Yaw: ", yRotationYaw, ", MatrixY: ", yRotationMatrix].join(''));
              if (items.length > 40 ) {
                items.shift();
              }
              out.innerHTML = items.join('<br/>');
          }
        },

      });

    </script>

    <style>
      body {
        font-family: Helvetica;
      }
    </style>

To reproduce the problem, rotate your hand around y axis clockwise, then go anticlockwise for a sec and stop, and look at the output. The Yaw goes from + to - correctly, but the Matrix rotation stays positive for a while then eventually goes negative. If you output other axis here as well you will see them incorrectly rotating as well.

The same rotationAngle code in Java works correctly and the angles update immendiately.

Yaw: 2.807581696269874, MatrixY: 3.9540689391769805
Yaw: 2.3573805302341024, MatrixY: 3.3355188214460707
Yaw: 0.990757765002793, MatrixY: 1.5380785875818754
Yaw: 2.860084242279823, MatrixY: 2.9037227577157156
Yaw: 2.972636726711616, MatrixY: 2.7470992253959214
Yaw: 4.681279889846144, MatrixY: 3.1402594795229324
Yaw: 2.6953696803750784, MatrixY: 3.2755057764124267
Yaw: 2.2619217859969036, MatrixY: 2.7425860733019483
Yaw: 1.1739548852107469, MatrixY: 2.2334770212719772
Yaw: 0.22811988535967462, MatrixY: 0.8642551777711346
Yaw: 0.10955182278785452, MatrixY: 1.2851137910942743
Yaw: -0.511533369445178, MatrixY: 0.7299261534426825
Yaw: -0.6659924704347241, MatrixY: 0.3517680138202906
Yaw: -3.850879983415973, MatrixY: 1.252071291876788
Yaw: -1.9809262191818588, MatrixY: 1.0639024008771365
Yaw: -4.998913752603481, MatrixY: 2.8461004644569288
Yaw: -4.942045220211243, MatrixY: 3.652753093584144
Yaw: -6.767596153556592, MatrixY: 4.061402921527718
Yaw: -9.421768988817497, MatrixY: 5.22120052623156
Yaw: -9.204616866800443, MatrixY: 6.101881578342009
Yaw: -4.679961199071821, MatrixY: 3.265375021828544
Yaw: -8.80705278349346, MatrixY: 6.504765045543261
Yaw: -21.57964356809041, MatrixY: 14.000975745155527
Yaw: -16.91561690882114, MatrixY: 8.662100719966736
Yaw: -7.98609850682863, MatrixY: 6.494986517376056
Yaw: -3.361801172027406, MatrixY: 2.53342313842207
Yaw: -6.217850059642184, MatrixY: 3.978453551069215
Yaw: -4.61323497638658, MatrixY: 2.5952165709587742
Yaw: -3.867906970240726, MatrixY: 1.5531059217027883
Yaw: -3.7729954071053733, MatrixY: 0.7953961649502568
Yaw: -2.9224403895090534, MatrixY: 0.15965535729584227
Yaw: -1.4923382822850273, MatrixY: -0.09849879683994987
Yaw: -3.0338644056454487, MatrixY: -0.4983592494798237
Yaw: -2.0712609084464266, MatrixY: -0.7488863218361071
Yaw: -1.3454004866784044, MatrixY: -0.7942154894899587
Traksewt pushed a commit to Traksewt/molecular-control-toolkit-js that referenced this issue Oct 16, 2014
@Traksewt
Copy link
Author

I just added a jsfiddle demonstrating the problem:
http://jsfiddle.net/7cqmcoxd/

@pehrlich
Copy link
Contributor

pehrlich commented Nov 4, 2014

It looks like rotationAngle is being derived via the "Motions API" , which is filtered differently from the hand itself. We'll clean this up in a future release. For now, here's a way to get a matrix from the hand data directly:

http://jsfiddle.net/kLs8ymye/2/

This prints out first the rotationAngle/motions api values, and the calculations based off of hand direction and normal.

Edit: We also found a couple of other subtle issues, which are documented here: #191

@Traksewt
Copy link
Author

Thanks that workaround helped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants