/// <summary> /// Move a coordinate a specified distance towards a target coordinate. /// </summary> /// <param name="target">Target coordinate</param> /// <param name="distance">Distance toward target</param> /// <param name="shape">Shape of earth</param> /// <example> /// The following example moves a coordinate 10km towards a target coordinate using /// ellipsoidal earth calculations. /// <code> /// //N 25º 0' 0" E 25º 0' 0" /// Coordinate coord = Coordinate(25,25); /// /// //Target Coordinate /// Coordinate target = new Coordinate(26.5, 23.2); /// /// Distance distance = new Distance(10, DistanceType.Kilometers); /// /// //Move coordinate the specified distance /// //towards target using ellipsoidal calculations /// coord.Move(target, distance, Shape.Ellipsoid); /// /// //New Coordinate - N 24º 56' 21.526" E 25º 4' 23.944" /// </code> /// </example> public void Move(Coordinate target, Distance distance, Shape shape) { Distance d = new Distance(this, target, shape); //Convert to Radians for formula double lat1 = latitude.ToRadians(); double lon1 = longitude.ToRadians(); double crs12 = d.Bearing * Math.PI / 180; //Convert bearing to radians double[] ellipse = new double[] { equatorial_radius, inverse_flattening }; if (shape == Shape.Sphere) { double[] cd = Distance_Assistant.Direct(lat1, lon1, crs12, distance.Meters); double lat2 = cd[0] * (180 / Math.PI); double lon2 = cd[1] * (180 / Math.PI); //ADJUST CORD Latitude.DecimalDegree = lat2; Longitude.DecimalDegree = -lon2; //v2.1.1.1 update } else { double[] cde = Distance_Assistant.Direct_Ell(lat1, -lon1, crs12, distance.Meters, ellipse); //Convert back from radians double lat2 = cde[0] * (180 / Math.PI); double lon2 = cde[1] * (180 / Math.PI); //v2.1.1.1 //ADJUST CORD Latitude.DecimalDegree = lat2; Longitude.DecimalDegree = lon2; } }
private void Vincenty(Coordinate coord1, Coordinate coord2) { double lat1, lat2, lon1, lon2; double d, crs12, crs21; lat1 = coord1.Latitude.ToRadians(); lat2 = coord2.Latitude.ToRadians(); lon1 = coord1.Longitude.ToRadians() * -1; //REVERSE FOR CALC 2.1.1.1 lon2 = coord2.Longitude.ToRadians() * -1; //REVERSE FOR CALC 2.1.1.1 //Ensure datums match between coords if ((coord1.equatorial_radius != coord2.equatorial_radius) || (coord1.inverse_flattening != coord2.inverse_flattening)) { throw new InvalidOperationException("The datum set does not match between Coordinate objects."); } double[] ellipse = new double[] { coord1.equatorial_radius, coord1.inverse_flattening }; // elliptic code double[] cde = Distance_Assistant.Dist_Ell(lat1, -lon1, lat2, -lon2, ellipse); // ellipse uses East negative crs12 = cde[1] * (180 / Math.PI); //Bearing crs21 = cde[2] * (180 / Math.PI); //Reverse Bearing d = cde[0]; //Distance bearing = crs12; //reverseBearing = crs21; meters = d; kilometers = d / 1000; feet = d * 3.28084; miles = d * 0.000621371; nauticalMiles = d * 0.0005399565; }
/// <summary> /// Move coordinate based on provided bearing and distance (in meters). /// </summary> /// <param name="distance">Distance in meters</param> /// <param name="bearing">Bearing</param> /// <param name="shape">Shape of earth</param> /// <example> /// The following example moves a coordinate 10km in the direction of /// the specified bearing using ellipsoidal earth calculations. /// <code> /// //N 25º 0' 0" E 25º 0' 0" /// Coordinate c = Coordinate(25,25); /// /// double meters = 10000; /// double bearing = 25; /// /// //Move coordinate the specified meters /// //and direction using ellipsoidal calculations /// c.Move(meters, bearing, Shape.Ellipsoid); /// /// //New Coordinate - N 25º 4' 54.517" E 24º 57' 29.189" /// </code> /// </example> public void Move(double distance, double bearing, Shape shape) { //Convert to Radians for formula double lat1 = latitude.ToRadians(); double lon1 = longitude.ToRadians(); double crs12 = bearing * Math.PI / 180; //Convert bearing to radians double[] ellipse = new double[] { equatorial_radius, inverse_flattening }; if (shape == Shape.Sphere) { double[] cd = Distance_Assistant.Direct(lat1, lon1, crs12, distance); double lat2 = cd[0] * (180 / Math.PI); double lon2 = cd[1] * (180 / Math.PI); //ADJUST CORD Latitude.DecimalDegree = lat2; Longitude.DecimalDegree = -lon2;//v2.1.1.1 } else { double[] cde = Distance_Assistant.Direct_Ell(lat1, -lon1, crs12, distance, ellipse); // ellipse uses East negative //Convert back from radians double lat2 = cde[0] * (180 / Math.PI); double lon2 = cde[1] * (180 / Math.PI); //v2.1.1.1 //ADJUST CORD Latitude.DecimalDegree = lat2; Longitude.DecimalDegree = lon2; } }