Check whether it is possible to join two points given on circle such that distance between them is k | Return distance between the centers ; Distance between centers ; Case 5 ; SubCase 1 ; Subcase 2 ; Case 1 ; Case 3 ; Case 4 ; Case 2 ; Since value of k will always be an integer ; Driver Code
function dis ( x1 , y1 , x2 , y2 ) { return Math . sqrt ( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ) ; } function check ( c1 , c2 , k ) { let min = 0 ; let max = 0 ; let de = dis ( c1 [ 0 ] , c1 [ 1 ] , c2 [ 0 ] , c2 [ 1 ] ) ; if ( de == 0 ) { if ( c1 [ 2 ] == c2 [ 2 ] ) { min = 0 ; max = 0 ; } else if ( c1 [ 2 ] - c2 [ 2 ] > 0 ) { min = c1 [ 2 ] - c2 [ 2 ] ; max = min + 2 * c2 [ 2 ] ; } else { min = c2 [ 2 ] - c1 [ 2 ] ; max = min + 2 * c1 [ 2 ] ; } } else if ( de >= c1 [ 2 ] + c2 [ 2 ] ) { min = de - c1 [ 2 ] - c2 [ 2 ] ; max = de + c1 [ 2 ] + c2 [ 2 ] ; } else if ( de + c2 [ 2 ] < c1 [ 2 ] ) { max = c2 [ 2 ] + c1 [ 2 ] + de ; min = c1 [ 2 ] - de - c2 [ 2 ] ; } else if ( de + c1 [ 2 ] < c2 [ 2 ] ) { max = c2 [ 2 ] + c1 [ 2 ] + de ; min = c2 [ 2 ] - de - c1 [ 2 ] ; } else if ( ( de + c2 [ 2 ] >= c1 [ 2 ] ) || ( de + c1 [ 2 ] >= c2 [ 2 ] ) ) { max = c2 [ 2 ] + c1 [ 2 ] + de ; min = 0 ; } let temin = ( Math . ceil ( min ) ) ; let re = max ; if ( k >= temin && k <= re ) { return true ; } return false ; } let circle1 = [ 0 , 0 , 5 ] ; let circle2 = [ 8 , 3 , 2 ] ; let k = 3 ; if ( check ( circle1 , circle2 , k ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }