Check if two vectors are collinear or not | Function to calculate cross product of two vectors ; Update cross_P [ 0 ] ; Update cross_P [ 1 ] ; Update cross_P [ 2 ] ; Function to check if two given vectors are collinear or not ; Store the first and second vectors ; Store their cross product ; Calculate their cross product ; Check if their cross product is a NULL Vector or not ; Driver Code ; Given coordinates of the two vectors
def crossProduct ( vect_A , vect_B , cross_P ) : NEW_LINE INDENT cross_P [ 0 ] = ( vect_A [ 1 ] * vect_B [ 2 ] - vect_A [ 2 ] * vect_B [ 1 ] ) NEW_LINE cross_P [ 1 ] = ( vect_A [ 2 ] * vect_B [ 0 ] - vect_A [ 0 ] * vect_B [ 2 ] ) NEW_LINE cross_P [ 2 ] = ( vect_A [ 0 ] * vect_B [ 1 ] - vect_A [ 1 ] * vect_B [ 0 ] ) NEW_LINE DEDENT def checkCollinearity ( x1 , y1 , z1 , x2 , y2 , z2 ) : NEW_LINE INDENT A = [ x1 , y1 , z1 ] NEW_LINE B = [ x2 , y2 , z2 ] NEW_LINE cross_P = [ 0 for i in range ( 3 ) ] NEW_LINE crossProduct ( A , B , cross_P ) NEW_LINE if ( cross_P [ 0 ] == 0 and cross_P [ 1 ] == 0 and cross_P [ 2 ] == 0 ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT x1 = 4 NEW_LINE y1 = 8 NEW_LINE z1 = 12 NEW_LINE x2 = 8 NEW_LINE y2 = 16 NEW_LINE z2 = 24 NEW_LINE checkCollinearity ( x1 , y1 , z1 , x2 , y2 , z2 ) NEW_LINE DEDENT