Untitled
unknown
plain_text
a year ago
1.2 kB
1
Indexable
Never
using System.Windows; using System.Windows.Controls; using System.Windows.Shapes; public class ViewModel { public bool AreRectanglesTouchingOuterCircle(Canvas canvas, double outerCircleRadius) { foreach (UIElement element in canvas.Children) { if (element is Rectangle rectangle) { Point rectangleCenter = new Point(Canvas.GetLeft(rectangle) + rectangle.Width / 2, Canvas.GetTop(rectangle) + rectangle.Height / 2); // Calculate the distance between the rectangle center and the outer circle center double distance = CalculateDistance(rectangleCenter, new Point(0, 0)); // Check if the distance is less than or equal to the outer circle radius if (distance <= outerCircleRadius) { return true; // At least one rectangle is touching the outer circle } } } return false; // No rectangle is touching the outer circle } private double CalculateDistance(Point p1, Point p2) { double dx = p1.X - p2.X; double dy = p1.Y - p2.Y; return Math.Sqrt(dx * dx + dy * dy); } }