コード例 #1
0
        //http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/

        public MyQuaternion ConverFromAxisAngle(MyQuaternion _A)
        {
            MyQuaternion Result = _A;

            if (Result.W > 1)
            {
                _A.Normalize(Result);
            }
            float angle = 2 * Mathf.Acos(Result.W);
            float s     = Mathf.Acos(1 - Result.W * Result.W);

            if (s < 0.01f)
            {
                Result.X = _A.X;
                Result.Y = _A.Y;
                Result.Z = _A.Z;
            }
            else
            {
                Result.X = _A.X / s;
                Result.Y = _A.Y / s;
                Result.Z = _A.Z / s;
            }
            return(Result);
        }
コード例 #2
0
        //http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
        public MyQuaternion ConvertToAxisAngle(MyQuaternion _A, float _ALFA)
        {
            MyQuaternion Result = _A;

            Result.W = Mathf.Cos(_ALFA / 2);//definicion del angulo teta
            Result.X = Result.X * Mathf.Sin(_ALFA / 2);
            Result.Y = Result.Y * Mathf.Sin(_ALFA / 2);
            Result.Z = Result.Z * Mathf.Sin(_ALFA / 2);
            Result.Normalize(Result);
            return(Result);
        }