bool TryMoveBackwardOnPath(GeoLine originLine, GeoPoint origin, Double distance, out GeoPoint final) { final = null; Double distanceMoved = EarthGeo.GetDistance(origin as GeoPoint, originLine.P1 as GeoPoint); if (distanceMoved <= distance) { for (int index = IndexOf(originLine) - 1; index >= 0; index--) { if (distanceMoved + this[index].Length >= distance) { final = EarthGeo.GetPoint(this[index].P2 as GeoPoint, Angle.Reverse(this[index].Bearing), distance - distanceMoved); break; } else { distanceMoved += this[index].Length; } } } else { /** the destination is on the first segment */ final = EarthGeo.GetPoint(origin, Angle.Reverse(originLine.Bearing), distance); } return(final != null); }
public Double ClosestDistanceFrom(GeoPoint from) { GeoPoint point = new GeoPoint(ClosestPointTo(from)); Double distance = EarthGeo.GetDistance(point, from); return(distance); }
Double GetDistanceForTwoOrderedPoints(GeoLine l1, GeoPoint p1, GeoLine l2, GeoPoint p2) { Double distance = 0; if (l1.Equals(l2)) { distance = EarthGeo.GetDistance(p1, p2); } else { int index; for (index = 0; index < Count && this[index].Equals(l1) == false; index++) { ; } if (index < Count) { distance += EarthGeo.GetDistance(p1 as GeoPoint, l1.P2 as GeoPoint); for (; this[index].Equals(l2) == false; index++) { distance += this[index].Length; } if (index < Count) { distance += EarthGeo.GetDistance(p2 as GeoPoint, l2.P1 as GeoPoint); } } } return(distance); }
public bool TryGetDistanceBetweenTwoPointsOnPath(GeoPoint p1, GeoPoint p2, out Double distance) { bool success = false; distance = 0; /** get the line each point lies on */ GeoLine l1, l2; Double d1, d2; if (TryGetLineForPoint(p1, .1, out l1) && TryGetLineForPoint(p2, .1, out l2)) { if (l1.Equals(l2)) { distance = EarthGeo.GetDistance(p1, p2); success = true; } else if (TryGetDistanceFromEnd(p1, out d1) && TryGetDistanceFromEnd(p2, out d2)) { if (d1 > d2) { distance = GetDistanceForTwoOrderedPoints(l1, p1, l2, p2); } else { distance = GetDistanceForTwoOrderedPoints(l2, p2, l1, p1); } success = true; } } return(success); }
public bool TryGetDistanceFromEnd(GeoPoint point, out Double distance) { bool success = false; distance = 0; GeoLineList list = new GeoLineList(this); list.Reverse(); for (int index = 0; index < list.Count; index++) { GeoLine line = list[index]; GeoPoint closest; Double thisDistance; closest = line.ClosestPointTo(point, out thisDistance); /** less than this distance, he is on the line */ if (thisDistance > .1) { distance += line.Length; } else { distance += EarthGeo.GetDistance(line.P2 as GeoPoint, closest); success = true; break; } } return(success); }
public GeoPoint ClosestEndPointTo(GeoPoint point, out Double distance) { Double d1 = EarthGeo.GetDistance(_P1, point); Double d2 = EarthGeo.GetDistance(_P2, point); distance = Math.Min(d1, d2); return(d1 < d2 ? _P1 : _P2); }
public static GeoCircle CreateFromRegionPolygon(GeoPolygon polygon) { GeoPoint centroid = polygon.Centroid; List <Double> distances = new List <Double>(); foreach (GeoPoint point in polygon.Points) { distances.Add(EarthGeo.GetDistance(centroid, point)); } return(new GeoCircle(centroid, distances.Average())); }
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 void ExtendTo(GeoPoint point) { Double d1 = EarthGeo.GetDistance(_P1, point); Double d2 = EarthGeo.GetDistance(_P2, point); if (d1 < d2) { _P1 = point; } else { _P2 = point; } }
void Initialize(PointDList pixPointList, GeoPointList geoPointList) { // Get and store the difference in pixel orientation to north (Rotation from north) double geoBearing = EarthGeo.GetBearing(geoPointList[0], geoPointList[1]); double pixBearing = GetPixelBearing(pixPointList[0], pixPointList[1]); this.BearingDelta = geoBearing - pixBearing; // Get and store the pixel to meter ratio (Scale to meters) double geoDistance = EarthGeo.GetDistance(geoPointList[0], geoPointList[1]); double pixDistance = new Line(pixPointList[0], pixPointList[1]).Length; _pixelsPerMeter = pixDistance / geoDistance; // Store a pixel cross reference point, from which all other conversions can happen this.PixPoint = new PointD(pixPointList[0].X, pixPointList[0].Y); this.GeoPoint = new GeoPoint(geoPointList[0].Y, geoPointList[0].X); }
public GeoPoint ClosestPointTo(GeoPoint pt, out Double distance) { /** SPSPTODO: This needs to use spherical trig */ PointD closest; Double dx = P2.X - P1.X; Double dy = P2.Y - P1.Y; // Calculate the t that minimizes the distance. Double t = ((pt.X - P1.X) * dx + (pt.Y - P1.Y) * dy) / (dx * dx + dy * dy); // See if this represents one of the segment's // end points or a point in the middle. if (t < 0) { closest = new PointD(P1.X, P1.Y); dx = pt.X - P1.X; dy = pt.Y - P1.Y; } else if (t > 1) { closest = new PointD(P2.X, P2.Y); dx = pt.X - P2.X; dy = pt.Y - P2.Y; } else { closest = new PointD(P1.X + t * dx, P1.Y + t * dy); dx = pt.X - closest.X; dy = pt.Y - closest.Y; } GeoPoint ret = new GeoPoint(closest); distance = EarthGeo.GetDistance(pt, ret); return(ret); }
public override bool Intersects(GeoLine line, out GeoPoint intersection1, out GeoPoint intersection2, out int intersections) { intersection1 = new GeoPoint(float.NaN, float.NaN); intersection2 = new GeoPoint(float.NaN, float.NaN); const Double increment = .1; bool intersects = false; GeoPoint p = line.P1.Clone() as GeoPoint; do { if (this.Contains(p)) { intersects = true; break; } p = EarthGeo.GetPoint(p, line.Bearing, increment); } while(EarthGeo.GetDistance(line.P1 as GeoPoint, p) < line.Length); intersections = 0; if (intersects) { Double degy = EarthGeo.DegreesPerMeterAtLatitude(_center.Latitude); Double degx = EarthGeo.DegreesPerMeterAtLongitude(_center.Longitude); Double radius = Radius * Math.Max(degx, degy); Double dx, dy, A, B, C, det, t; dx = line.P2.X - line.P1.X; dy = line.P2.Y - line.P1.Y; A = dx * dx + dy * dy; B = 2 * (dx * (line.P1.X - Center.X) + dy * (line.P1.Y - Center.Y)); C = (line.P1.X - Center.X) * (line.P1.X - Center.X) + (line.P1.Y - Center.Y) * (line.P1.Y - Center.Y) - radius * radius; det = B * B - 4 * A * C; if ((A <= 0.00000001) || (det < 0)) { // No real solutions. intersection1 = new GeoPoint(float.NaN, float.NaN); intersection2 = new GeoPoint(float.NaN, float.NaN); } else if (det == 0) { // One solution. t = -B / (2 * A); intersection1 = new GeoPoint(line.P1.X + t * dx, line.P1.Y + t * dy); intersection2 = new GeoPoint(float.NaN, float.NaN); intersections = 1; } else { // Two solutions. t = (float)((-B + Math.Sqrt(det)) / (2 * A)); intersection1 = new GeoPoint(line.P1.X + t * dx, line.P1.Y + t * dy); t = (float)((-B - Math.Sqrt(det)) / (2 * A)); intersection2 = new GeoPoint(line.P1.X + t * dx, line.P1.Y + t * dy); intersections = 2; } } return(intersects); }
public override bool Contains(GeoPoint point) { Double distance = EarthGeo.GetDistance(_center, point); return(distance <= Radius); }