Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.5 kB
3
Indexable
public class ViewModel
{
    public bool IsRectangleTopAtOuterBoundary(double rectangleTop, double rectangleLeft, double rectangleWidth, double rectangleHeight, double rectangleAngleInDegrees, double circularRadius)
    {
        double halfRectangleWidth = rectangleWidth / 2;
        double halfRectangleHeight = rectangleHeight / 2;

        // Convert angle to radians
        double rectangleAngleInRadians = rectangleAngleInDegrees * Math.PI / 180.0;

        // Calculate the position of the center of the rectangle
        double rectangleCenterX = rectangleLeft + halfRectangleWidth;
        double rectangleCenterY = rectangleTop + halfRectangleHeight;

        // Calculate the position of the top edge of the rectangle based on the angle
        double rectangleTopEdgeX = rectangleCenterX - halfRectangleHeight * Math.Sin(rectangleAngleInRadians);
        double rectangleTopEdgeY = rectangleCenterY - halfRectangleHeight * Math.Cos(rectangleAngleInRadians);

        // Calculate the distance to the rectangle's left edge from the center
        double distanceToRectangleLeft = Math.Abs(rectangleLeft);

        // Calculate the Y-coordinate of the circular boundary at the point where the rectangle's left edge intersects it
        double circleBoundaryY = -Math.Sqrt(circularRadius * circularRadius - distanceToRectangleLeft * distanceToRectangleLeft);

        // Check if the Y-coordinate of the rectangle's top edge meets or intersects with the circular boundary
        return rectangleTopEdgeY <= circleBoundaryY;
    }
}