static Line LineFromCenterAndBearing(PointD centerPoint, Double bearing, Double distance) { PointD p1 = FlatGeo.GetPoint(centerPoint, Angle.Reverse(bearing), distance / 2); PointD p2 = FlatGeo.GetPoint(centerPoint, bearing, distance / 2); return(new Line(p1, p2)); }
public void Move(Double bearing, Double distance) { PointD np = FlatGeo.GetPoint(this, bearing, distance); _X = np.X; _Y = np.Y; }
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 Double DistanceTo(PointD to) { Double ret = Double.PositiveInfinity; /** make a single leg of a triangle between the remote point and one point on this line */ Line leg = new Line(P1, to); /** get the interior angle */ Double angle = FlatGeo.Angle(to, leg.P1, leg.P2).Degrees; if (angle >= 180) { angle -= 180; } if (angle != 0) { /** find the distance to the closest point on the line */ ret = Math.Abs(Math.Sin(angle) * leg.Length); } else { /** the point is on the line */ ret = 0; } return(ret); }
/** * get a point on the arc defined by 'circle' that is 'degrees' deg, * from 'from', in the direction of the point 'direction' */ public static PointD GetPointOnArc(Circle circle, PointD from, Angle degrees, Relationship relationship, PointD referencePoint) { Line start = new Line(circle.Center, from); Line refLine = new Line(circle.Center, referencePoint); Angle newAngle = FlatGeo.ChangeAngle(start, refLine, new Angle(degrees.Degrees * -1)); return(GetPoint(circle.Center, newAngle.Degrees, circle.Radius)); }
public double GetPixelBearing(PointD pt1, PointD pt2) { double retVal = FlatGeo.Degrees(Math.Atan2(pt2.Y - pt1.Y, pt2.X - pt1.X)) + 90; if (retVal < 0) { retVal = 360 + retVal; } return(retVal); }
public Angle InteriorAngle(PointD point) { LineList lines = GetLinesAdjacentTo(point); Angle ret = FlatGeo.Angle(lines[0], lines[1]); if (ret.Degrees > 180) { ret.Degrees = 360 - ret.Degrees; } return(ret); }
void RecalculateAxes() { MajorAxis = new Line( FlatGeo.GetPoint(_center, Angle.Reverse(_majorAxisBearing), _majorAxisLength / 2), FlatGeo.GetPoint(_center, _majorAxisBearing, _majorAxisLength / 2)); Double minorAxisBearing = Angle.Add(_majorAxisBearing, 90); MinorAxis = new Line( FlatGeo.GetPoint(_center, Angle.Reverse(minorAxisBearing), _minorAxisLength / 2), FlatGeo.GetPoint(_center, minorAxisBearing, _minorAxisLength / 2)); }
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); }
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 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); }
void RecalculateFociAndArea() { // __________ // \/ r1² * r2² Double fociDistance = Math.Sqrt(MajorRadius * MajorRadius - MinorRadius * MinorRadius); Foci = new PointD[] { FlatGeo.GetPoint(Center, Angle.Reverse(MajorAxis.Bearing), fociDistance), FlatGeo.GetPoint(Center, MajorAxis.Bearing, fociDistance) }; Eccentricity = new Line(Foci[0], Center).Length / new Line(Foci[0], MinorAxis.P1).Length; Area = Math.PI * MajorRadius * MinorRadius; }
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))); }
public static bool GetIntersection(GeoLine l1, GeoLine l2, int precision, out GeoPoint intersection) { intersection = new GeoPoint(); bool result = false; double A1, B1, C1; FlatGeo.GetLineABC(l1.ToLine(), out A1, out B1, out C1); double A2, B2, C2; FlatGeo.GetLineABC(l2.ToLine(), out A2, out B2, out C2); double det = A1 * B2 - A2 * B1; if (det != 0) { intersection = new GeoPoint((A1 * C2 - A2 * C1) / det, (B2 * C1 - B1 * C2) / det); bool result1 = intersection.IsWestOfOrEqualTo(EastMost(l1.P1 as GeoPoint, l1.P2 as GeoPoint), precision); bool result2 = intersection.IsEastOfOrEqualTo(WestMost(l1.P1 as GeoPoint, l1.P2 as GeoPoint), precision); bool result3 = intersection.IsWestOfOrEqualTo(EastMost(l2.P1 as GeoPoint, l2.P2 as GeoPoint), precision); bool result4 = intersection.IsEastOfOrEqualTo(WestMost(l2.P1 as GeoPoint, l2.P2 as GeoPoint), precision); bool result5 = intersection.IsSouthOfOrEqualTo(NorthMost(l1.P1 as GeoPoint, l1.P2 as GeoPoint), precision); bool result6 = intersection.IsNorthOfOrEqualTo(SouthMost(l1.P1 as GeoPoint, l1.P2 as GeoPoint), precision); bool result7 = intersection.IsSouthOfOrEqualTo(NorthMost(l2.P1 as GeoPoint, l2.P2 as GeoPoint), precision); bool result8 = intersection.IsNorthOfOrEqualTo(SouthMost(l2.P1 as GeoPoint, l2.P2 as GeoPoint), precision); if (intersection.IsWestOfOrEqualTo(EastMost(l1.P1 as GeoPoint, l1.P2 as GeoPoint), precision) && intersection.IsEastOfOrEqualTo(WestMost(l1.P1 as GeoPoint, l1.P2 as GeoPoint), precision) && intersection.IsWestOfOrEqualTo(EastMost(l2.P1 as GeoPoint, l2.P2 as GeoPoint), precision) && intersection.IsEastOfOrEqualTo(WestMost(l2.P1 as GeoPoint, l2.P2 as GeoPoint), precision) && intersection.IsSouthOfOrEqualTo(NorthMost(l1.P1 as GeoPoint, l1.P2 as GeoPoint), precision) && intersection.IsNorthOfOrEqualTo(SouthMost(l1.P1 as GeoPoint, l1.P2 as GeoPoint), precision) && intersection.IsSouthOfOrEqualTo(NorthMost(l2.P1 as GeoPoint, l2.P2 as GeoPoint), precision) && intersection.IsNorthOfOrEqualTo(SouthMost(l2.P1 as GeoPoint, l2.P2 as GeoPoint), precision)) { result = true; } } // else, its parallel return(result); }
public PointD GetPointAt(Double bearing, Double distance) { return(FlatGeo.GetPoint(this, bearing, distance)); }
public PointD GetPointAt(BearingAndRange vector) { return(FlatGeo.GetPoint(this, vector.Bearing, vector.Range)); }
public bool Intersects(Line other, out PointD intersection) { intersection = null; return(FlatGeo.GetIntersection(this, other, out intersection)); }
public Line(PointD origin, Double bearing, Double distance) : this(origin, FlatGeo.GetPoint(origin, bearing, distance)) { }