public void Priority_OfACircleEvent_ShouldMatchThePriorityCalculatedByTrigonometry
            (CircleEvent circle)
        {
            // Fixture setup
            var a = circle.LeftArc.Site.Position;
            var b = circle.MiddleArc.Site.Position;
            var c = circle.RightArc.Site.Position;

            var center = (a - b).CrossMultiply(c - b).Normalize();

            var colatitudeOfCenter = Trig.InverseCosine(center[2]);
            var radius             = Trig.InverseCosine(a.ScalarMultiply(center));

            var isOnOutsideOfSphere = colatitudeOfCenter + radius <= Constants.Pi;
            var sign             = isOnOutsideOfSphere ? 1 : -1;
            var expectedPriority = sign * (1 + Trig.Cosine(colatitudeOfCenter + radius));

            // Exercise system
            var priority = circle.Priority;

            // Verify outcome
            var failureString =
                String.Format(
                    "Expected priority was {0}\nActual priority was {1}",
                    expectedPriority,
                    priority);

            Assert.True(Number.AlmostEqual(expectedPriority, priority, Tolerance), failureString);

            // Teardown
        }
        public void Priority_OfACircleThrough0N45EAnd45N0EAnd0N45W_ShouldBeCorrect()
        {
            // Fixture setup
            var arcA = new Arc {
                Site = Utilities.SiteAt(90, 45)
            };
            var arcB = new Arc {
                Site = Utilities.SiteAt(45, 0)
            };
            var arcC = new Arc {
                Site = Utilities.SiteAt(90, -45)
            };

            var circle = new CircleEvent(arcA, arcB, arcC);

            // Exercise system
            var result = circle.Priority;

            // Verify outcome
            var expectedResult = -Trig.Cosine(Trig.DegreeToRadian(135)) - 1;

            Debug.WriteLine(expectedResult);

            var failureString = String.Format("Priority was {0}", result);

            Assert.True(Number.AlmostEqual(result, expectedResult, Tolerance), failureString);

            // Teardown
        }
        public static Vector3 CartesianCoordinates(double colatitude, double azimuth)
        {
            var x = Trig.Sine(colatitude) * Trig.Cosine(azimuth);
            var y = Trig.Sine(colatitude) * Trig.Sine(azimuth);
            var z = Trig.Cosine(colatitude);

            return(new Vector3(x, y, z));
        }
        /// <summary>
        /// Create a vector at the specified colatitude and azimuth at unit distance from the origin.
        /// </summary>
        public static Vector NewVector(double colatitude, double azimuth)
        {
            var x = Trig.Sine(colatitude) * Trig.Cosine(azimuth);
            var y = Trig.Sine(colatitude) * Trig.Sine(azimuth);
            var z = Trig.Cosine(colatitude);

            return(new Vector(new [] { x, y, z }));
        }
예제 #5
0
        public void CanComputeCosine(
            [Values(0.0, 8388608, 1.19209289550780998537e-7, -8388608, -1.19209289550780998537e-7)] double value,
            [Values(1.0, -0.90175467375875928, 0.99999999999999289, -0.90175467375875928, 0.99999999999999289)] double expected)
        {
            var actual = Trig.Cosine(value);

            AssertHelpers.AlmostEqual(expected, actual, 14);
        }
예제 #6
0
    private double[] VectorAt(double colatitude, float azimuth)
    {
        colatitude = Mathf.Deg2Rad * colatitude;
        azimuth    = Mathf.Deg2Rad * azimuth;

        var x = Trig.Sine(colatitude) * Trig.Cosine(azimuth);
        var y = Trig.Sine(colatitude) * Trig.Sine(azimuth);
        var z = Trig.Cosine(colatitude);

        return(new double[] { x, y, z });
    }
        public Vector3 CreateVectorAboveSweepline(IFixture fixture)
        {
            var randomZ       = (-1 + 2 * _random.NextDouble());
            var randomAzimuth = Constants.Pi * _random.NextDouble();

            var x = Math.Sqrt(1.0 - randomZ * randomZ) * Trig.Cosine(randomAzimuth);
            var y = Math.Sqrt(1.0 - randomZ * randomZ) * Trig.Sine(randomAzimuth);
            var z = randomZ;

            return(new Vector3(x, y, z));
        }
예제 #8
0
        BuildCoefficientsForLevels(
            int levels
            )
        {
            if (_realCoefficients[levels, 0] != null)
            {
                return;
            }

            int    M = 1;
            double uRealFw, uImagFw, uRealBw, uImagBw, angle, wRreal, wImag, uwI;

            for (int level = 1; level <= levels; level++, M <<= 1)
            {
                if (_realCoefficients[level, 0] != null)
                {
                    continue;
                }

                uRealFw = uRealBw = 1;
                uImagFw = uImagBw = 0;

                angle  = Constants.Pi / M;
                wRreal = Trig.Cosine(angle);
                wImag  = Trig.Sine(angle);

                double[] realForward  = new double[M];
                double[] imagForward  = new double[M];
                double[] realBackward = new double[M];
                double[] imagBackward = new double[M];

                for (int i = 0; i < M; i++)
                {
                    realForward[i]  = uRealFw;
                    imagForward[i]  = uImagFw;
                    realBackward[i] = uRealBw;
                    imagBackward[i] = uImagBw;

                    uwI     = uImagFw * wRreal - uRealFw * wImag;
                    uRealFw = uRealFw * wRreal + uImagFw * wImag;
                    uImagFw = uwI;

                    uwI     = uImagBw * wRreal + uRealBw * wImag;
                    uRealBw = uRealBw * wRreal - uImagBw * wImag;
                    uImagBw = uwI;
                }

                _realCoefficients[level, 0] = realForward;
                _imagCoefficients[level, 0] = imagForward;
                _realCoefficients[level, 1] = realBackward;
                _imagCoefficients[level, 1] = imagBackward;
            }
        }
예제 #9
0
        BuildCoefficientsForLevels(int levels)
        {
            if (_realCoefficients[levels, 0] != null)
            {
                return;
            }

            int m = 1;

            for (int level = 1; level <= levels; level++, m <<= 1)
            {
                if (_realCoefficients[level, 0] != null)
                {
                    continue;
                }

                double uRealFw = 1;
                double uRealBw = 1;
                double uImagFw = 0;
                double uImagBw = 0;

                double angle  = Constants.Pi / m;
                double wRreal = Trig.Cosine(angle);
                double wImag  = Trig.Sine(angle);

                double[] realForward  = new double[m];
                double[] imagForward  = new double[m];
                double[] realBackward = new double[m];
                double[] imagBackward = new double[m];

                for (int i = 0; i < m; i++)
                {
                    realForward[i]  = uRealFw;
                    imagForward[i]  = uImagFw;
                    realBackward[i] = uRealBw;
                    imagBackward[i] = uImagBw;

                    double uwI = (uImagFw * wRreal) - (uRealFw * wImag);
                    uRealFw = (uRealFw * wRreal) + (uImagFw * wImag);
                    uImagFw = uwI;

                    uwI     = (uImagBw * wRreal) + (uRealBw * wImag);
                    uRealBw = (uRealBw * wRreal) - (uImagBw * wImag);
                    uImagBw = uwI;
                }

                _realCoefficients[level, 0] = realForward;
                _imagCoefficients[level, 0] = imagForward;
                _realCoefficients[level, 1] = realBackward;
                _imagCoefficients[level, 1] = imagBackward;
            }
        }
        private Vector3 CreateVectorBelowLast()
        {
            var z = -1.0 + (1 + _maxZ) * _random.NextDouble();

            _maxZ = z;

            var azimuth = 2 * Constants.Pi * _random.NextDouble();

            var x = Math.Sqrt(1 - z * z) * Trig.Cosine(azimuth);
            var y = Math.Sqrt(1 - z * z) * Trig.Sine(azimuth);

            return(new Vector3(x, y, z));
        }
예제 #11
0
        public Vector3 CreateVectorAboveSweepline(IFixture fixture)
        {
            var sweepline  = fixture.Create <Sweepline>();
            var sweeplineZ = Trig.Cosine(sweepline.Colatitude);

            var randomZ       = (sweeplineZ + (1 - sweeplineZ) * _random.NextDouble());
            var randomAzimuth = Constants.Pi * _random.NextDouble();

            var x = Math.Sqrt(1.0 - randomZ * randomZ) * Trig.Cosine(randomAzimuth);
            var y = Math.Sqrt(1.0 - randomZ * randomZ) * Trig.Sine(randomAzimuth);
            var z = randomZ;

            return(new Vector3(x, y, z));
        }
        public void Test()
        {
            // Fixture setup
            var arcA = new Arc {
                Site = Utilities.SiteAt(45, -45)
            };
            var arcB = new Arc {
                Site = Utilities.SiteAt(0, 0)
            };
            var arcC = new Arc {
                Site = Utilities.SiteAt(45, 45)
            };

            var circle = new CircleEvent(arcA, arcB, arcC);

            var a = arcA.Site.Position;
            var b = arcB.Site.Position;
            var c = arcC.Site.Position;

            var center = (a - b).CrossMultiply(c - b).Normalize();

            var colatitudeOfCenter = Trig.InverseCosine(center[2]);
            var radius             = Trig.InverseCosine(a.ScalarMultiply(center));

            var isOnOutsideOfSphere = colatitudeOfCenter + radius <= Constants.Pi;
            var sign             = isOnOutsideOfSphere ? 1 : -1;
            var expectedPriority = sign * (1 + Trig.Cosine(colatitudeOfCenter + radius));

            // Exercise system
            var priority = circle.Priority;

            Debug.WriteLine(expectedPriority);
            Debug.WriteLine(Trig.RadianToDegree(colatitudeOfCenter));
            Debug.WriteLine(Trig.RadianToDegree(radius));


            // Verify outcome
            var failureString =
                String.Format(
                    "Expected priority was {0}\nActual priority was {1}",
                    expectedPriority,
                    priority);

            Assert.True(Number.AlmostEqual(expectedPriority, priority, Tolerance), failureString);

            // Teardown
        }
        public void Vectors_ShouldAllBeAboveSweepline(List <Vector3> vectors, Sweepline anonymousSweepline)
        {
            // Fixture setup

            // Exercise system

            // Verify outcome
            var expectedResult = Trig.Cosine(anonymousSweepline.Colatitude);

            foreach (var vector in vectors)
            {
                var result = vector[2];

                var failureString = String.Format("Had Z {0}, expected Z was {1}", result, expectedResult);
                Assert.True(result >= expectedResult, failureString);
            }
            // Teardown
        }
예제 #14
0
        public void TestExponential()
        {
            // exp(0) = 1
            Complex zero    = Complex.Zero;
            Complex expZero = zero.Exponential();

            Assert.That(expZero.Real, Is.EqualTo(1d), "Re{exp(0)} = 1");
            Assert.That(expZero.Imag, Is.EqualTo(0d), "Im{exp(0)} = 0");

            // exp(1) = e
            Complex one    = Complex.One;
            Complex expOne = one.Exponential();

            Assert.That(expOne.Real, Is.EqualTo(Constants.E), "Re{exp(1)} = e");
            Assert.That(expOne.Imag, Is.EqualTo(0d), "Im{exp(1)} = 0");

            // exp(i) = cos(1) + sin(1) * i
            Complex I    = Complex.I;
            Complex expI = I.Exponential();

            Assert.That(expI.Real, Is.EqualTo(Trig.Cosine(1d)), "Re{exp(i)} = cos(1)");
            Assert.That(expI.Imag, Is.EqualTo(Trig.Sine(1d)), "Im{exp(i)} = sin(1)");

            // exp(-1) = 1/e
            Complex mOne    = -Complex.One;
            Complex expMOne = mOne.Exponential();

            Assert.That(expMOne.Real, Is.EqualTo(1.0 / Constants.E), "Re{exp(-1)} = 1/e");
            Assert.That(expMOne.Imag, Is.EqualTo(0d), "Im{exp(-1)} = 0");

            // exp(-i) = cos(1) - sin(1) * i
            Complex mI    = -Complex.I;
            Complex expMI = mI.Exponential();

            Assert.That(expMI.Real, Is.EqualTo(Trig.Cosine(1d)), "Re{exp(-i)} = cos(1)");
            Assert.That(expMI.Imag, Is.EqualTo(-Trig.Sine(1d)), "Im{exp(-i)} = -sin(1)");

            // exp(i+1) = e * cos(1) + e * sin(1) * i
            Complex onePlusI    = Complex.One + Complex.I;
            Complex expOnePlusI = onePlusI.Exponential();

            Assert.That(expOnePlusI.Real, Is.EqualTo(Constants.E * Trig.Cosine(1d)), "Re{exp(i+1)} = e * cos(1)");
            Assert.That(expOnePlusI.Imag, Is.EqualTo(Constants.E * Trig.Sine(1d)), "Im{exp(i+1)} = e * sin(1)");
        }
예제 #15
0
 /// <summary>Trigonometric Cosine (Cosinus) of an angle in radians</summary>
 public RealValue Cosine()
 {
     return(new RealValue(Trig.Cosine(_dataValue)));
 }
예제 #16
0
        public static Vector3 PointOnEllipse(IArc arc, float azimuth, Sweepline sweepline)
        {
            var direction = new Generator.Vector3(Trig.Cosine(azimuth), Trig.Sine(azimuth), 0);

            return(arc.PointAt(direction, sweepline).ToUnityVector3());
        }
        public void CanComputeCosine(double value, double expected)
        {
            var actual = Trig.Cosine(value);

            AssertHelpers.AlmostEqual(expected, actual, 14);
        }