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
function checkOverlap ( R , Xc , Yc , X1 , Y1 , X2 , Y2 ) { let Xn = Math . max ( X1 , Math . min ( Xc , X2 ) ) ; let Yn = Math . max ( Y1 , Math . min ( Yc , Y2 ) ) ; let Dx = Xn - Xc ; let Dy = Yn - Yc ; return ( Dx * Dx + Dy * Dy ) <= R * R ; } let R = 1 ; let Xc = 0 , Yc = 0 ; let X1 = 1 , Y1 = - 1 ; let X2 = 3 , Y2 = 1 ; if ( checkOverlap ( R , Xc , Yc , X1 , Y1 , X2 , Y2 ) ) { document . write ( " " + " " ) ; } else { document . write ( " " ) ; }