/// <summary> /// 获取每个骨骼分别与坐标系的夹角(X,Y,Z轴的夹角) /// </summary> /// <param name="joints3"></param> /// <returns></returns> public static List <KeyBone> GetBodyAllKeyBones(IReadOnlyDictionary <JointType, Joint> joints3) { var boneDic = SkeletonDictionary.GetBoneDic(); var jointDic = SkeletonDictionary.GetJointDic(); List <KeyBone> keyBones = new List <KeyBone>(); foreach (Bone bone in SkeletonDictionary.GetBoneDic().Keys) { CameraSpacePoint point1 = joints3[boneDic[bone].Item1].Position; CameraSpacePoint point2 = joints3[boneDic[bone].Item2].Position; CameraSpacePoint vector = VectorHelp.GetVector(point1, point2); KeyBone keyBone = new KeyBone { Name = bone, Vector = vector, AngleX = VectorHelp.GetVectorAngle(vector, new CameraSpacePoint() { X = 1, Y = 0, Z = 0 }), AngleY = VectorHelp.GetVectorAngle(vector, new CameraSpacePoint() { X = 0, Y = 1, Z = 0 }), AngleZ = VectorHelp.GetVectorAngle(vector, new CameraSpacePoint() { X = 0, Y = 0, Z = 1 }) }; keyBones.Add(keyBone); } return(keyBones); }
/// <summary> /// 获取所有关节的角度 /// </summary> /// <param name="joints3">关节的三维坐标</param> /// <returns></returns> public static List <JointAngle> GetBodyJointAngleList(IReadOnlyDictionary <JointType, Joint> joints3) { List <JointAngle> jointAngles = new List <JointAngle>(); //骨头字典 Dictionary <Bone, Tuple <JointType, JointType> > boneDic = SkeletonDictionary.GetBoneDic(); //关节字典 Dictionary <JointType, Tuple <Bone, Bone> > jointDic = SkeletonDictionary.GetJointDic(); foreach (KeyValuePair <JointType, Tuple <Bone, Bone> > pair in jointDic) { Tuple <JointType, JointType> bondVectorTuple1 = boneDic[pair.Value.Item1]; Tuple <JointType, JointType> bondVectorTuple2 = boneDic[pair.Value.Item2]; CameraSpacePoint vector1 = VectorHelp.GetVector(joints3[bondVectorTuple1.Item1].Position, joints3[bondVectorTuple1.Item2].Position); CameraSpacePoint vector2 = VectorHelp.GetVector(joints3[bondVectorTuple2.Item2].Position, joints3[bondVectorTuple2.Item1].Position); float angle = VectorHelp.GetVectorAngle(vector1, vector2); //angle = (float) Math.Round(angle, 2); jointAngles.Add(new JointAngle(pair.Key, angle)); } return(jointAngles); }