Ejemplo n.º 1
0
 private void TestCoords(Action <int, Geodetic.Coordinates, Geodetic.Coordinates> action)
 {
     for (var i = 0; i < coords.GetLength(0); i += 2)
     {
         var from = Geodetic.Coords(latitude: coords[i, 0], longitude: coords[i, 1]);
         var to   = Geodetic.Coords(latitude: coords[i + 1, 0], longitude: coords[i + 1, 1]);
         action(i, from, to);
     }
 }
Ejemplo n.º 2
0
 [Test] public void GeodeticBearings()
 {
     TestCoords(
         (idx, from, to) => {
         double bearing = Geodetic.BearingDegrees(from, to);
         Assert.AreEqual(coords[idx, 3], bearing, 0.01, $"degrees for index {idx}");
         double radians = Geodetic.BearingRadians(from, to);
         Assert.AreEqual(coords[idx, 3], Trig.ToDegrees(radians), 0.01, $"radians for index {idx}");
     });
 }
Ejemplo n.º 3
0
        [Test] public void GeodeticDestination()
        {
            TestCoords(
                (idx, from, to) => {
                double kmApart = Geodetic.Kilometres(from, to);
                double bearing = Geodetic.BearingDegrees(from, to);

                var destination = Geodetic.Destination(start: from, distanceKm: kmApart, bearingDegrees: bearing);

                Assert.IsTrue(to.Equals(destination));
            });
        }
Ejemplo n.º 4
0
        [Test] public void GeodeticDistances()
        {
            TestCoords(
                (idx, from, to) => {
                double metresApart   = Geodetic.Kilometres(from, to) * 1000;
                string distanceApart = Geodetic.DistanceBetween(from, to);

                Assert.AreEqual(expected: coords[idx, 2], actual: metresApart, delta: 5);

                Assert.AreEqual(expected: distances[idx / 2], actual: distanceApart);

                Assert.AreEqual(metresApart, Geodetic.Haversine(from, to) * 1000);
            });
        }
Ejemplo n.º 5
0
        [Test] public void Example()
        {
            //- Generate coordinate structs in decimal degrees
            var from = Geodetic.Coords(latitude: -27.46850, longitude: 151.94379);
            //- or radians
            var to = Geodetic.Coords(latitude: -0.47941664, longitude: 2.65191906, radians: true);

            //- The calculations below don't need to know which form is used. We can always convert it ourselves
            from = from.ToRadians();
            to   = to.ToDegrees();
            //- Now we have two coordinates we can calculate how far apart they are
            double metresApart = Geodetic.Kilometres(from, to) * 1000;
            //- or use the human readable form which will use meters or km as needed
            string distanceApart = Geodetic.DistanceBetween(from, to);
            //- Now we have distance, what direction do we need to travel
            double bearing = Geodetic.BearingDegrees(from, to);
            //- and in radians
            double radians = Geodetic.BearingRadians(from, to);
            //- But what if we know the direction and distance to an object
            var destination = Geodetic.Destination(start: from, distanceKm: metresApart * 1000, bearingDegrees: bearing);
        }