/// <summary> /// 一个多边形和另外一个多边形之间的关系 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void PolygonInsideTestBtn_Click(object sender, RoutedEventArgs e) { List <Geometry2D> gss = this.drawingKernel.GeometryShapes; List <List <Line2D> > lines = new List <List <Line2D> >(); foreach (var g in gss) { if (g is PolygonGeometry) { List <Line2D> nlines = new List <Line2D>(); PolygonGeometry poly = g as DrawingKernel.Geometries.Primitives.PolygonGeometry; g.FillColor = Colors.Azure; g.Opacity = 0.3; poly.Update(); nlines.AddRange(poly.Lines); lines.Add(nlines); } if (g.GeometryId == "tp") { this.drawingKernel.RemoveGeometryShape(g); } } //计算多边形和多边形之间的关系 if (lines.Count == 2) { List <List <Line2D> > ins = new List <List <Line2D> >(); var result = GraphicAlgorithm.PolygonInsideOfRegion(lines[0], lines[1], ins); if (result == 1) { ins.ForEach(x => { PolygonGeometry pg = new PolygonGeometry(); x.ForEach(y => { pg.PPoints.Add(y.Start); }); pg.FillColor = Colors.Green; pg.GeometryId = "tp"; this.drawingKernel.AddShape(pg); }); } else if (result == 0) { ins.ForEach(x => { PolygonGeometry pg = new PolygonGeometry(); x.ForEach(y => { pg.PPoints.Add(y.Start); }); pg.FillColor = Colors.Red; pg.GeometryId = "tp"; this.drawingKernel.AddShape(pg); }); } else { MessageBox.Show("相离"); } } else { MessageBox.Show("不表现多个多边形的情况"); } }