Check if any pair of semicircles intersect or not | Function to check if any pairs of the semicircles intersects or not ; Stores the coordinates of all the semicircles ; x and y are coordinates ; Store the minimum and maximum value of the pair ; Push the pair in vector ; Compare one pair with other pairs ; Generating the second pair ; Extract all the second pairs one by one ; 1 st condition ; 2 nd condition ; If any one condition is true ; If any pair of semicircles doesn 't exists ; Driver Code
def checkIntersection ( arr , N ) : NEW_LINE INDENT vec = [ ] NEW_LINE for i in range ( N - 1 ) : NEW_LINE INDENT x = arr [ i ] NEW_LINE y = arr [ i + 1 ] NEW_LINE minn = min ( x , y ) NEW_LINE maxx = max ( x , y ) NEW_LINE vec . append ( [ minn , maxx ] ) NEW_LINE DEDENT for i in range ( len ( vec ) ) : NEW_LINE INDENT x = vec [ i ] NEW_LINE for j in range ( len ( vec ) ) : NEW_LINE INDENT y = vec [ j ] NEW_LINE cond1 = ( x [ 0 ] < y [ 0 ] and x [ 1 ] < y [ 1 ] and y [ 0 ] < x [ 1 ] ) NEW_LINE cond2 = ( y [ 0 ] < x [ 0 ] and y [ 1 ] < x [ 1 ] and x [ 0 ] < y [ 1 ] ) NEW_LINE if ( cond1 or cond2 ) : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT DEDENT return False NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 0 , 15 , 5 , 10 ] NEW_LINE N = len ( arr ) NEW_LINE if ( checkIntersection ( arr , N ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT