这是计算两个向量之间角度的代码(代码下方的解释):
public class Angles
{
public double AngleBetweenTwoVectors(Vector3D vectorA, Vector3D vectorB)
{
double dotProduct = 0.0;
dotProduct = Vector3D.DotProduct(vectorA, vectorB);
return (double)Math.Acos(dotProduct)/Math.PI*180;
}
public double[] GetVector(Skeleton skeleton)
{
Vector3D ShoulderCenter = new Vector3D(skeleton.Joints[JointType.ShoulderCenter].Position.X, skeleton.Joints[JointType.ShoulderCenter].Position.Y, skeleton.Joints[JointType.ShoulderCenter].Position.Z);
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);
/* ShoulderCenter.Normalize();
RightShoulder.Normalize();
LeftShoulder.Normalize();
RightElbow.Normalize();
LeftElbow.Normalize();
RightWrist.Normalize();
LeftWrist.Normalize();
if (skeleton.Joints[JointType.ShoulderCenter].TrackingState == JointTrackingState.Tracked) {
}
*/
double AngleRightElbow = AngleBetweenTwoVectors(RightElbow - RightShoulder, RightElbow - RightWrist);
double AngleRightShoulder = AngleBetweenTwoVectors(RightShoulder - ShoulderCenter, RightShoulder - RightElbow);
double AngleLeftElbow = AngleBetweenTwoVectors(LeftElbow - LeftShoulder, LeftElbow - LeftWrist);
double AngleLeftShoulder = AngleBetweenTwoVectors(LeftShoulder - ShoulderCenter, LeftShoulder - LeftElbow);
double[] Angles = {AngleRightElbow, AngleRightShoulder, AngleLeftElbow, AngleLeftShoulder};
return Angles;
}
}
首先我们来看看方法GetVector(Skeleton skeleton)
。在这种方法中,我们首先定义我们的 Vector3D(用于您选择的关节)。然后我们调用该方法AngleBetweenTwoVectors
并给它两个参数。
但是注意。如果我们只给它关节向量,我们将不会得到正确的角度。我们首先必须从 Vector 中减去周围的 Vectors(我们想要从中获取角度的 Vector)。然后我们将这两个向量传递给方法AngleBetweenTwoVectors
。
在这种方法中,我们首先必须计算点积。有关点积的更多信息,请单击此处。使用点积,我们可以计算角度。为此,我们只需要使用该arcos()
方法。
我挣扎的另一件事是:集会。您需要导入:
using System.Windows.Media;
using Microsoft.Kinect;
using Microsoft.Kinect.Toolkit.Fusion;
using System.Windows.Media.Media3D;
要获得 [...].Toolkit.Fusion 程序集,请转到“添加引用”并点击“浏览”。然后,您将从 MicrosoftSDK 的/Kinect/Developer Toolkit v1.8.0/Assemblies 引导至程序集目录。导入程序集并将其添加到您的项目中。