Kinect关节角度计算

时间:2015-04-23 15:08:06

标签: c# math vector kinect

对此抱歉,但我需要一些关于此功能和计算的确认

我目前有这些向量:

   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);

我正在使用此函数计算两个向量之间的角度

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;
}

我这样称呼它:

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

这是对的吗?我只是怀疑自己,因为当我伸直手臂或直立时,我的脖子和肘关节都检测到大约170-175而不是180°的角度

2 个答案:

答案 0 :(得分:1)

我已经确认上述算法在数学上是正确的,但是由于硬件的原因,设备的准确性可能有点偏差,并且个别人体骨骼可能会阻止完美的关节扩展,即180。

答案 1 :(得分:0)

纠正我,如果我错了,但是我想代替这个  return(double)Math.Acos(dotProduct)/ Math.PI * 180 应该是

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

由于Math.Acos返回的角度为弧度,要将其转换为度数,应将其乘以180 / pi