c# - Finding Elbow Angle with Kinect -


vector3d rwrist = new vector3d(skel.joints[jointtype.wristright].position.x,             skel.joints[jointtype.wristright].position.y, skel.joints[jointtype.wristright].position.z);         vector3d relbow = new vector3d(skel.joints[jointtype.elbowright].position.x,             skel.joints[jointtype.elbowright].position.y, skel.joints[jointtype.elbowright].position.z);         vector3d rshoulder = new vector3d(skel.joints[jointtype.shoulderright].position.x,             skel.joints[jointtype.shoulderright].position.y, skel.joints[jointtype.shoulderright].position.z);          vector3d wristtoelbow = vector3d.subtract(rwrist, relbow);         vector3d elbowtoshoulder = vector3d.subtract(relbow, rshoulder);          elbowangle = vector3d.anglebetween(elbowtoshoulder, wristtoelbow); 

so keeps returning nan? appreciate :) guys!!

you have normalize vectors. try adding code. recommend anglebetweenvector method (see code below).

public class angles     {     public double anglebetweentwovectors(vector3d vectora, vector3d vectorb)         {             double dotproduct;             vectora.normalize();             vectorb.normalize();             dotproduct = vector3d.dotproduct(vectora, vectorb);              return (double)math.acos(dotproduct)/math.pi*180;         }          public byte[] getvector(skeleton skeleton)         {             vector3d rightshoulder = new vector3d(skeleton.joints[jointtype.shoulderright].position.x, skeleton.joints[jointtype.shoulderright].position.y, skeleton.joints[jointtype.shoulderright].position.z);             vector3d leftshoulder = new vector3d(skeleton.joints[jointtype.shoulderleft].position.x, skeleton.joints[jointtype.shoulderleft].position.y, skeleton.joints[jointtype.shoulderleft].position.z);             vector3d rightelbow = new vector3d(skeleton.joints[jointtype.elbowright].position.x, skeleton.joints[jointtype.elbowright].position.y, skeleton.joints[jointtype.elbowright].position.z);             vector3d leftelbow = new vector3d(skeleton.joints[jointtype.elbowleft].position.x, skeleton.joints[jointtype.elbowleft].position.y, skeleton.joints[jointtype.elbowleft].position.z);             vector3d rightwrist = new vector3d(skeleton.joints[jointtype.wristright].position.x, skeleton.joints[jointtype.wristright].position.y, skeleton.joints[jointtype.wristright].position.z);             vector3d leftwrist = new vector3d(skeleton.joints[jointtype.wristleft].position.x, skeleton.joints[jointtype.wristleft].position.y, skeleton.joints[jointtype.wristleft].position.z);               double anglerightelbow = anglebetweentwovectors(rightelbow - rightshoulder, rightelbow - rightwrist);             double angleleftelbow = anglebetweentwovectors(leftelbow - leftshoulder, leftelbow - leftwrist);              byte[] angles = {convert.tobyte(anglerightelbow), convert.tobyte(anglerightshoulder),convert.tobyte(angleleftelbow),convert.tobyte(angleleftshoulder)};             return angles;         } } 
  1. define vectors
  2. substract
  3. pass anglebetweentwovectors - method
  4. (in anglebetweentwovectors) normalize (divide vector length on every axis) more information here
  5. calculate dot product (for more here)
  6. use arcosinus (arcos) method
  7. product/pi*180, otherwise radian

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -