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 ; Point A ; Point B ; Point C ; Point D
function checkIntersection ( p1 , p2 , p ) { let val ; if ( p1 [ 1 ] == p2 [ 1 ] && p1 [ 1 ] == p [ 1 ] ) { if ( p [ 0 ] <= Math . max ( p1 [ 0 ] , p2 [ 0 ] ) && ( p [ 0 ] >= Math . min ( p1 [ 0 ] , p2 [ 0 ] ) ) ) return 1 ; } if ( p1 [ 0 ] == p2 [ 0 ] && p1 [ 0 ] == p [ 0 ] ) { if ( p [ 1 ] <= Math . max ( p1 [ 1 ] , p2 [ 1 ] ) && ( p [ 1 ] >= Math . min ( p1 [ 1 ] , p2 [ 1 ] ) ) ) return 1 ; } else { val = ( p [ 1 ] - p1 [ 1 ] ) * ( p2 [ 0 ] - p1 [ 0 ] ) - ( p [ 0 ] - p1 [ 0 ] ) * ( p2 [ 1 ] - p1 [ 1 ] ) ; if ( val == 0 ) if ( ( p [ 0 ] <= Math . max ( p1 [ 0 ] , p2 [ 0 ] ) && ( p [ 0 ] >= Math . min ( p1 [ 0 ] , p2 [ 0 ] ) ) ) && ( p [ 1 ] <= Math . max ( p1 [ 1 ] , p2 [ 1 ] ) && ( p [ 1 ] >= Math . min ( p1 [ 1 ] , p2 [ 1 ] ) ) ) ) return 1 ; } return 0 ; } function towerOfSight ( a , b , c , d ) { let flag = 0 ; if ( checkIntersection ( a , c , b ) == 1 ) flag = 1 ; else if ( checkIntersection ( a , c , d ) == 1 ) flag = 1 ; else if ( checkIntersection ( b , d , a ) == 1 ) flag = 1 ; else if ( checkIntersection ( b , d , c ) == 1 ) flag = 1 ; document . write ( flag == 1 ? " " : " " ) ; } let a = [ 0 , 0 ] ; let b = [ 0 , - 2 ] ; let c = [ 2 , 0 ] ; let d = [ 0 , 2 ] ; towerOfSight ( a , b , c , d ) ;