def is_on(a, b, c):
    """Return true iff point c intersects the line segment from a to b."""
return collinear(a, b, c) and (within(a.x, c.x, b.x) if a.x != b.x else
    within(a.y, c.y, b.y))

def collinear(a, b, c):
    """Return true iff a, b, and c all lie on the same line."""
return (b.x - a.x) * (c.y - a.y) == (c.x - a.x) * (b.y - a.y)

def within(p, q, r):
    """Return true iff q is between p and r (inclusive)."""
return p <= q <= r or r <= q <= p
Как определить, что точка находится между двумя другими точками на отрезке?