Exemplo n.º 1
0
        public static List <Point> GetIntersection(Polyline poly, ConvexPolygon polygon)
        {
            var poList   = new List <Point>();
            var polySegm = Polyline.PointsToSegments(poly.Points);

            polySegm = polySegm.GetRange(0, polySegm.Count - 1);
            foreach (var segment in polySegm)
            {
                //for (int index = 0; index < polySegments.Count; index++)
                //{
                //    if ((!isLeft(polySegments[index], normals[index], segment.Begin)) &&
                //        (!isLeft(polySegments[index], normals[index], segment.End)))
                //    {
                //        index = polySegments.Count;
                //    }
                //    else
                //    {
                //        if (GetIntersection(segment, polySegments[index]).Count > 0)
                //            poList.Add((GetIntersection(segment, polySegments[index]))[0]);
                //    }
                //}
                if (GetIntersection(segment, polygon).Count > 0)
                {
                    poList.AddRange(GetIntersection(segment, polygon));
                }
                //if (poList.Count == 0)
                //{
                //    poList.Add(polySegm[0].Begin);
                //    poList.Add(polySegm.Last().End);
                //}
            }

            return(poList);
        }
Exemplo n.º 2
0
        // Пересечение полигона и круга
        public static bool IsIntersected(ConvexPolygon polygon, Circle circle)
        {
            var segments = Polyline.PointsToSegments(polygon.Points);

            foreach (var segment in segments)
            {
                if (IsIntersected(segment, circle))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Устанавливает список точек и нормалей
        /// </summary>
        public ConvexPolygon(List <Point> newPoints, List <Point> normals)
        {
            var set = Polyline.PointsToSegments(newPoints);

            if (!CheckSelfIntersection(set))
            {
                this.points  = newPoints;
                this.normals = normals;
            }
            else
            {
                throw new Exception(Messages.SelfIntersection);
            }
        }
Exemplo n.º 4
0
        public ConvexPolygon(List <Point> newPoints, List <Point> normals)
        {
            var set = Polyline.PointsToSegments(newPoints);

            if (convex(set))
            {
                this.points  = newPoints;
                this.normals = normals;
            }
            else
            {
                throw new Exception("Incorrect Polygon");
            }
        }
Exemplo n.º 5
0
        // Пересечение точки и полигона
        public static bool IsIntersected(Point Point, ConvexPolygon polygon)
        {
            var segments = Polyline.PointsToSegments(polygon.Points);
            var normals  = polygon.Normals;

            for (int index = 0; index < segments.Count; index++)
            {
                if (!isLeft(segments[index], normals[index], Point))
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Проверка пересечения ломаной и многоугольника
        /// </summary>
        /// <returns>Возвращает список точек пересечения</returns>
        public static List <Point> GetIntersection(Polyline poly, ConvexPolygon polygon)
        {
            var poList   = new List <Point>();
            var polySegm = Polyline.PointsToSegments(poly.Points);

            foreach (var segment in polySegm)
            {
                if (GetIntersection(segment, polygon).Count > 0)
                {
                    poList.AddRange(GetIntersection(segment, polygon));
                }
            }

            return(poList);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Возвращает список точек с вершинами квадрата, длина ребра которого edge, одна из точек - point
        /// </summary>
        public ConvexPolygon(Point point, double edge)
        {
            //var Mainpoints = new List<Point>();
            var points = new List <Point>();

            points.Add(point);
            points.Add(new Point(point.X + edge, point.Y));
            points.Add(new Point(point.X + edge, point.Y + edge));
            points.Add(new Point(point.X, point.Y + edge));

            var set = Polyline.PointsToSegments(points);

            normals = new List <Point>(/*set.Count*/);
            foreach (var segment in set)
            {
                normals.Add(GetLeftNormal(segment));
            }
        }
Exemplo n.º 8
0
        public ConvexPolygon(List <Point> newPoints)
        {
            var set = Polyline.PointsToSegments(newPoints);

            if (convex(set))
            {
                this.points = newPoints;
                normals     = new List <Point>(/*set.Count*/);
                foreach (var segment in set)
                {
                    normals.Add(GetLeftNormal(segment));
                }
            }
            else
            {
                throw new Exception("Incorrect Polygon");
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Получает список отрезков, соединяющий точки из списка и нормали к ним
        ///
        /// </summary>
        /// <param name="newPoints">Список точек, отмеченных в окне редактора карт</param>
        public ConvexPolygon(List <Point> newPoints)
        {
            var set = Polyline.PointsToSegments(newPoints);

            if (!CheckSelfIntersection(set))
            {
                this.points = newPoints;
                normals     = new List <Point>(/*set.Count*/);
                for (int index = 0; index < set.Count; index++)
                {
                    var segment = set[index];
                    normals.Add(GetLeftNormal(segment));
                }
            }
            else
            {
                throw new Exception(Messages.SelfIntersection);
            }
        }
Exemplo n.º 10
0
        ///<summary>
        /// Поиск точек пересечений Полигона с Полигоном
        /// </summary>
        public static List <Point> GetIntersection(ConvexPolygon fpolygon, ConvexPolygon spolygon)
        {
            var poList    = new List <Point>();
            var fpolySegm = Polyline.PointsToSegments(fpolygon.Points);
            var spolySegm = Polyline.PointsToSegments(spolygon.Points);

            foreach (var fsegment in fpolySegm)
            {
                foreach (var ssegment in spolySegm)
                {
                    if ((GetIntersection(fsegment, ssegment)).Count > 0)
                    {
                        poList.Add(GetIntersection(fsegment, ssegment)[0]);
                    }
                }
            }

            return(poList);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Проверка пересечения отрезка и многоугольника
        /// </summary>
        /// <returns>Возвращает список точек пересечения</returns>
        public static List <Point> GetIntersection(Segment segment, ConvexPolygon polygon)
        {
            var poList       = new List <Point>();
            var polySegments = Polyline.PointsToSegments(polygon.Points);
            var normals      = polygon.Normals;

            for (int index = 0; index < polySegments.Count; index++)
            {
                if ((!isLeft(polySegments[index], normals[index], segment.Begin)) && (!isLeft(polySegments[index], normals[index], segment.End)))
                {
                    return(poList);
                }
                else
                {
                    if (GetIntersection(segment, polySegments[index]).Count > 0)
                    {
                        poList.Add((GetIntersection(segment, polySegments[index]))[0]);
                    }
                }
            }
            if (IsIntersected(segment.Begin, polygon))
            {
                poList.Add(segment.Begin);
            }
            if (IsIntersected(segment.End, polygon))
            {
                poList.Add(segment.End);
            }
            for (int j = 0; j < poList.Count; j++)
            {
                for (int k = j + 1; k < poList.Count; k++)
                {
                    if ((poList[j].X == poList[k].X) && (poList[j].Y == poList[k].Y))
                    {
                        poList.Remove(poList[j]);
                    }
                }
            }

            return(poList);
        }
Exemplo n.º 12
0
 /// <summary>
 /// Преобразует массив точек в список точек, получает нормали для отрезков, соединяющих эти точки
 /// </summary>
 /// <param name="point"></param>
 public ConvexPolygon(params Point[] point)
 {
     if (point.Count() > 0)
     {
         var newPoints = point.ToList();
         var set       = Polyline.PointsToSegments(newPoints);
         if (!CheckSelfIntersection(set))
         {
             this.points = newPoints;
             normals     = new List <Point>(/*set.Count*/);
             foreach (var segment in set)
             {
                 normals.Add(GetLeftNormal(segment));
             }
         }
         else
         {
             throw new Exception(Messages.SelfIntersection);
         }
     }
 }
Exemplo n.º 13
0
        // Поиск точек пересечений Полигона с Полигоном
        public static List <Point> GetIntersection(ConvexPolygon fpolygon, ConvexPolygon spolygon)
        {
            var poList    = new List <Point>();
            var fpolySegm = Polyline.PointsToSegments(fpolygon.Points);
            var spolySegm = Polyline.PointsToSegments(spolygon.Points);

            foreach (var fsegment in fpolySegm)
            {
                foreach (var ssegment in spolySegm)
                {
                    if ((GetIntersection(fsegment, ssegment)).Count > 0)
                    {
                        poList.Add(GetIntersection(fsegment, ssegment)[0]);
                    }
                }
                //for (int index = 0; index < polySegments.Count; index++)
                //{
                //    if ((!isLeft(polySegments[index], normals[index], segment.Begin)) &&
                //        (!isLeft(polySegments[index], normals[index], segment.End)))
                //    {
                //        index = polySegments.Count;
                //    }
                //    else
                //    {
                //        if (GetIntersection(segment, polySegments[index]).Count > 0)
                //            poList.Add((GetIntersection(segment, polySegments[index]))[0]);
                //    }
                //}
                //if (GetIntersection(segment, spolygon).Count > 0) poList.AddRange(GetIntersection(segment, spolygon));
                //if (poList.Count == 0)
                //{
                //    poList.Add(polySegm[0].Begin);
                //    poList.Add(polySegm.Last().End);
                //}
            }

            return(poList);
        }
Exemplo n.º 14
0
        public static List <Point> GetIntersection(Segment segment, ConvexPolygon polygon)
        {
            var poList       = new List <Point>();
            var polySegments = Polyline.PointsToSegments(polygon.Points);
            var normals      = polygon.Normals;

            for (int index = 0; index < polySegments.Count; index++)
            {
                if ((!isLeft(polySegments[index], normals[index], segment.Begin)) && (!isLeft(polySegments[index], normals[index], segment.End)))
                {
                    return(poList);
                }
                else
                {
                    if (GetIntersection(segment, polySegments[index]).Count > 0)
                    {
                        poList.Add((GetIntersection(segment, polySegments[index]))[0]);
                    }
                }
            }
            //if (poList.Count==0)
            //{
            //    poList.Add(segment.Begin);
            //    poList.Add(segment.End);
            //}
            if (IsIntersected(segment.Begin, polygon))
            {
                poList.Add(segment.Begin);
            }
            if (IsIntersected(segment.End, polygon))
            {
                poList.Add(segment.End);
            }
            ;

            return(poList);
        }
Exemplo n.º 15
0
        // Поиск точек пересечений Полигона со списком точек (array)
        public static List <Point> GetIntersection(ConvexPolygon polygon, params Point[] arr)
        {
            int type     = 0; // flag of ConvexPolygon type intersect (Polyline,Segment,Point)
            var points   = new List <Point>();
            var segments = Polyline.PointsToSegments(polygon.Points);
            var normals  = polygon.Normals;

            switch (arr.Count())
            {
            case 0:     // Nothing
                return(new List <Point>());

            case 1:     // Point
                break;

            case 2:     // Segment
                type = 1;
                break;

            default:     // Polyline
                type = 2;

                var PolylineSegments = Polyline.PointsToSegments(arr.ToList());

                foreach (var polylineSegment in PolylineSegments)
                {
                    points.AddRange(Intersect.GetIntersection(polygon, polylineSegment.Begin, polylineSegment.End));
                }
                break;
            }

            for (int index = 0; index < segments.Count; index++)
            {
                var t = segments[index];

                if (type == 0)
                {
                    if (!isLeft(t, normals[index], arr[0]))
                    {
                        return(new List <Point>());
                    }
                }
                else if (type == 1)
                {
                    if (isLeft(t, normals[index], arr[0]) && !isLeft(t, normals[index], arr[1]) || !isLeft(t, normals[index], arr[0]) && isLeft(t, normals[index], arr[1]))
                    {
                        foreach (var segment in segments)
                        {
                            //if (Intersect.GetIntersection(new Segment(arr[0], arr[1]), segment).Count > 0) points.AddRange(Intersect.GetIntersection(new Segment(arr[0], arr[1]), segment));

                            var newSegment = new Segment(arr[0], arr[1]);

                            if (GetIntersection(newSegment, segment).Count > 0)
                            {
                                points.AddRange(Intersect.GetIntersection(new Segment(arr[0], arr[1]), segment));
                            }
                        }
                        break;
                    }
                    else if (!isLeft(t, normals[index], arr[0]) && !isLeft(t, normals[index], arr[1]))
                    {
                        return(new List <Point>());
                    }
                }
            }

            if (type == 0)
            {
                points.Add(arr[0]);
            }
            if (type == 1)
            {
                points.AddRange(new List <Point> {
                    arr[0], arr[1]
                });
            }

            return(points);
        }