# how to calculate the distance of players [Kinect]

• ### Question

• is there a way to determine the player distance?

i'de like to determine the distance between kinect and players and tell them if they are too near or too far from the kinect...

thanks

• Edited by Wednesday, June 13, 2012 3:56 PM
Wednesday, June 13, 2012 3:42 PM

• Each Skeleton has a Position property, which describes the X, Y and Z coordinates in real-world coordinates.

Wednesday, June 13, 2012 6:35 PM
• have you tried

```private static short CalculateDistanceFromDepth(byte first, byte second)
{
return (short)(first | second << 8);
}```

and then

```for (int depthColumnIndex = 0; depthColumnIndex < 640; depthColumnIndex += 2)
{
var depthIndex = depthColumnIndex + (depthRowIndex * 640);

var index = depthIndex * 2;

var distance = CalculateDistanceFromDepth(depthFrame[depthIndex], depthFrame[depthIndex + 1]);
}```

or something like this

```short[] rawDepthData = new short[depthFrame.PixelDataLength];
depthFrame.CopyPixelDataTo(rawDepthData);
int depth = rawDepthData[depthIndex] >> DepthImageFrame.PlayerIndexBitmaskWidth;```

Wednesday, June 13, 2012 6:11 PM

### All replies

• have you tried

```private static short CalculateDistanceFromDepth(byte first, byte second)
{
return (short)(first | second << 8);
}```

and then

```for (int depthColumnIndex = 0; depthColumnIndex < 640; depthColumnIndex += 2)
{
var depthIndex = depthColumnIndex + (depthRowIndex * 640);

var index = depthIndex * 2;

var distance = CalculateDistanceFromDepth(depthFrame[depthIndex], depthFrame[depthIndex + 1]);
}```

or something like this

```short[] rawDepthData = new short[depthFrame.PixelDataLength];
depthFrame.CopyPixelDataTo(rawDepthData);
int depth = rawDepthData[depthIndex] >> DepthImageFrame.PlayerIndexBitmaskWidth;```

Wednesday, June 13, 2012 6:11 PM
• Each Skeleton has a Position property, which describes the X, Y and Z coordinates in real-world coordinates.