public static void SetDistanceAndAngleGeocacheFromLocation(GAPPSF.Core.Data.Geocache gc, GAPPSF.Core.Data.Location loc) { GeodeticMeasurement gm = CalculateDistance(loc.Lat, loc.Lon, gc.Lat, gc.Lon); gc.DistanceToCenter = (long)gm.EllipsoidalDistance; gc.AngleToCenter = (int)gm.Azimuth.Degrees; }
public static GeodeticMeasurement CalculateDistance(double lat1, double lon1, double lat2, double lon2) { GlobalCoordinates p1 = new GlobalCoordinates(new Angle(lat1), new Angle(lon1)); GlobalCoordinates p2 = new GlobalCoordinates(new Angle(lat2), new Angle(lon2)); GeodeticCalculator gc = new GeodeticCalculator(); GlobalPosition gp1 = new GlobalPosition(p1); GlobalPosition gp2 = new GlobalPosition(p2); GeodeticMeasurement gm = gc.CalculateGeodeticMeasurement(Ellipsoid.WGS84, gp1, gp2); return(gm); }
public override object Execute(object[] args, ExecutionContext ctx) { string res = ""; ArgumentChecker checker = new ArgumentChecker(this.GetType().Name); checker.CheckForNumberOfArguments(ref args, 2, null); Utils.Location ll1 = Utils.Conversion.StringToLocation(args[0].ToString()); Utils.Location ll2 = Utils.Conversion.StringToLocation(args[1].ToString()); if ((ll1 != null) && (ll2 != null)) { GeodeticMeasurement gm = Utils.Calculus.CalculateDistance(ll1.Lat, ll1.Lon, ll2.Lat, ll2.Lon); res = gm.Azimuth.Degrees.ToString("0"); } return(res); }
public static double ComputeDistance(Waypoint w1, Waypoint w2, out double elevationChange) { GlobalCoordinates startCoords = new GlobalCoordinates(w1.Latitude, w1.Longitude); GlobalCoordinates endCoords = new GlobalCoordinates(w2.Latitude, w2.Longitude); GeodeticCurve curve = geoCal.CalculateGeodeticCurve(Ellipsoid.WGS84, startCoords, endCoords); elevationChange = 0; if (!double.IsNaN(w1.Elevation) && !double.IsNaN(w2.Elevation)) { elevationChange = w2.Elevation - w1.Elevation; } GeodeticMeasurement measurement = new GeodeticMeasurement(curve, elevationChange); return(measurement.PointToPointDistance); }
public IList <DerivedPointDto> CreateArc(double radius, SuppliedPointDto centerPoint, SuppliedPointDto startPoint, SuppliedPointDto endPoint) { Angle centerLatitude = new Angle(centerPoint.Latitude); Angle centerLongitude = new Angle(centerPoint.Longitude); Angle startLatitude = new Angle(startPoint.Latitude); Angle startLongitude = new Angle(startPoint.Longitude); Angle endLatitude = new Angle(endPoint.Latitude); Angle endLongitude = new Angle(endPoint.Longitude); GlobalCoordinates centerCoordinate = new GlobalCoordinates(centerLatitude, centerLongitude); GlobalCoordinates startCoordinate = new GlobalCoordinates(startLatitude, startLongitude); GlobalCoordinates endCoordinate = new GlobalCoordinates(endLatitude, endLongitude); GlobalPosition centerPosition = new GlobalPosition(centerCoordinate); GlobalPosition startPosition = new GlobalPosition(startCoordinate); GlobalPosition endPosition = new GlobalPosition(endCoordinate); GeodeticMeasurement centerToStartMeasurement = calculator.CalculateGeodeticMeasurement(centerPosition, startPosition); GeodeticMeasurement centerToEndMeasurement = calculator.CalculateGeodeticMeasurement(centerPosition, endPosition); // Radius should ensure that it is tolerable (we are going to ingore it in this implementation) double startDistance = centerToStartMeasurement.PointToPointDistance; double endDistance = centerToEndMeasurement.PointToPointDistance; double distanceDelta = Math.Abs(startDistance - endDistance); double distanceEpsilon = distanceDelta / 10; Angle startBearing = centerToStartMeasurement.Azimuth; Angle endBearing = centerToEndMeasurement.Azimuth; double degreesDelta = Math.Abs(startBearing.Degrees - endBearing.Degrees); double degreesEpsilon = degreesDelta / 10; // Our angular distribution IList <DerivedPointDto> arcPoints = new List <DerivedPointDto>(); // We are going to assume that arc derivation is done in a clockwise position. for (int i = 0; i < 10; i++) // Such that the 10th increment should equate to the end point and the initial the start { Angle nextBearing = new Angle(startBearing.Degrees + (degreesEpsilon * (i + 1))); GlobalCoordinates thetaLocation = calculator.CalculateEndingGlobalCoordinates(centerCoordinate, nextBearing, startDistance + (distanceEpsilon * (i + 1))); DerivedPointDto thetaPoint = new DerivedPointDto(thetaLocation.Latitude.Degrees, thetaLocation.Longitude.Degrees); arcPoints.Add(thetaPoint); } return(arcPoints); }
private void calculateAngleAndDegrees() { Framework.Data.Location ll1 = Utils.Conversion.StringToLocation(textBox5.Text); Framework.Data.Location ll2 = Utils.Conversion.StringToLocation(textBox6.Text); if (ll1 != null && ll2 != null) { GeodeticMeasurement gm = Utils.Calculus.CalculateDistance(ll1.Lat, ll1.Lon, ll2.Lat, ll2.Lon); textBox7.Text = gm.EllipsoidalDistance.ToString("0"); textBox8.Text = (0.0006214 * gm.EllipsoidalDistance).ToString("0.000"); textBox9.Text = gm.Azimuth.Degrees.ToString("0"); } else { textBox7.Text = ""; textBox8.Text = ""; textBox9.Text = ""; } }
public void TestCalculateGeodeticMeasurement() { // instantiate the calculator GeodeticCalculator geoCalc = new GeodeticCalculator(); // select a reference elllipsoid Ellipsoid reference = Ellipsoid.WGS84; // set Pike's Peak position GlobalPosition pikesPeak = new GlobalPosition(new GlobalCoordinates(Angle.FromDegrees(38.840511), Angle.FromDegrees(-105.0445896)), 4301); // set Alcatraz Island coordinates GlobalPosition alcatrazIsland = new GlobalPosition(new GlobalCoordinates(Angle.FromDegrees(37.826389), Angle.FromDegrees(-122.4225)), 0); // calculate the geodetic measurement GeodeticMeasurement geoMeasurement = geoCalc.CalculateGeodeticMeasurement(reference, pikesPeak, alcatrazIsland); Assert.AreEqual(-4301, geoMeasurement.ElevationChangeMeters, 0.001); Assert.AreEqual(1521788.826, geoMeasurement.PointToPointDistanceMeters, 0.001); Assert.AreEqual(1521782.748, geoMeasurement.EllipsoidalDistanceMeters, 0.001); Assert.AreEqual(271.21039153, geoMeasurement.Azimuth.Degrees, StandardTolerance); Assert.AreEqual(80.38029386, geoMeasurement.ReverseAzimuth.Degrees, StandardTolerance); }