public GeoPoint GetGeoPoint(PointD pixPoint) { // get a bearing to the point from our known point if ((pixPoint.X == this.PixPoint.X) && (pixPoint.Y == this.PixPoint.Y)) { return(this.GeoPoint); } /** draw a line to get our pixel length */ Line l1 = new Line(pixPoint, this.PixPoint); PointD vectorPoint = new PointD(_pixelReferencePoint.X + 100, _pixelReferencePoint.Y); double pixBearing = FlatGeo.Angle(pixPoint, _pixelReferencePoint, vectorPoint).Degrees + 90; double pixDistance = l1.Length; double geoBearing = FlatGeo.Radians((pixBearing + this.BearingDelta) % 360); double geoDistance = pixDistance / this.PixelsPerMeter; double lat = FlatGeo.Radians(this.GeoPoint.Y); double lon = FlatGeo.Radians(this.GeoPoint.X); double ddr = geoDistance / EarthGeo.EarthRadius; double lat2 = Math.Asin(Math.Sin(lat) * Math.Cos(ddr) + Math.Cos(lat) * Math.Sin(ddr) * Math.Cos(geoBearing)); double lon2 = lon + Math.Atan2(Math.Sin(geoBearing) * Math.Sin(ddr) * Math.Cos(lat), Math.Cos(ddr) - Math.Sin(lat) * Math.Sin(lat2)); lon2 = ((lon2 + Math.PI) % (2 * Math.PI)) - Math.PI; lat2 = FlatGeo.Degrees(lat2); lon2 = FlatGeo.Degrees(lon2); return(new GeoPoint(lat2, lon2)); }
public PointD GetPixelPoint(GeoPoint geoPoint) { // get a bearing to the point from our known point double geoBearing = EarthGeo.GetBearing(this.GeoPoint, geoPoint); double geoDistance = EarthGeo.GetDistance(this.GeoPoint, geoPoint); double pixBearing = FlatGeo.Radians(((geoBearing + 360) - this.BearingDelta) % 360); double pixDistance = geoDistance * this.PixelsPerMeter; PointD ret = new PointD(this.PixPoint.X + (Math.Sin(pixBearing) * pixDistance), this.PixPoint.Y - (Math.Cos(pixBearing) * pixDistance)); return(ret); }
public static double GetBearing(GeoPoint pt1, GeoPoint pt2) { double lat1 = FlatGeo.Radians(pt1.Y); double lon1 = FlatGeo.Radians(pt1.X); double lat2 = FlatGeo.Radians(pt2.Y); double lon2 = FlatGeo.Radians(pt2.X); double y = Math.Sin(lon2 - lon1) * Math.Cos(lat2); double x = Math.Cos(lat1) * Math.Sin(lat2) - Math.Sin(lat1) * Math.Cos(lat2) * Math.Cos(lon2 - lon1); double bearing = Math.Atan2(y, x); // bearing in radians double ret = (FlatGeo.Degrees(bearing) + 360) % 360; return(ret); }
static public double GetDistance(GeoPoint pt1, GeoPoint pt2) { // get the arc between the two earth points in radians double deltaLat = FlatGeo.Radians(pt2.Y - pt1.Y); double deltaLong = FlatGeo.Radians(pt2.X - pt1.X); double latitudeHelix = Math.Pow(Math.Sin(deltaLat * 0.5), 2); double longitudeHelix = Math.Pow(Math.Sin(deltaLong * 0.5), 2); double tmp = Math.Cos(FlatGeo.Radians(pt1.Y)) * Math.Cos(FlatGeo.Radians(pt2.Y)); double rad = 2.0 * Math.Asin(Math.Sqrt(latitudeHelix + tmp * longitudeHelix)); // Multiply the radians by the earth radius in meters for a distance measurement in meters return(EarthRadius * rad); }
public static GeoPoint GetPoint(GeoPoint origin, Double bearing, Double distanceInMeters) { bearing = FlatGeo.Radians(bearing % 360); double ddr = distanceInMeters / EarthGeo.EarthRadius; double lat = FlatGeo.Radians(origin.Y); double lon = FlatGeo.Radians(origin.X); double lat2 = Math.Asin(Math.Sin(lat) * Math.Cos(ddr) + Math.Cos(lat) * Math.Sin(ddr) * Math.Cos(bearing)); double lon2 = lon + Math.Atan2(Math.Sin(bearing) * Math.Sin(ddr) * Math.Cos(lat), Math.Cos(ddr) - Math.Sin(lat) * Math.Sin(lat2)); lon2 = ((lon2 + Math.PI) % (2 * Math.PI)) - Math.PI; return(new GeoPoint(FlatGeo.Degrees(lat2), FlatGeo.Degrees(lon2))); }