Check if the tower of sight issue occurs or not | Function to check if point p lies in between the line joining p1 and p2 ; If parallel to X - axis ; Point p lies between p1 and p2 ; If parallel to Y - axis ; Point p lies between p1 and p2 ; If point p satisfies the equation of line joining p1 and p2 ; Function to check if tower of sight issue occurred ; B lies between AC ; D lies between AC ; A lies between BD ; C lies between BD ; Driver code ; Point A ; Point B ; Point C ; Point D
def checkIntersection ( p1 , p2 , p ) : NEW_LINE INDENT if ( p1 [ 1 ] == p2 [ 1 ] and p1 [ 1 ] == p [ 1 ] ) : NEW_LINE INDENT if ( p [ 0 ] <= max ( p1 [ 0 ] , p2 [ 0 ] ) and ( p [ 0 ] >= min ( p1 [ 0 ] , p2 [ 0 ] ) ) ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT DEDENT if ( p1 [ 0 ] == p2 [ 0 ] and p1 [ 0 ] == p [ 0 ] ) : NEW_LINE INDENT if ( p [ 1 ] <= max ( p1 [ 1 ] , p2 [ 1 ] ) and ( p [ 1 ] >= min ( p1 [ 1 ] , p2 [ 1 ] ) ) ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT val = ( ( p [ 1 ] - p1 [ 1 ] ) * ( p2 [ 0 ] - p1 [ 0 ] ) - ( p [ 0 ] - p1 [ 0 ] ) * ( p2 [ 1 ] - p1 [ 1 ] ) ) NEW_LINE if ( val == 0 ) : NEW_LINE INDENT if ( ( p [ 0 ] <= max ( p1 [ 0 ] , p2 [ 0 ] ) and ( p [ 0 ] >= min ( p1 [ 0 ] , p2 [ 0 ] ) ) ) and ( p [ 1 ] <= max ( p1 [ 1 ] , p2 [ 1 ] ) and ( p [ 1 ] >= min ( p1 [ 1 ] , p2 [ 1 ] ) ) ) ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT DEDENT DEDENT return 0 NEW_LINE DEDENT def towerOfSight ( a , b , c , d ) : NEW_LINE INDENT flag = 0 NEW_LINE if ( checkIntersection ( a , c , b ) ) : NEW_LINE INDENT flag = 1 NEW_LINE DEDENT elif ( checkIntersection ( a , c , d ) ) : NEW_LINE INDENT flag = 1 NEW_LINE DEDENT elif ( checkIntersection ( b , d , a ) ) : NEW_LINE INDENT flag = 1 NEW_LINE DEDENT elif ( checkIntersection ( b , d , c ) ) : NEW_LINE INDENT flag = 1 NEW_LINE DEDENT if ( flag ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT a = [ 0 , 0 ] NEW_LINE b = [ 0 , - 2 ] NEW_LINE c = [ 2 , 0 ] NEW_LINE d = [ 0 , 2 ] NEW_LINE towerOfSight ( a , b , c , d ) NEW_LINE DEDENT