Beispiel #1
0
        static public void TestTrigonometric()
        {
            //Test sin
            AssertAlmostEqualsTrig(FMath.Sin(fint.CreateFromFloat(0) * FMath.Deg2Rad), 0.0f);
            AssertAlmostEqualsTrig(FMath.Sin(fint.CreateFromFloat(90) * FMath.Deg2Rad), 1.0f);
            AssertAlmostEqualsTrig(FMath.Sin(fint.CreateFromFloat(180) * FMath.Deg2Rad), 0.0f);
            AssertAlmostEqualsTrig(FMath.Sin(fint.CreateFromFloat(270) * FMath.Deg2Rad), -1.0f);

            AssertAlmostEqualsTrig(FMath.Sin(fint.CreateFromFloat(30.0f) * FMath.Deg2Rad), 0.5f);
            AssertAlmostEqualsTrig(FMath.Sin(fint.CreateFromFloat(-30.0f) * FMath.Deg2Rad), -0.5f);
            AssertAlmostEqualsTrig(FMath.Sin(fint.CreateFromFloat(60.0f) * FMath.Deg2Rad), 0.86603f);
            AssertAlmostEqualsTrig(FMath.Sin(fint.CreateFromFloat(-60.0f) * FMath.Deg2Rad), -0.86603f);

            //Test cos
            AssertAlmostEqualsTrig(FMath.Cos(fint.CreateFromFloat(0) * FMath.Deg2Rad), 1.0f);
            AssertAlmostEqualsTrig(FMath.Cos(fint.CreateFromFloat(90) * FMath.Deg2Rad), 0.0f);
            AssertAlmostEqualsTrig(FMath.Cos(fint.CreateFromFloat(180) * FMath.Deg2Rad), -1.0f);
            AssertAlmostEqualsTrig(FMath.Cos(fint.CreateFromFloat(270) * FMath.Deg2Rad), 0.0f);

            AssertAlmostEqualsTrig(FMath.Cos(fint.CreateFromFloat(60.0f) * FMath.Deg2Rad), 0.5f);
            AssertAlmostEqualsTrig(FMath.Cos(fint.CreateFromFloat(-60.0f) * FMath.Deg2Rad), 0.5f);
            AssertAlmostEqualsTrig(FMath.Cos(fint.CreateFromFloat(30.0f) * FMath.Deg2Rad), 0.86603f);
            AssertAlmostEqualsTrig(FMath.Cos(fint.CreateFromFloat(-30.0f) * FMath.Deg2Rad), 0.86603f);

            //Test asin
            AssertAlmostEqualsAngleRadians(FMath.Asin(fint.CreateFromFloat(0.0f)), 0.0f);
            AssertAlmostEqualsAngleRadians(FMath.Asin(fint.CreateFromFloat(-1.0f)), (float)-Math.PI / 2.0f);
            AssertAlmostEqualsAngleRadians(FMath.Asin(fint.CreateFromFloat(1.0f)), (float)Math.PI / 2.0f);
            AssertAlmostEqualsAngleRadians(FMath.Asin(fint.CreateFromFloat(-0.8660254f)), (float)-Math.PI / 3.0f);
            AssertAlmostEqualsAngleRadians(FMath.Asin(fint.CreateFromFloat(0.8660254f)), (float)Math.PI / 3.0f);
            AssertAlmostEqualsAngleRadians(FMath.Asin(fint.CreateFromFloat(-0.7071068f)), (float)-Math.PI / 4.0f);
            AssertAlmostEqualsAngleRadians(FMath.Asin(fint.CreateFromFloat(0.7071068f)), (float)Math.PI / 4.0f);
            AssertAlmostEqualsAngleRadians(FMath.Asin(fint.CreateFromFloat(-0.5f)), (float)-Math.PI / 6.0f);
            AssertAlmostEqualsAngleRadians(FMath.Asin(fint.CreateFromFloat(0.5f)), (float)Math.PI / 6.0f);

            //Test acos
            AssertAlmostEqualsAngleRadians(FMath.Acos(fint.CreateFromFloat(0)), (float)Math.PI / 2.0f);
            AssertAlmostEqualsAngleRadians(FMath.Acos(fint.CreateFromFloat(-1.0f)), (float)Math.PI);
            AssertAlmostEqualsAngleRadians(FMath.Acos(fint.CreateFromFloat(1.0f)), (float)0);
            AssertAlmostEqualsAngleRadians(FMath.Acos(fint.CreateFromFloat(-0.8660254f)), 5.0f * (float)Math.PI / 6.0f);
            AssertAlmostEqualsAngleRadians(FMath.Acos(fint.CreateFromFloat(0.8660254f)), (float)Math.PI / 6.0f);
            AssertAlmostEqualsAngleRadians(FMath.Acos(fint.CreateFromFloat(-0.7071068f)), 3.0f * (float)Math.PI / 4.0f);
            AssertAlmostEqualsAngleRadians(FMath.Acos(fint.CreateFromFloat(0.7071068f)), (float)Math.PI / 4.0f);
            AssertAlmostEqualsAngleRadians(FMath.Acos(fint.CreateFromFloat(-0.5f)), 2.0f * (float)Math.PI / 3.0f);
            AssertAlmostEqualsAngleRadians(FMath.Acos(fint.CreateFromFloat(0.5f)), (float)Math.PI / 3.0f);
        }
Beispiel #2
0
 //
 // Static Methods
 //
 public static fint Angle(FVector2 from, FVector2 to)
 {
     return(FMath.Acos(FMath.Clamp(FVector2.Dot(from.normalized, to.normalized), -fint.one, fint.one)) * FMath.Rad2Deg);
 }