Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }
Example #4
0
        public static bool TryParse(String value, out GeoLine line)
        {
            line = null;
            int index1 = value.IndexOf(GeoPoint.TOSTRING_DELIM);

            String name = String.Empty;

            if (index1 > 0)
            {
                name  = value.Substring(0, index1).Trim();
                value = value.Substring(index1).Trim();
            }

            int index = value.IndexOf(" - ");

            if (index > 0)
            {
                String s1 = value.Substring(0, index).Trim();
                String s2 = value.Substring(index + 2).Trim();

                GeoPoint p1, p2;
                if (GeoPoint.TryParse(s1, out p1) && GeoPoint.TryParse(s2, out p2))
                {
                    line      = new GeoLine(p1, p2);
                    line.Name = name;
                }
            }
            return(line != null);
        }
Example #5
0
        public static bool GetIntersection2(GeoLine l1, GeoLine l2, int precision, out GeoPoint intersection)
        {
            bool result = false;

            result = GetIntersection2(l1.P1 as GeoPoint, l1.Bearing, l2.P1 as GeoPoint, l2.Bearing, out intersection);

//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;
            }

            return(result);
        }
Example #6
0
        public bool TryGetPointAtDistanceFromEnd(Double distance, out GeoPoint point)
        {
            point = null;

            Double      totalLength = 0;
            GeoLineList list        = new GeoLineList(this);

            list.Reverse();

            for (int index = 0; point == null && index < list.Count; index++)
            {
                GeoLine line      = list[index];
                Double  newLength = totalLength + line.Length;
                if (newLength > distance)
                {
                    Double segLength = distance - totalLength;
                    point = EarthGeo.GetPoint(line.P2 as GeoPoint, Angle.Reverse(line.Bearing), segLength);
                }
                else
                {
                    totalLength = newLength;
                }
            }
            return(point != null);
        }
Example #7
0
        public override bool Intersects(GeoLine line)
        {
            GeoPoint i1, i2;
            int      intersections;

            return(Intersects(line, out i1, out i2, out intersections));
        }
Example #8
0
 public bool SharesEndPointWith(GeoLine other, int precision = 0)
 {
     return
         (other.P1.Equals(P1, precision) ||
          other.P1.Equals(P2, precision) ||
          other.P2.Equals(P1, precision) ||
          other.P2.Equals(P2, precision));
 }
Example #9
0
        public void Expand(Double meters)
        {
            /** SPSP THIS WILL NOT WORK */
            GeoLine cross1 = new GeoLine(GeoPoints[0], GeoPoints[2]);
            GeoLine cross2 = new GeoLine(GeoPoints[1], GeoPoints[3]);

            GeoPoints[0].Move(Angle.Reverse(cross1.Bearing), meters);
            GeoPoints[1].Move(Angle.Reverse(cross2.Bearing), meters);
            GeoPoints[2].Move(cross1.Bearing, meters);
            GeoPoints[3].Move(cross2.Bearing, meters);
        }
Example #10
0
        void RecalculateAxes()
        {
            MajorAxis = new GeoLine(
                EarthGeo.GetPoint(_center, Angle.Reverse(m_MajorAxisBearing), m_MajorAxisLength / 2),
                EarthGeo.GetPoint(_center, m_MajorAxisBearing, m_MajorAxisLength / 2));

            Double minorAxisBearing = Angle.Add(m_MajorAxisBearing, 90);

            MinorAxis = new GeoLine(
                EarthGeo.GetPoint(_center, Angle.Reverse(minorAxisBearing), m_MinorAxisLength / 2),
                EarthGeo.GetPoint(_center, minorAxisBearing, m_MinorAxisLength / 2));
        }
Example #11
0
        public GeoLine NearestEdgeFrom(GeoPoint point)
        {
            Double  closest    = Double.MaxValue;
            GeoLine closetLine = new GeoLine();

            foreach (GeoLine line in this.Lines)
            {
                Double   distance;
                GeoPoint p = line.ClosestPointTo(point, out distance);
                if (distance < closest)
                {
                    closest    = distance;
                    closetLine = line;
                }
            }
            return(closetLine);
        }
Example #12
0
        public bool TryGetLineForPoint(GeoPoint point, Double precision, out GeoLine line)
        {
            line = null;
            Double shortest = Double.MaxValue;

            foreach (GeoLine l in this)
            {
                Double   distance;
                GeoPoint closest = l.ClosestPointTo(point, out distance);
                if (distance <= precision)
                {
                    if (distance < shortest)
                    {
                        line     = l;
                        shortest = distance;
                    }
                }
            }
            return(line != null);
        }
Example #13
0
        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);
        }
Example #14
0
 public bool Intersects(GeoLine other, int precision, out GeoPoint intersection)
 {
     return(EarthGeo.GetIntersection(this, other, precision, out intersection));
 }
Example #15
0
 public bool Intersects(GeoLine other, out GeoPoint intersection)
 {
     return(Intersects(other, EarthGeo.GeoPrecision, out intersection));
 }
Example #16
0
        public bool Intersects(GeoLine other)
        {
            GeoPoint intersection;

            return(Intersects(other, out intersection));
        }
Example #17
0
 public static bool GetIntersection(GeoLine l1, GeoLine l2, out GeoPoint retPoint)
 {
     return(GetIntersection(l1, l2, EarthGeo.GeoPrecision, out retPoint));
 }
Example #18
0
        public bool Contains(GeoPoint point, Double rayLength = DEFAULT_RAY_LENGTH)
        {
            /** Use Ray-Casting Algorithm to determine if point lies within polygon */

            Double rayBearing = EarthGeo.North;
            float  insides    = 0;
            float  outsides   = 0;

            int minimumRays = 4;

            bool majority = false;

            /**
             * We will cast at least two rays and keep casting till we get a majority of
             * one or the other, or we go in a circle.
             */
            do
            {
                /**
                 * Step One:
                 *   Create a ray from our point extending outwards
                 */
                GeoPoint endPoint = EarthGeo.GetPoint(point, rayBearing, rayLength);
                GeoLine  ray      = new GeoLine(point, endPoint);

                /**
                 * Step 2
                 *   Draw line from our point in any direction (we will use North)
                 *   and count the intersections
                 */
                Double intersections = 0;
                foreach (GeoLine line in Lines)
                {
                    if (ray.Intersects(line))
                    {
                        intersections++;
                    }
                }

                /** if the intersections are even, the point is outside... if odd, it's inside */
                bool inside = (intersections % 2) != 0;

                if (inside)
                {
                    insides++;
                }
                else
                {
                    outsides++;
                }

                rayBearing = Angle.Add(rayBearing, 95);

                if (insides + outsides >= minimumRays)
                {
                    majority = insides > outsides * 2 || outsides > insides * 2;
                }
            }while(majority == false && !(insides + outsides >= 360 / 5));

            return(insides > outsides);
        }
Example #19
0
 public virtual bool Intersects(GeoLine line, out GeoPoint intersection1, out GeoPoint intersection2, out int intersectionsCalculated)
 {
     throw new NotImplementedException();
 }
Example #20
0
 public bool Equals(GeoLine l)
 {
     return(l.P1.X == P1.X && l.P1.Y == P1.Y && l.P2.X == P2.X && l.P2.Y == P2.Y);
 }
Example #21
0
 public virtual bool Intersects(GeoLine line)
 {
     throw new NotImplementedException();
 }
Example #22
0
        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);
        }
Example #23
0
 public GeoEllipse(GeoLine majorAxis, GeoLine minorAxis)
     : this(majorAxis.MidPoint, majorAxis.Length, minorAxis.Length, majorAxis.Bearing)
 {
     MajorAxis = majorAxis;
     MinorAxis = minorAxis;
 }