示例#1
0
        private void TestAtan2()
        {
            mResult.Append("Testing Atan2 function\r\n");

            int correct = 0;
            int total   = 0;

            for (float x = 0; x < 5f; x += 0.11f)
            {
                for (float y = -20f; y < 20f; y += 0.105f)
                {
                    float m  = (float)Math.Atan2(y, x);
                    float m2 = Math2.Atan2(y, x);

                    const float rad = 180 / 3.141592654f;

                    float dm  = m * rad;
                    float dm2 = m2 * rad;

                    if (Check(x, y, dm, dm2, "Atan2: x {0}, y {1} | {2} != {3}"))
                    {
                        correct++;
                    }

                    total++;
                }
            }

            mResult.AppendFormat("Atan2: Total: {0}, OK: {1}\r\n", total, correct);
        }
示例#2
0
        private void Initialize()
        {
            // Distance from start to center.

            const float twoPi = 2 * 3.141592654f;

            float oox = Origin.X - Center.X;
            float ooy = Origin.Y - Center.Y;

            float eex = End.X - Center.X;
            float eey = End.Y - Center.Y;

            Distance = (float)Math2.Sqrt(oox * oox + ooy * ooy);

            // Alpha angle: start with X axis

            Alpha = (float)Math2.Atan2(ooy, oox);

            // Beta angle: end with X axis

            Beta = (float)Math2.Atan2(eey, eex);

            // Gamma angle is arc angle (beta - alpha)

            if (Alpha < 0 && Beta > 0)
            {
                Gamma = Beta - (Alpha + twoPi);
            }
            else if (Alpha > 0 && Beta < 0)
            {
                Gamma = (Beta + twoPi) - Alpha;
            }
            else
            {
                Gamma = Beta - Alpha;
            }

            if (Math2.Abs(Gamma) > 3.141592654f)
            {
                Gamma = Beta - Alpha;
            }
        }