Спасибо, что нашли время, чтобы посмотреть на это. Я пытаюсь объединить 2 многоугольника, я пытаюсь достичь этого.
Но это произошло
Но где -то в моем коде это выглядит, когда я добавляю второй полигон, он возвращаюсь к первой точке первого полигона
вот моя функция, где я стараюсь сместить их. Я попытался удалить дубликаты точек, но это, похоже, не сработало в моем случае < /p>
public PointCollection ReshapeAfterCollision(Shape shape1, Shape shape2)
{
// Change the Polygons to Geometry so Geometry can work with it
var geom1 = shape1.RenderedGeometry;
var geom2 = shape2.RenderedGeometry;
// Here i check if the lines have collision ( returns the lines that are touching eachother)
var collision = Geometry.Combine(geom1, geom2, GeometryCombineMode.Intersect, null);
// remove all the lines that touch eachother
var geom1Clean = Geometry.Combine(geom1, collision, GeometryCombineMode.Exclude, null);
var geom2Clean = Geometry.Combine(geom2, collision, GeometryCombineMode.Exclude, null);
// Here i merge the polygons
var merged = Geometry.Combine(geom1, geom2, GeometryCombineMode.Union, null);
var pathGeometry = merged.GetFlattenedPathGeometry();
// this is foreach sets the geometry path back to points so i can change it back to polygons
var points = new PointCollection();
foreach (var figure in pathGeometry.Figures)
{
Point? lastPoint = null;
// Add StartPoint only if it's not a duplicate
if (lastPoint == null || !figure.StartPoint.Equals(lastPoint.Value))
{
points.Add(figure.StartPoint);
lastPoint = figure.StartPoint;
}
foreach (var segment in figure.Segments)
{
if (segment is PolyLineSegment polyLineSegment)
{
foreach (var pt in polyLineSegment.Points)
{
if (!pt.Equals(lastPoint.Value))
{
points.Add(pt);
lastPoint = pt;
}
}
}
else if (segment is LineSegment lineSegment)
{
var pt = lineSegment.Point;
if (!pt.Equals(lastPoint.Value))
{
points.Add(pt);
lastPoint = pt;
}
}
}
// Only close manually if needed and not already closed
if (!figure.IsClosed && !lastPoint.Equals(figure.StartPoint))
{
points.Add(figure.StartPoint);
}
}
return points;
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... o-polygons