#
# Python program demonstration the
#  turning-direction computation
#

def turningDirection( pt1, pt2, pt3 ):
    """ returns  1 if pt1 -> pt2 -> pt3 is a turn
        returns -1 if pt1 -> pt2 -> pt3 is a turn
        returns  0 if they are collinear
    """
    x1, y1 = pt1;  x2, y2 = pt2;  x3, y3 = pt3;
    # the signed magnitude of the cross product
    CP = (x2-x1)*(y3-y1)-(y2-y1)*(x3-x1) 
    if CP > 0: return  1
    if CP < 0: return -1
    return 0


if __name__ == "__main__":

    pt1  = (10,10)
    pt2  = (20,20)
    pt3  = (15,30)
    pt3p = (40,20)
    ptpr = (30,30)

    print "turningDirection( pt1, pt2, pt3 ) is", turningDirection( pt1, pt2, pt3 )
    print "turningDirection( pt1, pt2, pt3p) is", turningDirection( pt1, pt2, pt3p)
    print "turningDirection( pt1, pt2, ptpr) is", turningDirection( pt1, pt2, ptpr)