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

RotationAxis incorrectly calculated #191

Open
pehrlich opened this issue Nov 4, 2014 · 0 comments
Open

RotationAxis incorrectly calculated #191

pehrlich opened this issue Nov 4, 2014 · 0 comments

Comments

@pehrlich
Copy link
Contributor

pehrlich commented Nov 4, 2014

    this._rotation[7] - sinceHand._rotation[5],
   // should become
    rotation[7] - rotation[5],

where rotation is defined by

    Leap.mat3.multiply(rotation, basis, basisLast) 

https://github.com/leapmotion/leapjs/blob/master/lib/hand.js#L278-L282

As it is right now, the axis of rotation has a slight mis-alignment, which grows larger with faster rotations.

Also, Axis angle should use atan2 instead acos2, to prevent possibility of singularities when standing still:

axisAngle = function(rotation) {
  //NOTE: Index = 3*row + col when basis vector 
  var axis = [
    rotation[5] - rotation[7],
    rotation[6] - rotation[2],
    rotation[1] - rotation[3]
  ]; 
  var sin = Leap.vec3.len(axis);
  var cos = ((rotation[0] + rotation[4] + rotation[8]) - 1.0)*0.5;
  var angle = Math.atan2(sin,cos);

    if (-1e-6 < sin && sin < 1e-6) {
        axis = [0, 0, 0];
        angle = 0;
        return [axis, angle];
    }

  Leap.vec3.scale(axis, axis, 1 / sin);
  return [axis,angle];
}

cc @GabrielHare

PS: full fiddle is here: http://jsfiddle.net/kLs8ymye/2/

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

1 participant