コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: Anovi-Soft/KGG
        private void Window_Activated_1(object sender, EventArgs e)
        {
            var pol1 = new MyPolygon(new List<Vector>() {
                new Vector(0,3),
                new Vector(3,6),
                new Vector(6,3),
                new Vector(3,0)});

            var pol2 = new MyPolygon(new List<Vector>() {
                new Vector(4,0),
                new Vector(15, 5),
                new Vector(15,1)});

            DrawPolygon(pol1, Colors.LightSalmon);
            DrawPolygon(pol2, Colors.HotPink);

            MyPolygon pol3;
            try
            {
                pol3 = MyPolygon.Intersection(pol1, pol2);
            }
            catch (DisjointPolygons)
            {
                return;
            }
            DrawPolygon(pol3, Colors.DarkBlue);
        }
コード例 #2
0
ファイル: MainWindow.xaml.cs プロジェクト: Anovi-Soft/KGG
 public void DrawPolygon(MyPolygon poly, Color fill)
 {
     var polygon = new Polygon();
     polygon.Points = new PointCollection(poly.Points.Select(a => new Point(Math.Round(a.X * step + canvasSize / 2),
                                                                            Math.Round(-a.Y * step + canvasSize / 2))));
     polygon.Stroke = Brushes.Black;
     polygon.Fill = new SolidColorBrush(fill);
     polygon.StrokeThickness = 1;
     canvas.Children.Add(polygon);            
 }
コード例 #3
0
ファイル: MyPolygon.cs プロジェクト: Anovi-Soft/KGG
 public static MyPolygon Intersection(MyPolygon a, MyPolygon b)
 {
     b.points.Add(b.points.First());
     for (int i = 0; i < b.points.Count - 1; i++)
     {
         a = Intersection(a, new Segment(b.points[i], b.points[i + 1]));
         if (a.Points.Count == 0)
             throw new DisjointPolygons();
     }
     return a; 
 }
コード例 #4
0
ファイル: MyPolygon.cs プロジェクト: Anovi-Soft/KGG
 public static MyPolygon Intersection(MyPolygon a, Segment b)
 {
     List<Vector> result = new List<Vector>();
     a.points.Add(a.points.First());
     for (int i = 0; i < a.points.Count - 1; i++)
     {
         Vector start = a.points[i];
         Vector end = a.points[i + 1];
         bool s = b.PlaceOfPoint(start) <= 0; //справа
         bool e = b.PlaceOfPoint(end) <= 0; 
         if (s)
             result.Add(start);
         if (s ^ e)
             result.Add(b.CrossingPoint(new Segment(start, end)));
     }
     return new MyPolygon(result);
 }