public static double PathLengthBetween(this Skeleton skeleton, JointType first, JointType second) { JointPath path = JointPath.Between(first, second); double length = 0; for (int i = 1; i < path.Count; i++) { length += skeleton.Joints[path[i - 1]].DistanceTo(skeleton.Joints[path[i]]); } return(length); }
static JointPath() { int[,] nextInPath = new int[20, 20] { { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 12, 12, 12, 12, 16, 16, 16, 16 }, { 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0 }, { 1, 1, 2, 3, 4, 4, 4, 4, 8, 8, 8, 8, 1, 1, 1, 1, 1, 1, 1, 1 }, { 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }, { 2, 2, 2, 2, 4, 5, 5, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }, { 4, 4, 4, 4, 4, 5, 6, 6, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 }, { 5, 5, 5, 5, 5, 5, 6, 7, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 }, { 6, 6, 6, 6, 6, 6, 6, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6 }, { 2, 2, 2, 2, 2, 2, 2, 2, 8, 9, 9, 9, 2, 2, 2, 2, 2, 2, 2, 2 }, { 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 10, 10, 8, 8, 8, 8, 8, 8, 8, 8 }, { 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 11, 9, 9, 9, 9, 9, 9, 9, 9 }, { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 10, 10, 10, 10, 10, 10, 10, 10 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 13, 13, 13, 0, 0, 0, 0 }, { 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 14, 14, 12, 12, 12, 12 }, { 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 15, 13, 13, 13, 13 }, { 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 14, 14, 14, 14 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 17, 17, 17 }, { 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 18, 18 }, { 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 18, 19 }, { 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 19 } }; pathBetween = new JointPath[20, 20]; for (int start = 0; start < 20; start++) { for (int end = 0; end < 20; end++) { List <int> path = new List <int>(); int current = start; while (nextInPath[current, end] != current) { path.Add(current); current = nextInPath[current, end]; } pathBetween[start, end] = new JointPath(path.Select(i => (JointType)i)); } } }