Exemple #1
0
 /// <summary>
 /// Функциядля проверки пересечения полигона и фигуры
 /// </summary>
 public static bool IsIntersected(ConvexPolygon polygon, Figure figure)
 {
     if (figure is Circle)
     {
         return(IsIntersected(polygon, figure as Circle));
     }
     else if (figure is ConvexPolygon)
     {
         return(IsIntersected(polygon, figure as ConvexPolygon));
     }
     else if (figure is Point)
     {
         return(IsIntersected(polygon, figure as Point));
     }
     else if (figure is Polyline)
     {
         return(IsIntersected(polygon, figure as Polyline));
     }
     else if (figure is Segment)
     {
         return(IsIntersected(figure as Segment, polygon));
     }
     else
     {
         return(false);
     }
 }
Exemple #2
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);
        }
Exemple #3
0
        ///<summary>
        /// Поиск точек пересечений Полигона со списком точек (array)
        ///</summary>
        public static List <Point> GetIntersection(ConvexPolygon polygon, params Point[] arr)
        {
            switch (arr.Count())
            {
            case 0:     // Nothing
                return(new List <Point>());

            case 1:     // Point
                if (IsIntersected(arr[0], polygon))
                {
                    return(new List <Point> {
                        arr[0]
                    });
                }
                else
                {
                    return(new List <Point>());
                }

            case 2:     // Segment
                return(GetIntersection(Polyline.PointsToSegments(arr.ToList())[0], polygon));

            default:     // Polyline
                return(GetIntersection(new Polyline(arr.ToList()), polygon));
            }
        }
Exemple #4
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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #7
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);
        }
Exemple #8
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);
        }
Exemple #9
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);
        }
Exemple #10
0
        public Area(List<object> fig)
        {
            var figs = fig.ConvertAll(x => (Figure) x);
            figures = figs;
            var points = new List<Point>();
            foreach (var figure in figs)
            {
                if (figure is Point)
                    points.Add((Point)figure);
                else if (figure is ConvexPolygon)
                    points.AddRange(((ConvexPolygon)figure).Points);
                else if (figure is Circle)
                {
                    points.Add(new Point(((Circle)figure).Center.X + ((Circle)figure).Radius, ((Circle)figure).Center.Y));
                    points.Add(new Point(((Circle)figure).Center.X, ((Circle)figure).Center.Y + ((Circle)figure).Radius));
                    points.Add(new Point(((Circle)figure).Center.X - ((Circle)figure).Radius, ((Circle)figure).Center.Y));
                    points.Add(new Point(((Circle)figure).Center.X, ((Circle)figure).Center.Y - ((Circle)figure).Radius));

                }
            }
            double minX = points[0].X, maxX = points[0].X, minY = points[0].Y, maxY = points[0].Y;
            foreach (var point in points)
            {
                if (point.X < minX) minX = point.X;
                if (point.X > maxX) maxX = point.X;
                if (point.Y < minY) minY = point.Y;
                if (point.Y > maxY) maxY = point.Y;
            }
            var listpo = new List<Point>()
                             {
                                 new Point(minX, maxY),
                                 new Point(minX, minY),
                                 new Point(maxX, minY),
                                 new Point(maxX, maxY)
                             };
            poly = new ConvexPolygon(listpo);
        }
Exemple #11
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);
        }
Exemple #12
0
 public BikovGroup(ConvexPolygon poligon)
     : base(poligon, BikovFea())
 {
 }
Exemple #13
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;
 }
Exemple #14
0
 // Установление пересечения Полигона и Ломанной
 public static bool IsIntersected(ConvexPolygon polygon, Polyline polyline)
 {
     return GetIntersection(polygon, polyline).Count > 0;
 }
Exemple #15
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;
        }
Exemple #16
0
 //public static List<Point> GetIntersection(Segment first, Segment second)
 //{
 //    Point vectorFirst = new Point(first.End.X - first.Begin.X, first.End.Y - first.Begin.Y);
 //    Point vectorSecond = new Point(second.End.X - second.Begin.X, second.End.Y - second.Begin.Y);
 //    var poList = new List<Point>();
 //    if (vectorFirst.X / vectorSecond.X == vectorFirst.Y / vectorSecond.Y)
 //    {
 //        if (Point.Length(first.Begin, first.End) > Point.Length(second.Begin, second.End))
 //        {
 //            if (IsIntersected(second.Begin, first)) poList.Add(second.Begin);
 //            if (IsIntersected(second.End, first)) poList.Add(second.End);
 //        }
 //        else
 //        {
 //            if (IsIntersected(first.Begin, second)) poList.Add(first.Begin);
 //            if (IsIntersected(first.End, second)) poList.Add(first.End);
 //        }
 //    }
 //    double p = 0, t = 0;
 //    double a1 = 0, a2 = 0, b1 = 0, b2 = 0, d1 = 0, d2 = 0;
 //    d1 = second.Begin.X - first.Begin.X;
 //    d2 = second.Begin.Y - first.Begin.Y;
 //    a1 = vectorFirst.X;
 //    a2 = vectorFirst.Y;
 //    b1 = vectorSecond.X;
 //    b2 = vectorSecond.Y;
 //    if (a1 == 0)
 //    {
 //        p = d1 / b1;
 //        t = (d2 - p * b2) / a2;
 //    }
 //    else
 //    {
 //    p = d2 - (d1 / a1) * a2;
 //    p = p / (b2 - (b1 * a2) / a1);
 //    t = (d1 - b1 * p) / a1;
 //    }
 //    p = -p;
 //    if ((IsIntersected(new Point(first.Begin.X + vectorFirst.X * t, first.Begin.Y + vectorFirst.Y * t), first))
 //        && (IsIntersected(new Point(second.Begin.X + vectorSecond.X * p, second.Begin.Y + vectorSecond.Y * p), second)))
 //    {
 //        Point pointInter = new Point(first.Begin.X + vectorFirst.X * t, first.Begin.Y + vectorFirst.Y * t);
 //        poList.Add(pointInter);
 //    }
 //    //if ((p <= 1) && (p >= 0) && (t <= 1) && (t >= 0))
 //    return poList;
 //}
 //public static List<Point> GetIntersection(Segment first, Segment second)
 //{
 //    //Point vectorFirst = new Point(first.End.X - first.Begin.X, first.End.Y - first.Begin.Y);
 //    //Point vectorSecond = new Point(second.End.X - second.Begin.X, second.End.Y - second.Begin.Y);
 //    Point firstNorm = LeftNormal(first);
 //    Point secondNorm = LeftNormal(second);
 //    List<Point> pointli = new List<Point>();
 //    if (((isLeft(first, firstNorm, second.Begin)) && (!(isLeft(first, firstNorm, second.End))))
 //        || (!(isLeft(first, firstNorm, second.Begin)) && (isLeft(first, firstNorm, second.End))))
 //    {
 //        if (((isLeft(second, secondNorm, first.Begin)) && (!(isLeft(second, secondNorm, first.End))))
 //            || (!(isLeft(second, secondNorm, first.Begin)) && (isLeft(second, secondNorm, first.End))))
 //        {
 //            Point vector = new Point(-firstNorm.X, -firstNorm.Y);
 //            pointli.Add();
 //        }
 //    }
 //}
 // Поиск пересечений Полигона и Ломанной
 public static List<Point> GetIntersection(ConvexPolygon polygon, Polyline polyline)
 {
     return Intersect.GetIntersection(polygon, polyline.Points.ToArray());
 }
Exemple #17
0
 /// <summary>
 /// Функция для проверки пересечения двух полигонов
 /// </summary>
 public static bool IsIntersected(ConvexPolygon curPolygon, ConvexPolygon movPolygon)
 {
     return(GetIntersection(curPolygon, movPolygon).Count > 0);
 }
Exemple #18
0
 public Area(ConvexPolygon polygon)
 {
     poly = polygon;
 }
Exemple #19
0
 /// <summary>
 /// Создание юнита с указанными областью расположения, свойствами и типом
 /// </summary>
 /// <param name="polygon"></param>
 /// <param name="features"></param>
 /// <param name="type"></param>
 public Unit(ConvexPolygon polygon, UnitFeatures features, UnitType type)
 {
     figures = new List<Figure> { polygon };
     Polygon = polygon;
     props = features;
     UnitType = type;
     unitCommander = new AutomaticCommander("", CommanderType.Common, this);
 }
Exemple #20
0
 /// <summary>
 /// создаёт юнит с заданными областью расположения, свойствами и указанным боевым командиром
 /// </summary>
 /// <param name="polygon">Область расположения</param>
 /// <param name="features">Свойства</param>
 /// <param name="commander">Боевой командир</param>
 public Unit(ConvexPolygon polygon, UnitFeatures features, AutomaticCommander commander)
 {
     figures = new List<Figure> { polygon };
     Polygon = polygon;
     props = features;
     unitCommander = commander;
 }
Exemple #21
0
 /// <summary>
 /// 
 /// Создаёт юнит по по области его расположения
 /// </summary>
 /// <param name="polygon"></param>
 public Unit(ConvexPolygon polygon)
 {
     figures = new List<Figure> { polygon };
     Polygon = polygon;
     unitCommander = new AutomaticCommander("");
 }
Exemple #22
0
 public static List <Point> IsIntersected(ConvexPolygon curPolygon, ConvexPolygon movPolygon)
 {
     return(GetIntersection(curPolygon, movPolygon));
 }
Exemple #23
0
 // Пересечение отрезка и полигона
 private static bool IsIntersected(Segment segment, ConvexPolygon polygon)
 {
     return GetIntersection(segment, polygon).Count > 0;
 }
        /// <summary>
        /// Обработка нажатия кнопки "Нарисовать", отрисовывает нужную местность
        /// </summary>
        private void drawArea(object sender, RoutedEventArgs e)
        {
            if (Drawer.ClickedPoints.Count == 0)
            {
                MessageBox.Show(Messages.EmptyClickedPoints);
            }
            else
            {
                try
                {
                    List <Geometry.Figure> po = new List <Geometry.Figure>();

                    if (Drawer.LandName == "Road" || Drawer.LandName == "Water")
                    {
                        #region Check Self Intersection

                        var listSeg = Geometry.Figures.Polyline.PointsToSegments(Drawer.ClickedPoints);
                        listSeg.Remove(listSeg.Last());

                        if (Geometry.Figures.Polyline.CheckSelfIntersection(listSeg))
                        {
                            throw new Exception(Messages.SelfIntersectionPolyline);
                        }

                        #endregion

                        Geometry.Figures.Polyline poly = new Geometry.Figures.Polyline(Drawer.ClickedPoints);
                        po.Add(poly);
                    }
                    else
                    {
                        ConvexPolygon CV = new ConvexPolygon();

                        //??
                        List <Geometry.Figures.Point>         mypoints    = new List <Geometry.Figures.Point>();
                        List <List <Geometry.Figures.Point> > mypolpoints = new List <List <Geometry.Figures.Point> >();

                        foreach (Geometry.Figures.Point p in Drawer.ClickedPoints)
                        {
                            mypoints.Add(new Geometry.Figures.Point(p.X, p.Y));
                        }

                        #region Check Self Intersection

                        var listSeg = Geometry.Figures.Polyline.PointsToSegments(mypoints);

                        if (Geometry.Figures.ConvexPolygon.CheckSelfIntersection(listSeg))
                        {
                            throw new Exception(Messages.SelfIntersection);
                        }

                        #endregion

                        mypolpoints = CV.ConvertToConvexList(mypoints);

                        Drawer.Line.Points.Clear();
                        List <Geometry.Figures.Point> polPoints = new List <Geometry.Figures.Point>();

                        Geometry.Figures.ConvexPolygon poly = new Geometry.Figures.ConvexPolygon(Drawer.ClickedPoints);

                        foreach (List <Geometry.Figures.Point> pointList in mypolpoints) //points
                        {
                            po.Add(new Geometry.Figures.ConvexPolygon(pointList));
                        }
                    }
                    switch (Drawer.LandName)
                    {
                    case "Sand":
                    {
                        GameEngine.Lands.Sand sand = new GameEngine.Lands.Sand(po);
                        map.Lands.Add(sand);
                        break;
                    }

                    case "Forest":
                    {
                        GameEngine.Lands.Forest forest = new GameEngine.Lands.Forest(po);
                        map.Lands.Add(forest);
                        break;
                    }

                    case "Water":
                    {
                        GameEngine.Lands.Water water = new GameEngine.Lands.Water(po);
                        map.Lands.Add(water);
                        break;
                    }

                    case "Mountain":
                    {
                        GameEngine.Lands.Mountains mountain = new GameEngine.Lands.Mountains(po);
                        map.Lands.Add(mountain);
                        break;
                    }

                    case "City":
                    {
                        GameEngine.Lands.City city = new GameEngine.Lands.City(po);
                        map.Lands.Add(city);
                        break;
                    }

                    case "LowLand":
                    {
                        GameEngine.Lands.Lowland lowLand = new GameEngine.Lands.Lowland(po);
                        map.Lands.Add(lowLand);
                        break;
                    }

                    case "Field":
                    {
                        GameEngine.Lands.Field field = new GameEngine.Lands.Field(po);
                        map.Lands.Add(field);
                        break;
                    }

                    case "Road":
                    {
                        GameEngine.Lands.Road road = new GameEngine.Lands.Road(po);
                        map.Lands.Add(road);
                        break;
                    }
                    }
                    resetPoints(null, null);
                    reDrawMap();
                    Drawer.ClickedPoints = new List <Geometry.Figures.Point>();
                }
                catch (Exception a)
                {
                    MessageBox.Show(a.Message);
                    resetPoints(null, null);
                    reDrawMap();
                    Drawer.ClickedPoints = new List <Geometry.Figures.Point>();
                }
            }
        }
Exemple #25
0
 /// <summary>
 /// Специальный конструктор который по Номеру Типа автоматически создает конкретный заполненный Юнит
 /// 1 - Группа Быкова
 /// 2 - Японцы
 /// 3 - Танки
 /// </summary>
 /// <param name="poligon">Область Юнита</param>
 /// <param name="type">Номер Типа</param>
 public Unit(ConvexPolygon poligon, int type)
 {
     Polygon = poligon;
     if (type == 1) // Тип 1
     {
         props = BikovGroup.BikovFea();
         UnitType = UnitType.Infantry;
     }
     if (type == 2) // Тип 2
     {
         props = JapaneseGroup.JapaneseGroupFea();
         UnitType = UnitType.Infantry;
     }
     if (type == 3)  // Тип 3
     {
         props = TankBattalion.TankBattalionFea();
         UnitType = UnitType.Armor;
     }
 }
Exemple #26
0
 public JapaneseGroup(ConvexPolygon poligon)
     : base(poligon, JapaneseGroupFea())
 {
 }
Exemple #27
0
 ///<summary>
 /// Поиск пересечений Полигона и Ломаной
 /// </summary>
 public static List <Point> GetIntersection(ConvexPolygon polygon, Polyline polyline)
 {
     return(Intersect.GetIntersection(polygon, polyline.Points.ToArray()));
 }
Exemple #28
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);
        }
Exemple #29
0
 /// <summary>
 /// Функциядля проверки пересечения полигона и фигуры
 /// </summary>
 public static bool IsIntersected(ConvexPolygon polygon, Figure figure)
 {
     if (figure is Circle) return IsIntersected(polygon, figure as Circle);
     else if (figure is ConvexPolygon) return IsIntersected(polygon, figure as ConvexPolygon);
     else if (figure is Point) return IsIntersected(polygon, figure as Point);
     else if (figure is Polyline) return IsIntersected(polygon, figure as Polyline);
     else if (figure is Segment) return IsIntersected( figure as Segment , polygon);
     else return false;
 }
Exemple #30
0
        ///<summary>
        /// Поиск точек пересечений Полигона со списком точек (array)
        ///</summary>
        public static List<Point> GetIntersection(ConvexPolygon polygon, params Point[] arr)
        {
            switch (arr.Count())
            {
                case 0: // Nothing
                    return new List<Point>();
                case 1: // Point
                    if (IsIntersected(arr[0], polygon))
                    {
                        return new List<Point> { arr[0] };
                    }
                    else
                    {
                        return new List<Point>();
                    }
                case 2: // Segment
                    return GetIntersection(Polyline.PointsToSegments(arr.ToList())[0], polygon);
                default: // Polyline
                    return GetIntersection(new Polyline(arr.ToList()), polygon);

            }
        }
Exemple #31
0
 /// <summary>
 /// Функция для проверки пересечения двух полигонов
 /// </summary>
 public static bool IsIntersected(ConvexPolygon curPolygon, ConvexPolygon movPolygon)
 {
     return GetIntersection(curPolygon, movPolygon).Count > 0;
 }
Exemple #32
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;
        }
Exemple #33
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;
 }
Exemple #34
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;
        }
Exemple #35
0
        IDrawable run(IDrawable input)
        {
            if (!(input is PointSet))
            {
                throw new Exception("PolygonTest. Input is not PolygonTest.");
            }
            var inp = input as PointSet;
            Point c = inp[0]; Point d = inp[1]; Point e = inp[2]; Point fe = inp[3];

            ConvexPolygon f1 = new ConvexPolygon(new Point((c.X + d.X) / 2, c.Y), new Point(d.X, (c.Y + d.Y) / 3), new Point(d.X, 2 * ((d.Y + c.Y) / 3)), new Point((c.X + d.X) / 2, d.Y), new Point(c.X, 2 * ((d.Y + c.Y) / 3)), new Point(c.X, ((d.Y + c.Y) / 3)));
            ConvexPolygon f2 = new ConvexPolygon(new Point((e.X + fe.X) / 2, e.Y), new Point(fe.X, (e.Y + fe.Y) / 3), new Point(fe.X, 2 * ((fe.Y + e.Y) / 3)), new Point((e.X + fe.X) / 2, fe.Y), new Point(e.X, 2 * ((fe.Y + e.Y) / 3)), new Point(e.X, ((fe.Y + e.Y) / 3)));
            var x = Intersect.GetIntersection(f1,f2);
            if (x.Count > 0) return new DrawableSet(new List<IDrawable>() { new PointSet(x.ToArray()),new PolygonSet(f1,f2), DrawableElement.Text(0, 0, "Vse horosho") });
            else return new DrawableSet(new List<IDrawable>() { new PointSet(x.ToArray()), new PolygonSet(f1, f2), DrawableElement.Text(0, 0, "Vse ploho") });
        }
Exemple #36
0
 // Установление пересечения Полигона со списком точек (array)
 public static bool IsIntersected(ConvexPolygon polygon, params Point[] arr)
 {
     return GetIntersection(polygon, arr).Count > 0;
 }
Exemple #37
0
 ///<summary>
 /// Установление пересечения Полигона и Ломанной
 /// </summary>
 public static bool IsIntersected(ConvexPolygon polygon, Polyline polyline)
 {
     return(GetIntersection(polygon, polyline).Count > 0);
 }
Exemple #38
0
 public static List<Point> IsIntersected(ConvexPolygon curPolygon, ConvexPolygon movPolygon)
 {
     return GetIntersection(curPolygon, movPolygon);
 }
Exemple #39
0
        ///<summary>
        /// Установление пересечения Полигона со списком точек (array)
        /// </summary>

        public static bool IsIntersected(ConvexPolygon polygon, params Point[] arr)
        {
            return(GetIntersection(polygon, arr).Count > 0);
        }
        /// <summary>
        /// Создание войска. Войско создаётся при условии, что списки UnitCreater.Groups, UnitCreaters.Items не пусты
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CreateUnit(object sender, RoutedEventArgs e)
        {
            messageUnit.Text = "";

            if (Drawer.ClickedPoints.Count == 0)
            {
                MessageBox.Show(Messages.PositionIsNotChosen);
                return;
            }
            Geometry.Figures.ConvexPolygon polygon = new Geometry.Figures.ConvexPolygon(Drawer.ClickedPoints);

            try
            {
                //определяем тип юнита
                switch ((UnitType)UnitTypes.SelectionBoxItem)
                {
                case UnitType.Infantry:
                {
                    UnitCreater.Type = UnitType.Infantry;
                    break;
                }

                case UnitType.Cavalry:
                {
                    UnitCreater.Type = UnitType.Cavalry;
                    break;
                }

                case UnitType.Artillery:
                {
                    UnitCreater.Type = UnitType.Artillery;
                    break;
                }

                case UnitType.Armor:
                {
                    UnitCreater.Type = UnitType.Armor;
                    break;
                }

                case UnitType.AirForce:
                {
                    UnitCreater.Type = UnitType.AirForce;
                    break;
                }

                case UnitType.Navy:
                {
                    UnitCreater.Type = UnitType.Navy;
                    break;
                }

                case UnitType.Engineers:
                {
                    UnitCreater.Type = UnitType.Engineers;
                    break;
                }
                }
            }
            catch
            {
                MessageBox.Show(Messages.EmptyUnit, Messages.EmptyFields);
                return;
            }

            try
            {
                // определяем страну
                switch ((Countries)Country.SelectionBoxItem)
                {
                case Countries.USSR:
                {
                    UnitCreater.Country = Countries.USSR;
                    break;
                }

                case Countries.Japan:
                {
                    UnitCreater.Country = Countries.Japan;
                    break;
                }

                case Countries.Mongolia:
                {
                    UnitCreater.Country = Countries.Mongolia;
                    break;
                }

                case Countries.Manchukuo:
                {
                    UnitCreater.Country = Countries.Manchukuo;
                    break;
                }
                }
            }
            catch
            {
                MessageBox.Show(Messages.EmptyCountry, Messages.EmptyFields);
                return;
            }

            try
            {
                // определяем сторону
                switch (Side.Text)
                {
                case "1":
                {
                    UnitCreater.Side = 1;
                    break;
                }

                case "0":
                {
                    UnitCreater.Side = 0;
                    break;
                }
                }
            }
            catch
            {
                MessageBox.Show(Messages.EmptySide, Messages.EmptyFields);
                return;
            }


            try
            {
                if (UnitCreater.Groups.Count == 0 || UnitCreater.Items.Count == 0)
                {
                    throw new Exception();
                }

                UnitFeatures features = new UnitFeatures(UnitCreater.Groups, UnitCreater.Items);
                Unit         unit     = new Unit(polygon, features, UnitCreater.Type);
                unit.SetSide(UnitCreater.Side, UnitCreater.Country, null);

                UnitCreater.Groups = new List <Group>();
                UnitCreater.Items  = new List <Item>();

                map.Units.Add(unit);
                resetPoints(null, null);
                reDrawMap();
                messageUnit.Text = Messages.UnitIsCreated;
            }
            catch
            {
                MessageBox.Show(Messages.ItemOrGroupIsNotCreated);
            }
        }
Exemple #41
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;
        }
Exemple #42
0
 public TankBattalion(ConvexPolygon poligon)
     : base(poligon, TankBattalionFea())
 {
 }
Exemple #43
0
 // Пересечение отрезка и полигона
 private static bool IsIntersected(Segment segment, ConvexPolygon polygon)
 {
     return(GetIntersection(segment, polygon).Count > 0);
 }
        IDrawable run(IDrawable input)
        {
            if (!(input is PointSet))
            {
                throw new Exception("SegmentPolygonTest. Input is not SegmentPolygonTest.");
            }

            var inp = input as PointSet;

            Point a = inp[0]; Point c = inp[1]; Point d = inp[2]; Point e = inp[3];

            //a = new Point(10, 10); e = new Point(40, 10); Point ee = new Point(60, 40);
            //Segment b = new Segment(a, e); //Segment bbb = new Segment(e, ee);
            Segment b = new Segment(10, (c.Y + d.Y) / 2.5, 100, (c.Y + d.Y) / 2.5);
            var f = new ConvexPolygon(new Point((c.X + d.X) / 2, c.Y), new Point(d.X, (c.Y + d.Y) / 3), new Point(d.X, 2 * ((d.Y + c.Y) / 3)), new Point((c.X + d.X) / 2, d.Y), new Point(c.X, 2*((d.Y + c.Y) / 3)), new Point(c.X, ((d.Y + c.Y) / 3)));
            var fa = new ConvexPolygon(new Point((c.X + d.X) / 2 + 40, c.Y), new Point(d.X + 40, (c.Y + d.Y) / 3), new Point(d.X + 40, 2 * ((d.Y + c.Y) / 3)), new Point((c.X + d.X) / 2 + 40, d.Y), new Point(c.X + 40, 2 * ((d.Y + c.Y) / 3)), new Point(c.X + 40, ((d.Y + c.Y) / 3)));
            //var f = new ConvexPolygon(new Point(c.X, c.Y), new Point(d.X, c.Y), new Point(d.X, d.Y), new Point(c.X, d.Y));

            //var f = new ConvexPolygon(new Point(40,40), new Point(70,40), new Point(70,70), new Point(40,70));
            //b = new Segment(30,50,40,50);

            var x = Intersect.GetIntersection(b, f);// var y = Intersect.GetIntersection(f);
            var xx = Intersect.GetIntersection(b, fa);
            if (x.Count + xx.Count > 0) return new DrawableSet(new List<IDrawable>()
            { new PointSet(x.Concat(xx).ToArray()),
                new SegmentSet(b),
                new PolygonSet(f,fa),
                DrawableElement.Text(0, 0, "Vse horosho")
            });
            else return new DrawableSet(new List<IDrawable>()
            { new PointSet(x.Concat(xx).ToArray()),
                new SegmentSet(b),
                new PolygonSet(f, fa),
                DrawableElement.Text(0, 0, "Vse ploho")
            });
            //return new PointSet(x.ToArray());
        }
Exemple #45
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;
        }
        IDrawable run(IDrawable input)
        {
            if (!(input is PointSet))
            {
                throw new Exception("PolylinePoligonTest. Input is not PolylinePoligonTest.");
            }

            var inp = input as PointSet;

            Point a = inp[0]; Point c = inp[1]; Point d = inp[2]; Point e = inp[4];
            Point polyPoint1 = inp[4];

            Point aa = new Point(20, 20); e = new Point(30, 20); Point ee = new Point(50,30);
            Segment b = new Segment(aa, e); Segment eee = new Segment(e, ee); Segment eae = new Segment(new Point(50, 30), a);
            Polyline polyline = new Polyline(20, 20, 30, 20, 50, 30, a.X, a.Y);

            //Segment b = new Segment(a,e);
            //Segment eee = new Segment(e,new Point(3*(a.X+e.X)/2,4*(a.Y+e.Y)/2));
            //var polyline = new Polyline(new List<Point>() { a, e, new Point((a.X + e.X) / 2, (a.Y + e.Y) / 2) });

            //var f = new ConvexPolygon(new Point(c.X, c.Y), new Point(d.X, c.Y), new Point(d.X, d.Y), new Point(c.X, d.Y));

            var f = new ConvexPolygon(new Point((c.X + d.X) / 2, c.Y), new Point(d.X, (c.Y + d.Y) / 3), new Point(d.X, 2 * ((d.Y + c.Y) / 3)), new Point((c.X + d.X) / 2, d.Y), new Point(c.X, 2 * ((d.Y + c.Y) / 3)), new Point(c.X, ((d.Y + c.Y) / 3)));

            var x = Intersect.GetIntersection(polyline,f);
            if (x.Count > 0) return new DrawableSet(new List<IDrawable>() { new PointSet(x.ToArray()), new SegmentSet(b,eee,eae),new PolygonSet(f), DrawableElement.Text(0, 0, "Vse horosho") });
            else return new DrawableSet(new List<IDrawable>() { new PointSet(x.ToArray()),new SegmentSet(b,eee,eae), new PolygonSet(f), DrawableElement.Text(0, 0, "Vse ploho") });
        }
Exemple #47
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;
        }