# Regarding Joint co-ordinates • ### Question

• If I am not mistaken, the 20 joint positions (i mean their 3D co-ordinates) are available in

SkeletonFrame.SkeletonData[i].skeletonPositions[j].x .....

Here j varies from 0 to 19 right ??? So which joint corresponds to which array index ...

Where can i find that details .. Or is there a better way to access joint co-ordinates ???

Thank in advance fro the help ..

Saturday, June 18, 2011 7:35 AM

• oh i got it !!!

we can use NUI_SKELETON_POSITION_HEAD, NUI_SKELETON_POSITION_ELBOW_LEFT and so on as the array index.

[moderator] this is solution for C++ native code
Saturday, June 18, 2011 9:22 AM
• As shown in the quickstart series the easiest way to select a joint from the array is:

```skeleton.Joints[JointID.HandLeft]
```

This gives you the Joint, you can extract the Position from that..

Joint orientation data is not provided by the engine. You have to calculate it on your own.

By the way:

If you want to calculate with the positions (like determining the distance or so): I've made a class for that. EDIT: see down there vv

~theCake

[moderator] And this is solution for C# managed code
• Edited by Monday, June 20, 2011 10:41 AM to include all information for this post to be an answer to the initial question.
• Proposed as answer by Monday, June 20, 2011 10:42 AM
• Marked as answer by Tuesday, June 21, 2011 10:44 PM
• Edited by Tuesday, June 21, 2011 10:45 PM qualifying solution with applicable language
Saturday, June 18, 2011 2:12 PM

### All replies

• oh i got it !!!

we can use NUI_SKELETON_POSITION_HEAD, NUI_SKELETON_POSITION_ELBOW_LEFT and so on as the array index.

[moderator] this is solution for C++ native code
Saturday, June 18, 2011 9:22 AM
• As shown in the quickstart series the easiest way to select a joint from the array is:

```skeleton.Joints[JointID.HandLeft]
```

This gives you the Joint, you can extract the Position from that..

Joint orientation data is not provided by the engine. You have to calculate it on your own.

By the way:

If you want to calculate with the positions (like determining the distance or so): I've made a class for that. EDIT: see down there vv

~theCake

[moderator] And this is solution for C# managed code
• Edited by Monday, June 20, 2011 10:41 AM to include all information for this post to be an answer to the initial question.
• Proposed as answer by Monday, June 20, 2011 10:42 AM
• Marked as answer by Tuesday, June 21, 2011 10:44 PM
• Edited by Tuesday, June 21, 2011 10:45 PM qualifying solution with applicable language
Saturday, June 18, 2011 2:12 PM
• As shown in the quickstart series the easiest way to select a joint from the array is:

```skeleton.Joints[JointID.HandLeft]
```

This gives you the Joint, you can extract the Position from that..

By the way:

If you want to calculate with the positions (like determining the distance or so): I've made a class for that. Just say if you want the code^^

~theCake

Do you mean Code to Calculate the Orientation of the Joint? Or just the position in space? I'm still in the process of trying to find a Joint's Orientation Matrix :)
Saturday, June 18, 2011 11:02 PM
• The joint orientations are not provided by the engine. You have to calculate them on your own.

You can use my Point3D class to calculate with joint/3D positions:

```using System;
using Microsoft.Research.Kinect.Nui;

namespace YourNamespace
{
/// <summary>
/// A coordinate in 3D-space.
/// </summary>
class Point3D
{
public double X, Y, Z;
/// <summary>
/// 3D coordinate from components.
/// </summary>
/// <param name="X">X component</param>
/// <param name="Y">Y component</param>
/// <param name="Z">Z component</param>
public Point3D(double X, double Y, double Z)
{
this.X = X;
this.Y = Y;
this.Z = Z;
}
/// <summary>
/// 3D coordinate from Microsoft.Research.Kinect.Nui.Joint
/// </summary>
/// <param name="j">A Microsoft.Research.Kinect.Nui.Joint</param>
public Point3D(Joint j)
{
this.X = j.Position.X;
this.Y = j.Position.Y;
this.Z = j.Position.Z;
}
/// <summary>
/// Vector (Point3D) from one Point3D to another. (same as B - A)
/// </summary>
/// <param name="p1">A</param>
/// <param name="p2">B</param>
/// <returns></returns>
public static Point3D Vector(Point3D p1, Point3D p2)
{
return new Point3D(p2.X - p1.X, p2.Y - p1.Y, p2.Z - p1.Z);
}
/// <summary>
/// Substracts two Point3Ds.
/// </summary>
/// <param name="p1">a</param>
/// <param name="p2">b</param>
/// <returns></returns>
public static Point3D operator -(Point3D p1, Point3D p2)
{
return new Point3D(p2.X - p1.X, p2.Y - p1.Y, p2.Z - p1.Z);
}
/// <summary>
/// </summary>
/// <param name="p1">a</param>
/// <param name="p2">b</param>
/// <returns></returns>
public static Point3D operator +(Point3D p1, Point3D p2)
{
return new Point3D(p2.X + p1.X, p2.Y + p1.Y, p2.Z + p1.Z);
}
/// <summary>
/// Scales a Point3D (like a vector).
/// </summary>
/// <param name="p">vector</param>
/// <param name="factor">factor</param>
/// <returns></returns>
public static Point3D operator *(Point3D p, double factor)
{
return new Point3D(p.X * factor, p.Y * factor, p.Z * factor);
}
/// <summary>
/// Reverse operation to *
/// </summary>
/// <param name="p">vector</param>
/// <param name="quotient">quotient</param>
/// <returns></returns>
public static Point3D operator /(Point3D p, double quotient)
{
return new Point3D(p.X / quotient, p.Y / quotient, p.Z / quotient);
}
/// <summary>
/// Returns the length of a Point3D
/// </summary>
/// <param name="vector">v</param>
/// <returns>lenght of Point3D-vector</returns>
public static double Length(Point3D vector)
{
return Math.Sqrt(vector.X * vector.X + vector.Y * vector.Y + vector.Z * vector.Z);
}
/// <summary>
/// Calculates the Point3d in the middle between two Point3Ds
/// </summary>
/// <param name="p1">A</param>
/// <param name="p2">B</param>
/// <returns>the Point3D in the middle</returns>
public static Point3D Center(Point3D p1, Point3D p2)
{
return new Point3D((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2, (p1.Z + p2.Z) / 2);
}
}
}
```

For example:

```Point3D joint1 = new Point3D(skeleton.Joints[JointID.ElbowLeft]);
Point3D joint2 = new Point3D(skeleton.Joints[JointID.WristLeft]);
//
Point3D vector = Point3D.Vector(joint1, joint2);
//same as
Point3D vector = joint2 - joint1;
```

have fun ;)

Sunday, June 19, 2011 1:09 PM
• Ah yeah, I'm already doing something similar in XNA with Vector3's. I instead used an extension method:

```    public static Vector3 ToVector3(this Vector nuiVector)
{
return new Vector3(nuiVector.X, nuiVector.Y, nuiVector.Z);
}
```
Was hoping you'd been doing Joint Orientation stuff. Ah well.

Sunday, June 19, 2011 5:24 PM
• Thi thing with joint orientations is that there is no logical orientation for something like ShoulderCenter.. I suppose that's the reason they left it out.

btw.: do you have a clue how to track additional objects? To be specific: a rod the user holds with his hand. (light-sabers you know^^) -> I was thinking of looping through all pixels in the depth-image that are near to a hand-joint and then calculate a line from their positions..

Sunday, June 19, 2011 6:34 PM
• I haven't gotten into the depth Image Data just yet. If I figure anything out, I'm sure I'll blog about it

I kinda figure that Orientation needs to be thought of in terms of 3D Bones, where HipCenter would be oriented towards ShoulderCenter, the root of the skeleton. From there you have to create bone orientations toward each child bone, so ShoulderRight and ShoulderLeft would be the children and so forth.

Sunday, June 19, 2011 7:51 PM