Exemple #1
0
        public static float getAngleNew(Vecto3Float vect1, Vecto3Float vect2)

        {
            vect1.normalize();
            vect2.normalize();

            if (vect1.magnitude() != 0.0 && vect2.magnitude() != 0.0)
            {
                double x = (double)vect1.cross(vect2).magnitude();
                double y = (double)vect1.dot(vect2);

                return(atan2(x, y));
            }
            else
            {
                return(0f);
            }
        }
Exemple #2
0
        ///<summary>
        /// Compute angle between the joint according to the position of the joint
        ///</summary>
        private void angleVector()
        {
            SkeletonPoint shoulderLeft   = this.avgPoint[JointType.ShoulderLeft];
            SkeletonPoint shoulderCenter = this.avgPoint[JointType.ShoulderCenter];
            SkeletonPoint shoulderRight  = this.avgPoint[JointType.ShoulderRight];

            SkeletonPoint elbowLeft  = this.avgPoint[JointType.ElbowLeft];
            SkeletonPoint elbowRight = this.avgPoint[JointType.ElbowRight];

            SkeletonPoint wristLeft  = this.avgPoint[JointType.WristLeft];
            SkeletonPoint wristRight = this.avgPoint[JointType.WristRight];

            SkeletonPoint hipLeft   = this.avgPoint[JointType.HipLeft];
            SkeletonPoint hipCenter = this.avgPoint[JointType.HipCenter];
            SkeletonPoint hipRight  = this.avgPoint[JointType.HipRight];

            Vecto3Float upperArmLeft = new Vecto3Float(shoulderLeft.X - elbowLeft.X,
                                                       shoulderLeft.Y - elbowLeft.Y,
                                                       shoulderLeft.Z - elbowLeft.Z);

            Vecto3Float lowerArmLeft = new Vecto3Float(wristLeft.X - elbowLeft.X,
                                                       wristLeft.Y - elbowLeft.Y,
                                                       wristLeft.Z - elbowLeft.Z);

            Vecto3Float upperArmRight = new Vecto3Float(shoulderRight.X - elbowRight.X,
                                                        shoulderRight.Y - elbowRight.Y,
                                                        shoulderRight.Z - elbowRight.Z);

            Vecto3Float lowerArmRight = new Vecto3Float(wristRight.X - elbowRight.X,
                                                        wristRight.Y - elbowRight.Y,
                                                        wristRight.Z - elbowRight.Z);


            Vecto3Float shoulderLToHipLeft = new Vecto3Float(shoulderLeft.X - hipLeft.X,
                                                             shoulderLeft.Y - hipLeft.Y,
                                                             shoulderLeft.Z - hipLeft.Z);

            Vecto3Float shoulderRToHipRight = new Vecto3Float(shoulderRight.X - hipRight.X,
                                                              shoulderRight.Y - hipRight.Y,
                                                              shoulderRight.Z - hipRight.Z);

            Vecto3Float shoulderLToShoulderC = new Vecto3Float(shoulderLeft.X - shoulderCenter.X,
                                                               shoulderLeft.Y - shoulderCenter.Y,
                                                               shoulderLeft.Z - shoulderCenter.Z);

            Vecto3Float shoulderRToShoulderC = new Vecto3Float(shoulderRight.X - shoulderCenter.X,
                                                               shoulderRight.Y - shoulderCenter.Y,
                                                               shoulderRight.Z - shoulderCenter.Z);


            if (hipLeft.Z + 0.15 > elbowLeft.Z)   //if the elbow is in front of the hip
            {
                //Shoulder Roll
                //Left

                if (Math.Abs(shoulderLeft.Z - elbowLeft.Z) < 0.1 &&
                    Math.Abs(shoulderLeft.X - elbowLeft.X) < 0.1)
                {
                    this.jointAngles[NAOConversion.LShoulderRoll] = NAOConversion.convertAngle(NAOConversion.LShoulderRoll,
                                                                                               Kinematic.getAngleNew(upperArmLeft.projectionOntoXY(),
                                                                                                                     shoulderLToHipLeft.projectionOntoXY()));
                }
                else
                {
                    this.jointAngles[NAOConversion.LShoulderRoll] = NAOConversion.convertAngle(NAOConversion.LShoulderRoll,
                                                                                               Kinematic.getAngleNew(upperArmLeft.projectionOntoZX(),
                                                                                                                     shoulderLToHipLeft.projectionOntoZX()));
                }


                //Shoulder Pitch
                //Left
                this.jointAngles[NAOConversion.LShoulderPitch] = NAOConversion.convertAngle(NAOConversion.LShoulderPitch,
                                                                                            Kinematic.getAngleNew(upperArmLeft.projectionOntoZY(),
                                                                                                                  shoulderLToHipLeft.projectionOntoZY()));
            }

            if (hipRight.Z + 0.15 > elbowRight.Z)//if the elbow is in front of the hip

            {
                //Shoulder Roll
                //Right
                if (Math.Abs(shoulderRight.Z - elbowRight.Z) < 0.1 &&
                    Math.Abs(shoulderRight.X - elbowRight.X) < 0.1)
                {
                    this.jointAngles[NAOConversion.RShoulderRoll] = NAOConversion.convertAngle(NAOConversion.RShoulderRoll,
                                                                                               Kinematic.getAngleNew(upperArmRight.projectionOntoXY(),
                                                                                                                     shoulderRToHipRight.projectionOntoXY()));
                }
                else
                {
                    this.jointAngles[NAOConversion.RShoulderRoll] = NAOConversion.convertAngle(NAOConversion.RShoulderRoll,
                                                                                               Kinematic.getAngleNew(upperArmRight.projectionOntoZX(),
                                                                                                                     shoulderRToHipRight.projectionOntoZX()));
                }
                //Shoulder Pitch
                //Right
                this.jointAngles[NAOConversion.RShoulderPitch] = NAOConversion.convertAngle(NAOConversion.RShoulderPitch,
                                                                                            Kinematic.getAngleNew(shoulderRToHipRight.projectionOntoZY(),
                                                                                                                  upperArmRight.projectionOntoZY()));
            }


            //Elbow Roll
            //Left
            this.jointAngles[NAOConversion.LElbowRoll] = NAOConversion.convertAngle(NAOConversion.LElbowRoll,
                                                                                    Kinematic.getAngleNew(upperArmLeft, lowerArmLeft));
            //Right
            this.jointAngles[NAOConversion.RElbowRoll] = NAOConversion.convertAngle(NAOConversion.RElbowRoll,
                                                                                    Kinematic.getAngleNew(upperArmRight, lowerArmRight));

            //Elbow Yaw
            ////Left
            Vecto3Float shoulderLTohipCenter = new Vecto3Float(shoulderLeft.X - hipCenter.X,
                                                               shoulderLeft.Y - hipCenter.Y,
                                                               shoulderLeft.Z - hipCenter.Z);
            Vecto3Float lCrossCenterArm = upperArmLeft.cross(shoulderLTohipCenter);
            Vecto3Float lCrossArms      = upperArmLeft.cross(lowerArmLeft);
            float       lElbowYaw       = Kinematic.getAngleNew(lCrossCenterArm, lCrossArms);

            this.jointAngles[NAOConversion.LElbowYaw] = NAOConversion.convertAngle(NAOConversion.LElbowYaw, lElbowYaw);


            //Right
            Vecto3Float shoulderRTohipCenter = new Vecto3Float(shoulderRight.X - hipCenter.X,
                                                               shoulderRight.Y - hipCenter.Y,
                                                               shoulderRight.Z - hipCenter.Z);
            Vecto3Float rCrossCenterArm = upperArmRight.cross(shoulderRTohipCenter);
            Vecto3Float rCrossArms      = upperArmRight.cross(lowerArmRight);
            float       rElbowYaw       = Kinematic.getAngleNew(rCrossCenterArm, rCrossArms);

            this.jointAngles[NAOConversion.RElbowYaw] = NAOConversion.convertAngle(NAOConversion.RElbowYaw, rElbowYaw);
        }
Exemple #3
0
        public static float getAngleNew(Vecto3Float vect1, Vecto3Float vect2)
        {
            vect1.normalize();
            vect2.normalize();

            if (vect1.magnitude() != 0.0 && vect2.magnitude() != 0.0)
            {
                double x = (double)vect1.cross(vect2).magnitude();
                double y = (double)vect1.dot(vect2);

                return atan2(x, y);
            }
            else
            {
                return 0f;
            }
        }
Exemple #4
0
        ///<summary>
        /// Compute angle between the joint according to the position of the joint
        ///</summary>
        private void angleVector()
        {
            SkeletonPoint shoulderLeft = this.avgPoint[JointType.ShoulderLeft];
            SkeletonPoint shoulderCenter = this.avgPoint[JointType.ShoulderCenter];
            SkeletonPoint shoulderRight = this.avgPoint[JointType.ShoulderRight];

            SkeletonPoint elbowLeft = this.avgPoint[JointType.ElbowLeft];
            SkeletonPoint elbowRight = this.avgPoint[JointType.ElbowRight];

            SkeletonPoint wristLeft = this.avgPoint[JointType.WristLeft];
            SkeletonPoint wristRight = this.avgPoint[JointType.WristRight];

            SkeletonPoint hipLeft = this.avgPoint[JointType.HipLeft];
            SkeletonPoint hipCenter = this.avgPoint[JointType.HipCenter];
            SkeletonPoint hipRight = this.avgPoint[JointType.HipRight];

            Vecto3Float upperArmLeft = new Vecto3Float(shoulderLeft.X - elbowLeft.X,
                                                       shoulderLeft.Y - elbowLeft.Y,
                                                       shoulderLeft.Z - elbowLeft.Z);

            Vecto3Float lowerArmLeft = new Vecto3Float(wristLeft.X - elbowLeft.X,
                                                       wristLeft.Y - elbowLeft.Y,
                                                       wristLeft.Z - elbowLeft.Z);

            Vecto3Float upperArmRight = new Vecto3Float(shoulderRight.X - elbowRight.X,
                                                        shoulderRight.Y - elbowRight.Y,
                                                        shoulderRight.Z - elbowRight.Z);

            Vecto3Float lowerArmRight = new Vecto3Float(wristRight.X - elbowRight.X,
                                                        wristRight.Y - elbowRight.Y,
                                                        wristRight.Z - elbowRight.Z);

            Vecto3Float shoulderLToHipLeft = new Vecto3Float(shoulderLeft.X - hipLeft.X,
                                                             shoulderLeft.Y - hipLeft.Y,
                                                             shoulderLeft.Z - hipLeft.Z);

            Vecto3Float shoulderRToHipRight = new Vecto3Float(shoulderRight.X - hipRight.X,
                                                              shoulderRight.Y - hipRight.Y,
                                                              shoulderRight.Z - hipRight.Z);

            Vecto3Float shoulderLToShoulderC = new Vecto3Float(shoulderLeft.X - shoulderCenter.X,
                                                               shoulderLeft.Y - shoulderCenter.Y,
                                                               shoulderLeft.Z - shoulderCenter.Z);

            Vecto3Float shoulderRToShoulderC = new Vecto3Float(shoulderRight.X - shoulderCenter.X,
                                                               shoulderRight.Y - shoulderCenter.Y,
                                                               shoulderRight.Z - shoulderCenter.Z);

            if (hipLeft.Z + 0.15 > elbowLeft.Z)   //if the elbow is in front of the hip
            {
                //Shoulder Roll
                //Left

                if (Math.Abs(shoulderLeft.Z - elbowLeft.Z) < 0.1 &&
                    Math.Abs(shoulderLeft.X - elbowLeft.X) < 0.1)
                {
                    this.jointAngles[NAOConversion.LShoulderRoll] = NAOConversion.convertAngle(NAOConversion.LShoulderRoll,
                                                                                    Kinematic.getAngleNew(upperArmLeft.projectionOntoXY(),
                                                                                                          shoulderLToHipLeft.projectionOntoXY()));
                }
                else
                {
                    this.jointAngles[NAOConversion.LShoulderRoll] = NAOConversion.convertAngle(NAOConversion.LShoulderRoll,
                                                                                     Kinematic.getAngleNew(upperArmLeft.projectionOntoZX(),
                                                                                                           shoulderLToHipLeft.projectionOntoZX()));
                }

                //Shoulder Pitch
                //Left
                this.jointAngles[NAOConversion.LShoulderPitch] = NAOConversion.convertAngle(NAOConversion.LShoulderPitch,
                                                                                             Kinematic.getAngleNew(upperArmLeft.projectionOntoZY(),
                                                                                                                   shoulderLToHipLeft.projectionOntoZY()));
            }

            if (hipRight.Z + 0.15 > elbowRight.Z)//if the elbow is in front of the hip

            {

                //Shoulder Roll
                //Right
                if (Math.Abs(shoulderRight.Z - elbowRight.Z) < 0.1 &&
                    Math.Abs(shoulderRight.X - elbowRight.X) < 0.1)
                {
                    this.jointAngles[NAOConversion.RShoulderRoll] = NAOConversion.convertAngle(NAOConversion.RShoulderRoll,
                                                                                    Kinematic.getAngleNew(upperArmRight.projectionOntoXY(),
                                                                                                          shoulderRToHipRight.projectionOntoXY()));
                }
                else
                {
                    this.jointAngles[NAOConversion.RShoulderRoll] = NAOConversion.convertAngle(NAOConversion.RShoulderRoll,
                                                                                     Kinematic.getAngleNew(upperArmRight.projectionOntoZX(),
                                                                                                           shoulderRToHipRight.projectionOntoZX()));
                }
                //Shoulder Pitch
                //Right
                this.jointAngles[NAOConversion.RShoulderPitch] = NAOConversion.convertAngle(NAOConversion.RShoulderPitch,
                                                                                             Kinematic.getAngleNew(shoulderRToHipRight.projectionOntoZY(),
                                                                                                                    upperArmRight.projectionOntoZY()));
            }

            //Elbow Roll
            //Left
            this.jointAngles[NAOConversion.LElbowRoll] = NAOConversion.convertAngle(NAOConversion.LElbowRoll,
                                                                                     Kinematic.getAngleNew(upperArmLeft, lowerArmLeft));
            //Right
            this.jointAngles[NAOConversion.RElbowRoll] = NAOConversion.convertAngle(NAOConversion.RElbowRoll,
                                                                                    Kinematic.getAngleNew(upperArmRight, lowerArmRight));

            //Elbow Yaw
            ////Left
            Vecto3Float shoulderLTohipCenter = new Vecto3Float(shoulderLeft.X - hipCenter.X,
                                                               shoulderLeft.Y - hipCenter.Y,
                                                               shoulderLeft.Z - hipCenter.Z);
            Vecto3Float lCrossCenterArm = upperArmLeft.cross(shoulderLTohipCenter);
            Vecto3Float lCrossArms = upperArmLeft.cross(lowerArmLeft);
            float lElbowYaw = Kinematic.getAngleNew(lCrossCenterArm, lCrossArms);
            this.jointAngles[NAOConversion.LElbowYaw] = NAOConversion.convertAngle(NAOConversion.LElbowYaw, lElbowYaw);

            //Right
            Vecto3Float shoulderRTohipCenter = new Vecto3Float(shoulderRight.X - hipCenter.X,
                                                               shoulderRight.Y - hipCenter.Y,
                                                               shoulderRight.Z - hipCenter.Z);
            Vecto3Float rCrossCenterArm = upperArmRight.cross(shoulderRTohipCenter);
            Vecto3Float rCrossArms = upperArmRight.cross(lowerArmRight);
            float rElbowYaw = Kinematic.getAngleNew(rCrossCenterArm, rCrossArms);
            this.jointAngles[NAOConversion.RElbowYaw] = NAOConversion.convertAngle(NAOConversion.RElbowYaw, rElbowYaw);
        }