コード例 #1
0
ファイル: Point.cs プロジェクト: pashcovich/sparrow-sharp
        /// <summary>
        /// Rotates by the specified angle in Radians
        /// </summary>
        public void RotateBy(float angle)
        {
            float sin = NumberUtil.FastSin(angle);
            float cos = NumberUtil.FastCos(angle);

            X = X * cos - Y * sin;
            Y = X * sin + Y * cos;
        }
コード例 #2
0
ファイル: Matrix.cs プロジェクト: pashcovich/sparrow-sharp
        /// <summary>
        /// Applies a rotation on the matrix (angle in radians).
        /// </summary>
        public void Rotate(float angleInRadians)
        {
            if (angleInRadians == 0.0f)
            {
                return;
            }
            float sin = NumberUtil.FastSin(angleInRadians);
            float cos = NumberUtil.FastCos(angleInRadians);

            float a  = A * cos - B * sin;
            float b  = A * sin + B * cos;
            float c  = C * cos - D * sin;
            float d  = C * sin + D * cos;
            float tx = Tx * cos - Ty * sin;
            float ty = Tx * sin + Ty * cos;

            A  = a;
            B  = b;
            C  = c;
            D  = d;
            Tx = tx;
            Ty = ty;
        }
コード例 #3
0
        public string TestLUTAccuracy()
        {
            float  angle        = -1000;
            int    numIter      = (int)Math.Abs(angle) * 200;
            float  angleDiff    = Math.Abs(angle) * 2 / numIter;
            double biggestError = 0;

            for (int i = 0; i < numIter; i++)
            {
                angle += angleDiff;
                var sinDiff = Math.Abs(Math.Abs(Math.Sin(angle)) - Math.Abs(NumberUtil.FastSin(angle)));
                var cosDiff = Math.Abs(Math.Abs(Math.Cos(angle)) - Math.Abs(NumberUtil.FastCos(angle)));
                if (sinDiff > biggestError)
                {
                    biggestError = sinDiff;
                }
                if (cosDiff > biggestError)
                {
                    biggestError = sinDiff;
                }
            }
            return("largest error: " + biggestError); // around 0.0045
        }