def orientation(p, q, r):
    """
    Returns the orientation of the ordered triplet (p, q, r).
    The function returns the following values:
    0 --> p, q, r, are colinear
    1 --> Clockwise
    2 --> Counterclockwise
    """
    # Taken from:
    # http://www.geeksforgeeks.org/check-if-two-given-line-segments-intersect/
    val = ((q.y - p.y) * (r.x - q.x)) - ((q.x - p.x) * (r.y - q.y))

    if val == 0:
        # (p, q, r) is colinear
        return 0
    elif val > 0:
        # (p, q, r) is clockwise
        return 1
    else:
        # (p, q, r) is counterclockwise
        return 2