Check whether it is possible to join two points given on circle such that distance between them is k | Python3 program to implement above approach ; 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 wialways be an integer ; Driver Code
from math import sqrt , ceil , floor NEW_LINE def dis ( x1 , y1 , x2 , y2 ) : NEW_LINE INDENT return sqrt ( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ) NEW_LINE DEDENT def check ( c1 , c2 , k ) : NEW_LINE INDENT min = 0 NEW_LINE max = 0 NEW_LINE de = dis ( c1 [ 0 ] , c1 [ 1 ] , c2 [ 0 ] , c2 [ 1 ] ) NEW_LINE if ( de == 0 ) : NEW_LINE INDENT if ( c1 [ 2 ] == c2 [ 2 ] ) : NEW_LINE INDENT min = 0 NEW_LINE max = 0 NEW_LINE DEDENT else : NEW_LINE INDENT if ( c1 [ 2 ] - c2 [ 2 ] > 0 ) : NEW_LINE INDENT min = c1 [ 2 ] - c2 [ 2 ] NEW_LINE max = min + 2 * c2 [ 2 ] NEW_LINE DEDENT else : NEW_LINE INDENT min = c2 [ 2 ] - c1 [ 2 ] NEW_LINE max = min + 2 * c1 [ 2 ] NEW_LINE DEDENT DEDENT DEDENT elif ( de >= c1 [ 2 ] + c2 [ 2 ] ) : NEW_LINE INDENT min = de - c1 [ 2 ] - c2 [ 2 ] NEW_LINE max = de + c1 [ 2 ] + c2 [ 2 ] NEW_LINE DEDENT elif ( de + c2 [ 2 ] < c1 [ 2 ] ) : NEW_LINE INDENT max = c2 [ 2 ] + c1 [ 2 ] + de NEW_LINE min = c1 [ 2 ] - de - c2 [ 2 ] NEW_LINE DEDENT elif ( de + c1 [ 2 ] < c2 [ 2 ] ) : NEW_LINE INDENT max = c2 [ 2 ] + c1 [ 2 ] + de NEW_LINE min = c2 [ 2 ] - de - c1 [ 2 ] NEW_LINE DEDENT elif ( ( de + c2 [ 2 ] >= c1 [ 2 ] ) or ( de + c1 [ 2 ] >= c2 [ 2 ] ) ) : NEW_LINE INDENT max = c2 [ 2 ] + c1 [ 2 ] + de NEW_LINE min = 0 NEW_LINE DEDENT temin = ceil ( min ) NEW_LINE re = max NEW_LINE if ( k >= temin and k <= re ) : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT circle1 = [ 0 , 0 , 5 ] NEW_LINE circle2 = [ 8 , 3 , 2 ] NEW_LINE k = 3 NEW_LINE if ( check ( circle1 , circle2 , k ) ) : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT