ShatteredPheonix
ShatteredPheonix

Reputation: 77

Kinect Joint Angle Calculation

Sorry about this but I need some conformation about this function and calculation

I currently have these Vectors:

   Vector3D ElbowLeft = new Vector3D(body.Joints[JointType.ElbowLeft].Position.X, body.Joints[JointType.ElbowLeft].Position.Y, body.Joints[JointType.ElbowLeft].Position.Z);
   Vector3D WristLeft = new Vector3D(body.Joints[JointType.WristLeft].Position.X, body.Joints[JointType.WristLeft].Position.Y, body.Joints[JointType.WristLeft].Position.Z);
   Vector3D ShoulderLeft = new Vector3D(body.Joints[JointType.ShoulderLeft].Position.X, body.Joints[JointType.ShoulderLeft].Position.Y, body.Joints[JointType.ShoulderLeft].Position.Z);

   Vector3D Head = new Vector3D(body.Joints[JointType.Head].Position.X, body.Joints[JointType.Head].Position.Y, body.Joints[JointType.Head].Position.Z);
   Vector3D Neck = new Vector3D(body.Joints[JointType.Neck].Position.X, body.Joints[JointType.Neck].Position.Y, body.Joints[JointType.Neck].Position.Z);
   Vector3D SpineShoulder = new Vector3D(body.Joints[JointType.SpineShoulder].Position.X, body.Joints[JointType.SpineShoulder].Position.Y, body.Joints[JointType.SpineShoulder].Position.Z);

I am calculating the angle between the two vectors using this function

public double AngleBetweenTwoVectors(Vector3D vectorA, Vector3D vectorB)
{
    double dotProduct = 0.0;
    vectorA.Normalize();
    vectorB.Normalize();
    dotProduct = Vector3D.DotProduct(vectorA, vectorB);

    return (double)Math.Acos(dotProduct) / Math.PI * 180;
}

And I am calling it like this:

   double LeftElbowAngle = AngleBetweenTwoVectors(ElbowLeft - ShoulderLeft, ElbowLeft - WristLeft);
   double NeckAngle = AngleBetweenTwoVectors(Neck - Head, Neck - SpineBase);

Is this correct? Im just doubting myself because When i put my arm straight or stand up straight it detects an angle of about 170 - 175 rather than 180. on both my neck and my elbow joint

Upvotes: 1

Views: 1776

Answers (2)

mudassir ahmed
mudassir ahmed

Reputation: 201

correct me If I'm wrong but I think instead of this return (double)Math.Acos(dotProduct) / Math.PI * 180 it should be

 return (double)Math.Acos(dotProduct) * (180.0/Math.PI);

since angle returned by Math.Acos is in radian and to convert it into degrees you should be multiplying it to 180/pi

Upvotes: 0

ShatteredPheonix
ShatteredPheonix

Reputation: 77

I have confirmed that the above Algorithim is correct mathematically, however the accuracy of the device may be a bit off due to the hardware, and individual human bones may prevent from perfect joint extension which is 180.

Upvotes: 1

Related Questions