gpt4 book ai didi

c# - 使用 Kinect 寻找肘部角度

转载 作者:行者123 更新时间:2023-11-30 22:15:07 25 4
gpt4 key购买 nike

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

所以它一直返回 NaN?我真的很感激一些帮助:)非常感谢你们!!

最佳答案

您必须规范化您的向量。尝试添加此代码。我建议您自己执行 AngleBetweenVector 方法(参见下面的代码)。

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. 定义向量
  2. 减去
  3. 传递给AngleBetweenTwoVectors - 方法
  4. (在 AngleBetweenTwoVectors 中)归一化(除以每个轴上的矢量长度)以获取更多信息 here
  5. 计算点积(更多here)
  6. 使用阿科斯(阿科斯)方法
  7. Product/PI*180,否则你会得到 radian

关于c# - 使用 Kinect 寻找肘部角度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18154420/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com