Measure angle between two direction vectors using LeapMotion


#1

Not sure if I’m posting this right but I’m trying to measure the angle between the direction vectors of the thumb proximal bone and the index finger metacarpal bone using LeapMotion with OpenFrameworks. The documentation about bone types can be found here.

The algorithm I’m using is:

  1. Find thumb bone metacarpal direction (metacarpal to tip)
  2. Find index finger metacarpal direction
  3. Find angle between 1 and 2.

The problem: the angle value seems wrong as it changes by ±3 degrees around 16 degrees… should be going from around 10 degrees to 50 or more.

Please can you tell me where I’m going wrong?

Here’s some of my code:

    fingerType fingerTypes[] = {THUMB, INDEX, MIDDLE, RING, PINKY};


            const Finger & thumbFinger = hands[0].fingers()[ fingerTypes[THUMB] ];
            const Finger & indexFinger = hands[0].fingers()[ fingerTypes[INDEX] ];

            //1.
            thumbMetacarpal = simpleHands[0].fingers[ fingerTypes[0] ].mcp;

            Leap::Vector tempThumbPos = thumbFinger.bone(Leap::Bone::TYPE_METACARPAL).center();
            ofPoint temp = leap.getMappedofPoint( tempThumbPos );
           //convert to ofPoint data type
            thumb_metacarpal_position.set(temp.x, temp.y, temp.z);

            Leap::Vector tempindexPos = indexFinger.bone(Leap::Bone::TYPE_METACARPAL).center();
           //convert to ofPoint data type
            index_metacarpal_position.set(tempindexPos.x, tempindexPos.y, tempThumbPos.z);

            //2.
            //https://developer-archive.leapmotion.com/documentation/javascript/devguide/Intro_Skeleton_API.html
            //The normalized direction of the bone from base to tip.
            Leap::Vector tempThumbDirection = thumbFinger.bone(Leap::Bone::TYPE_PROXIMAL).direction();
             //convert to ofPoint data type
            thumb_metacarpal_direction.set(tempThumbDirection.x, tempThumbDirection.y, tempThumbDirection.z);


            //The normalized direction of the bone from base to tip.
            Leap::Vector tempindexDirection = indexFinger.bone(Leap::Bone::TYPE_METACARPAL).direction();
            //convert to ofPoint data type
            index_metacarpal_direction.set(tempindexDirection.x, tempindexDirection.y, tempindexDirection.z);

            //3.
            angle = (tempThumbPos.angleTo(tempindexPos) * 180)

#2

I found a round-about solution by measuring the metacarpal->tip resultant vectors from the joint positional vectors… not sure why the API methods didn’t work as expected. I’ll look into it…