Skip to content

RotationAxis incorrectly calculated #191

@pehrlich

Description

@pehrlich
    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/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions