Check if any point overlaps the given Circle and Rectangle | Function to check if any point overlaps the given Circle and Rectangle ; Find the nearest point on the rectangle to the center of the circle ; Find the distance between the nearest point and the center of the circle Distance between 2 points , ( x1 , y1 ) & ( x2 , y2 ) in 2D Euclidean space is ( ( x1 - x2 ) * * 2 + ( y1 - y2 ) * * 2 ) * * 0.5 ; Driver code
def checkOverlap ( R , Xc , Yc , X1 , Y1 , X2 , Y2 ) : NEW_LINE INDENT Xn = max ( X1 , min ( Xc , X2 ) ) NEW_LINE Yn = max ( Y1 , min ( Yc , Y2 ) ) NEW_LINE Dx = Xn - Xc NEW_LINE Dy = Yn - Yc NEW_LINE return ( Dx ** 2 + Dy ** 2 ) <= R ** 2 NEW_LINE DEDENT if ( __name__ == " _ _ main _ _ " ) : NEW_LINE INDENT R = 1 NEW_LINE Xc , Yc = 0 , 0 NEW_LINE X1 , Y1 = 1 , - 1 NEW_LINE X2 , Y2 = 3 , 1 NEW_LINE print ( checkOverlap ( R , Xc , Yc , X1 , Y1 , X2 , Y2 ) ) NEW_LINE DEDENT