Exemplo n.º 1
0
        public static GeomCoordinate GetNearestPoint(CoordinateRectangle line, GeomCoordinate pt)
        {
            const double r2D = 180 / Math.PI; // Constant for converting radians to degrees

            var a = GetLength(line.LeftTop, line.RightBottom);

            if (a <= 0)
            {
                return(pt);
            }

            var b = GetLength(line.LeftTop, pt);
            var c = GetLength(line.RightBottom, pt);

            var enB = Math.Acos((Math.Pow(a, 2) + Math.Pow(b, 2) - Math.Pow(c, 2)) / (2 * a * b)) * r2D;

            if (enB >= 90)
            {
                return(pt);
            }
            var enC = Math.Acos((Math.Pow(a, 2) + Math.Pow(c, 2) - Math.Pow(b, 2)) / (2 * a * c)) * r2D;

            if (enC >= 90)
            {
                return(pt);
            }


            var x = ((line.Right - line.Left) * (line.Bottom - line.Top) * (pt.Latitude - line.Top) +
                     line.Left * Math.Pow(line.Bottom - line.Top, 2) + pt.Longitude * Math.Pow(line.Right - line.Left, 2)) /
                    (Math.Pow(line.Bottom - line.Top, 2) + Math.Pow(line.Right - line.Left, 2));
            var y = (line.Bottom - line.Top) * (x - line.Left) / (line.Right - line.Left) + line.Top;

            return(new GeomCoordinate(x, y));
        }
Exemplo n.º 2
0
        public IntersectResult LineContains(CoordinateRectangle line)
        {
            var iLeftTop     = PointContains(line.LeftTop) != IntersectResult.None;
            var iRightBottom = PointContains(line.RightBottom) != IntersectResult.None;

            if (iLeftTop && iRightBottom)
            {
                return(IntersectResult.Contains);
            }
            if (iLeftTop || iRightBottom)
            {
                return(IntersectResult.Intersects);
            }
            if (MapUtilities.CheckLinesIntersection(new CoordinateRectangle(Left, Top, Right, Top), line))
            {
                return(IntersectResult.Intersects);
            }
            if (MapUtilities.CheckLinesIntersection(new CoordinateRectangle(Right, Top, Right, Bottom), line))
            {
                return(IntersectResult.Intersects);
            }
            if (MapUtilities.CheckLinesIntersection(new CoordinateRectangle(Left, Bottom, Right, Bottom), line))
            {
                return(IntersectResult.Intersects);
            }
            if (MapUtilities.CheckLinesIntersection(new CoordinateRectangle(Left, Top, Left, Bottom), line))
            {
                return(IntersectResult.Intersects);
            }
            return(IntersectResult.None);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Approximate distance from point to line segment
        /// Transmitted latitude / longitude in degrees and hundredths
        /// </summary>
        ///
        public static double GetDistance(CoordinateRectangle line, GeomCoordinate pt)
        {
            const double r2D = 180 / Math.PI; // Constant for converting radians to degrees

            var a = GetLength(line.LeftTop, line.RightBottom);

            var b = GetLength(line.LeftTop, pt);
            var c = GetLength(line.RightBottom, pt);

            if (a <= 0)
            {
                return((b + c) / 2);
            }

            var enB = Math.Acos((Math.Pow(a, 2) + Math.Pow(b, 2) - Math.Pow(c, 2)) / (2 * a * b)) * r2D;

            if (enB >= 90)
            {
                return(b);
            }
            var enC = Math.Acos((Math.Pow(a, 2) + Math.Pow(c, 2) - Math.Pow(b, 2)) / (2 * a * c)) * r2D;

            if (enC >= 90)
            {
                return(c);
            }

            var s  = (a + b + c) / 2;
            var ar = Math.Sqrt(s * (s - a) * (s - b) * (s - c));

            return(ar * 2 / a);
        }
Exemplo n.º 4
0
        public IntersectResult RectangleContains(CoordinateRectangle rectangle)
        {
            var iLeftTop     = PointContains(rectangle.LeftTop) != IntersectResult.None;
            var iRightBottom = PointContains(rectangle.RightBottom) != IntersectResult.None;

            if (iLeftTop && iRightBottom)
            {
                return(IntersectResult.Contains);
            }
            if (iLeftTop || iRightBottom)
            {
                return(IntersectResult.Intersects);
            }

            if (PointContains(rectangle.LeftBottom) != IntersectResult.None)
            {
                return(IntersectResult.Intersects);
            }
            if (PointContains(rectangle.RightTop) != IntersectResult.None)
            {
                return(IntersectResult.Intersects);
            }

            iLeftTop     = rectangle.PointContains(LeftTop) != IntersectResult.None;
            iRightBottom = rectangle.PointContains(RightBottom) != IntersectResult.None;

            if (iLeftTop && iRightBottom)
            {
                return(IntersectResult.Supersets);
            }
            if (iLeftTop || iRightBottom)
            {
                return(IntersectResult.Intersects);
            }

            if (rectangle.PointContains(LeftBottom) != IntersectResult.None)
            {
                return(IntersectResult.Intersects);
            }
            if (rectangle.PointContains(RightTop) != IntersectResult.None)
            {
                return(IntersectResult.Intersects);
            }

            if (MapUtilities.CheckLinesIntersection(new CoordinateRectangle(Left, Top, Left, Bottom),
                                                    new CoordinateRectangle(rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Top)))
            {
                return(IntersectResult.Intersects);
            }
            if (MapUtilities.CheckLinesIntersection(new CoordinateRectangle(Left, Top, Right, Top),
                                                    new CoordinateRectangle(rectangle.Left, rectangle.Top, rectangle.Left, rectangle.Bottom)))
            {
                return(IntersectResult.Intersects);
            }

            return(IntersectResult.None);
        }
Exemplo n.º 5
0
 public bool IncludeTo(CoordinateRectangle rect)
 {
     for (var i = 0; i < Coordinates.Count; i++)
     {
         if (rect.PointContains(Coordinates[i]) != IntersectResult.Contains)
         {
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 6
0
        public bool Add(GeomCoordinate coordinate)
        {
            if (Count > 2)
            {
                var line1 = new CoordinateRectangle(First, coordinate);
                var line2 = new CoordinateRectangle(Last, coordinate);
                for (var i = 0; i < Count - 1; i++)
                {
                    if (MapUtilities.CheckLinesIntersection(this[i], line1) ||
                        MapUtilities.CheckLinesIntersection(this[i], line2))
                    {
                        return(false);
                    }
                }
            }

            Coordinates.Add(coordinate);
            return(true);
        }
Exemplo n.º 7
0
        public IntersectResult PoligonContains(CoordinateRectangle coordinate)
        {
            //to do

            return(IntersectResult.None);
        }