Check whether two straight lines are orthogonal or not | Function to check if two straight lines are orthogonal or not ; Both lines have infinite slope ; Only line 1 has infinite slope ; Only line 2 has infinite slope ; Find slopes of the lines ; Check if their product is - 1 ; Driver code
< ? php function checkOrtho ( $ x1 , $ y1 , $ x2 , $ y2 , $ x3 , $ y3 , $ x4 , $ y4 ) { if ( $ x2 - $ x1 == 0 && $ x4 - $ x3 == 0 ) return false ; else if ( $ x2 - $ x1 == 0 ) { $ m2 = ( int ) ( ( $ y4 - $ y3 ) / ( $ x4 - $ x3 ) ) ; if ( $ m2 == 0 ) return true ; else return false ; } else if ( $ x4 - $ x3 == 0 ) { $ m1 = ( int ) ( ( $ y2 - $ y1 ) / ( $ x2 - $ x1 ) ) ; if ( $ m1 == 0 ) return true ; else return false ; } else { $ m1 = ( int ) ( ( $ y2 - $ y1 ) / ( $ x2 - $ x1 ) ) ; $ m2 = ( int ) ( ( $ y4 - $ y3 ) / ( $ x4 - $ x3 ) ) ; if ( $ m1 * $ m2 == -1 ) return true ; else return false ; } } $ x1 = 0 ; $ y1 = 4 ; $ x2 = 0 ; $ y2 = -9 ; $ x3 = 2 ; $ y3 = 0 ; $ x4 = -1 ; $ y4 = 0 ; if ( checkOrtho ( $ x1 , $ y1 , $ x2 , $ y2 , $ x3 , $ y3 , $ x4 , $ y4 ) ) print ( " Yes " ) ; else print ( " No " ) ; ? >