none
Need angle of user rotation? RRS feed

  • Question

  • Hi All,

    How to find the angle of user rotation (0-360) relatively standing at the same location infront of kinect. Anyone please provide a formula/detailed explanation for this.

    Thanks,

    Bharat.

    Tuesday, February 28, 2012 11:30 AM

Answers

  • Try something like this:

            double GetShoulderRotation(Skeleton skeleton)
            {
                Joint leftShoulder = skeleton.Joints[JointType.ShoulderLeft];
                Joint rightShoulder = skeleton.Joints[JointType.ShoulderRight];
                if (leftShoulder.TrackingState == JointTrackingState.NotTracked ||
                    rightShoulder.TrackingState == JointTrackingState.NotTracked)
                {
                    return Double.NaN;
                }
                else
                {
                    return Math.Atan2(
                        rightShoulder.Position.Z - leftShoulder.Position.Z, 
                        leftShoulder.Position.X - rightShoulder.Position.X) * 180.0 / Math.PI;
                }
            }
    

    This will return NaN if either shoulder isn't tracked. Otherwise, it should return an angle in degrees. Zero means facing directly forward.

    John
    K4W Dev

    Wednesday, February 29, 2012 5:04 AM

All replies

  • Last time I tried, facing away from the Kinect gave bad data; it said I was facing the Kinect, with my arms behind my body. I'd expect a little less than 180 degrees of useful data.

    For angle of rotation, either go for the two shoulder points, or two hip joints. (Or average them.) Use the X and Z coords, and form a right triangle. Use trigonometry to find the angles, then add/subtract 90 degrees to find the angle.

    Tuesday, February 28, 2012 9:01 PM
  • Hi,

    can you provide any code help, I have tried different ways, no one worked out. The angles I get are very flickery and widely varying.

    Thanks,

    Bharat

    Wednesday, February 29, 2012 3:51 AM
  • Try something like this:

            double GetShoulderRotation(Skeleton skeleton)
            {
                Joint leftShoulder = skeleton.Joints[JointType.ShoulderLeft];
                Joint rightShoulder = skeleton.Joints[JointType.ShoulderRight];
                if (leftShoulder.TrackingState == JointTrackingState.NotTracked ||
                    rightShoulder.TrackingState == JointTrackingState.NotTracked)
                {
                    return Double.NaN;
                }
                else
                {
                    return Math.Atan2(
                        rightShoulder.Position.Z - leftShoulder.Position.Z, 
                        leftShoulder.Position.X - rightShoulder.Position.X) * 180.0 / Math.PI;
                }
            }
    

    This will return NaN if either shoulder isn't tracked. Otherwise, it should return an angle in degrees. Zero means facing directly forward.

    John
    K4W Dev

    Wednesday, February 29, 2012 5:04 AM