Direction of a Point from a Line Segment | Structure for point in cartesian plane . ; Constant integers for directions ; Subtracting co - ordinates of point A from B and P , to make A as origin ; Determining cross Product ; Return RIGHT if cross product is positive ; Return LEFT if cross product is negative ; Return ZERO if cross product is zero ; Driver code ; A . y = 10 A ( - 30 , 10 ) ; B . y = - 15 B ( 29 , - 15 ) ; P . y = 28 P ( 15 , 28 )
class point : NEW_LINE INDENT def __init__ ( self ) : NEW_LINE INDENT self . x = 0 NEW_LINE self . y = 0 NEW_LINE DEDENT DEDENT RIGHT = 1 NEW_LINE LEFT = - 1 NEW_LINE ZERO = 0 NEW_LINE def directionOfPoint ( A , B , P ) : NEW_LINE INDENT global RIGHT , LEFT , ZERO NEW_LINE B . x -= A . x NEW_LINE B . y -= A . y NEW_LINE P . x -= A . x NEW_LINE P . y -= A . y NEW_LINE cross_product = B . x * P . y - B . y * P . x NEW_LINE if ( cross_product > 0 ) : NEW_LINE INDENT return RIGHT NEW_LINE DEDENT if ( cross_product < 0 ) : NEW_LINE INDENT return LEFT NEW_LINE DEDENT return ZERO NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT A = point ( ) NEW_LINE B = point ( ) NEW_LINE P = point ( ) NEW_LINE A . x = - 30 NEW_LINE B . x = 29 NEW_LINE P . x = 15 NEW_LINE direction = directionOfPoint ( A , B , P ) NEW_LINE if ( direction == 1 ) : NEW_LINE INDENT print ( " Right ▁ Direction " ) NEW_LINE DEDENT elif ( direction == - 1 ) : NEW_LINE INDENT print ( " Left ▁ Direction " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Point ▁ is ▁ on ▁ the ▁ Line " ) NEW_LINE DEDENT DEDENT