Esempio n. 1
0
        public void ACosTest()
        {
            float actual   = MathHelper.Round(MathHelper.Acos(0f), 6);
            float expected = 1.570796f;

            Assert.AreEqual(expected, actual);
        }
Esempio n. 2
0
        public void Acos(double expected, double input)
        {
            // Act
            var actual = MathHelper.Acos(input);

            // Assert
            Assert.Equal(expected, actual);
        }
Esempio n. 3
0
            public static Props FromCommonProps(CameraFrame frame)
            {
                var forward = frame.Forward;
                var yaw     = MathHelper.Atan2(forward.Xz.X, -forward.Xz.Y);
                var pitch   = MathHelper.Acos(Vector3.Dot(new Vector3(forward.X, 0, forward.Z).Normalize(), forward));

                return(new Props
                {
                    Eye = frame.Eye,
                    Yaw = yaw,
                    Pitch = pitch
                });
            }
Esempio n. 4
0
        public static Quaternion Slerp(float t, Quaternion q1, Quaternion q2)
        {
            float cosTheta = Dot(q1, q2);

            if (cosTheta > 0.9995f)
            {
                return(Normalize((1.0f - t) * q1 + t * q2));
            }
            else
            {
                float      theta  = MathHelper.Acos(MathHelper.Clamp(cosTheta, -1.0f, 1.0f));
                float      thetap = theta * t;
                Quaternion qperp  = Normalize(q2 - q1 * cosTheta);
                return(q1 * MathHelper.Cos(thetap) + qperp * MathHelper.Sin(thetap));
            }
        }
Esempio n. 5
0
        public static Quaternion Slerp(Quaternion left, Quaternion right, float amount)
        {
            var cosTheta    = MathHelper.Clamp(Dot(left, right), -1f, 1f);
            var theta       = MathHelper.Acos(cosTheta);
            var sinTheta    = MathHelper.Sin(theta);
            var invSinTheta = 1.0f / sinTheta;
            var wLeft       = MathHelper.Sin((1.0f - amount) * theta) * invSinTheta;
            var wRight      = MathHelper.Sin(amount * theta) * invSinTheta;

            if (cosTheta < 0f)
            {
                wRight = -wRight;
            }

            return(new Quaternion(
                       wLeft * left.X + wRight * right.X,
                       wLeft * left.Y + wRight * right.Y,
                       wLeft * left.Z + wRight * right.Z,
                       wLeft * left.W + wRight * right.W));
        }
 public static bool FrustumCheckChunk(Vector3i pos_to_check)
 {
     return(MathHelper.RadiansToDegrees(MathHelper.Acos(Vector3.Dot(Camera.Front.Normalized(),
                                                                    (Camera.Position - ConvertChunkToWorldCoordinates(pos_to_check)).Normalized()))) >
            Camera.Frustrum / 2f);
 }
Esempio n. 7
0
        /// <summary>
        /// Calculates the angles and sides.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <remarks>
        /// http://cossincalc.com/
        /// </remarks>
        private static TriangleData CalculateAnglesAndSides(TriangleData data)
        {
            // A
            if (MathHelper.IsEqualToZero(data.A))
            {
                if (!MathHelper.IsEqualToZero(data.B) && !MathHelper.IsEqualToZero(data.C))
                {
                    data.A = 180 - data.B - data.C;
                }
                else if (!MathHelper.IsEqualToZero(data.B) && !MathHelper.IsEqualToZero(data.a) && !MathHelper.IsEqualToZero(data.b))
                {
                    data.A = MathHelper.Asin(MathHelper.Sin(data.B) * data.a / data.b);
                }
                else if (!MathHelper.IsEqualToZero(data.B) && !MathHelper.IsEqualToZero(data.b) && !MathHelper.IsEqualToZero(data.c))
                {
                    if (MathHelper.IsEqualToZero(data.C))
                    {
                        data.C = MathHelper.Asin(MathHelper.Sin(data.B) * data.c / data.b);
                    }

                    data.A = 180 - data.B - data.C;
                }
                else if (!MathHelper.IsEqualToZero(data.B) && !MathHelper.IsEqualToZero(data.a) && !MathHelper.IsEqualToZero(data.c))
                {
                    double a2 = data.a * data.a;
                    double c2 = data.c * data.c;
                    if (MathHelper.IsEqualToZero(data.b))
                    {
                        data.b = System.Math.Sqrt(a2 + c2 - (2 * data.a * data.c * MathHelper.Cos(data.B)));
                    }

                    double b2 = data.b * data.b;
                    data.A = MathHelper.Acos((b2 + c2 - a2) / (2 * data.b * data.c));
                }
                else if (!MathHelper.IsEqualToZero(data.C) && !MathHelper.IsEqualToZero(data.a) && !MathHelper.IsEqualToZero(data.b))
                {
                    double a2 = data.a * data.a;
                    double b2 = data.b * data.b;
                    if (MathHelper.IsEqualToZero(data.c))
                    {
                        data.c = System.Math.Sqrt(a2 + b2 - (2 * data.a * data.b * MathHelper.Cos(data.C)));
                    }

                    double c2 = data.c * data.c;
                    data.A = MathHelper.Acos((b2 + c2 - a2) / (2 * data.b * data.c));
                }
                else if (!MathHelper.IsEqualToZero(data.C) && !MathHelper.IsEqualToZero(data.a) && !MathHelper.IsEqualToZero(data.c))
                {
                    if (MathHelper.IsEqualToZero(data.A))
                    {
                        data.A = MathHelper.Asin(MathHelper.Sin(data.C) * data.a / data.c);
                    }

                    data.B = 180 - data.A - data.C;
                }
                else if (!MathHelper.IsEqualToZero(data.C) && !MathHelper.IsEqualToZero(data.b) && !MathHelper.IsEqualToZero(data.c))
                {
                    if (MathHelper.IsEqualToZero(data.B))
                    {
                        data.B = MathHelper.Asin(MathHelper.Sin(data.C) * data.b / data.c);
                    }

                    data.A = 180 - data.B - data.C;
                }
                else
                {
                    throw new ArithmeticException("This scenario is not implemented yet.");
                }
            }

            // B
            if (MathHelper.IsEqualToZero(data.B))
            {
                if (!MathHelper.IsEqualToZero(data.A) && !MathHelper.IsEqualToZero(data.C))
                {
                    data.B = 180 - data.A - data.C;
                }
                else if (!MathHelper.IsEqualToZero(data.A) && !MathHelper.IsEqualToZero(data.a) && !MathHelper.IsEqualToZero(data.b))
                {
                    data.B = MathHelper.Asin(MathHelper.Sin(data.A) * data.b / data.a);
                }
                else if (!MathHelper.IsEqualToZero(data.A) && !MathHelper.IsEqualToZero(data.b) && !MathHelper.IsEqualToZero(data.c))
                {
                    double b2 = data.b * data.b;
                    double c2 = data.c * data.c;
                    if (MathHelper.IsEqualToZero(data.a))
                    {
                        data.a = System.Math.Sqrt(b2 + c2 - (2 * data.b * data.c * MathHelper.Cos(data.A)));
                    }

                    double a2 = data.a * data.a;
                    data.B = MathHelper.Acos((a2 + c2 - b2) / (2 * data.a * data.c));
                }
                else if (!MathHelper.IsEqualToZero(data.A) && !MathHelper.IsEqualToZero(data.a) && !MathHelper.IsEqualToZero(data.c))
                {
                    if (MathHelper.IsEqualToZero(data.C))
                    {
                        data.C = MathHelper.Asin(MathHelper.Sin(data.A) * data.c / data.a);
                    }

                    data.B = 180 - data.A - data.C;
                }
                else
                {
                    throw new ArithmeticException("This scenario is not implemented yet.");
                }
            }

            // C
            if (MathHelper.IsEqualToZero(data.C))
            {
                if (!MathHelper.IsEqualToZero(data.A) && !MathHelper.IsEqualToZero(data.B))
                {
                    data.C = 180 - data.A - data.B;
                }
                else
                {
                    throw new ArithmeticException("This scenario is not implemented yet.");
                }
            }

            // a
            if (MathHelper.IsEqualToZero(data.a))
            {
                if (!MathHelper.IsEqualToZero(data.A) && !MathHelper.IsEqualToZero(data.B) && !MathHelper.IsEqualToZero(data.b))
                {
                    data.a = MathHelper.Sin(data.A) * data.b / MathHelper.Sin(data.B);
                }
                else if (!MathHelper.IsEqualToZero(data.A) && !MathHelper.IsEqualToZero(data.C) && !MathHelper.IsEqualToZero(data.c))
                {
                    data.a = MathHelper.Sin(data.A) * data.c / MathHelper.Sin(data.C);
                }
                else
                {
                    throw new ArithmeticException("This scenario is not implemented yet.");
                }
            }

            // b
            if (MathHelper.IsEqualToZero(data.b))
            {
                if (!MathHelper.IsEqualToZero(data.A) && !MathHelper.IsEqualToZero(data.B) && !MathHelper.IsEqualToZero(data.a))
                {
                    data.b = MathHelper.Sin(data.B) * data.a / MathHelper.Sin(data.A);
                }
                else
                {
                    throw new ArithmeticException("This scenario is not implemented yet.");
                }
            }

            // c
            if (MathHelper.IsEqualToZero(data.c))
            {
                if (!MathHelper.IsEqualToZero(data.A) && !MathHelper.IsEqualToZero(data.C) && !MathHelper.IsEqualToZero(data.a))
                {
                    data.c = MathHelper.Sin(data.C) * data.a / MathHelper.Sin(data.A);
                }
                else
                {
                    throw new ArithmeticException("This scenario is not implemented yet.");
                }
            }

            return(IsAngleAndSidesCalculated(data)
                ? data
                : CalculateAnglesAndSides(data));
        }
Esempio n. 8
0
 public static float Acos(float radians) => (float)MathHelper.Acos(radians);