Calculate the distance from p3 to the stroke defined by p1 and p2.
    The distance is the length of the perpendicular from p3 on p1.

    Parameters
    ----------
    p1 : dictionary with "x" and "y"
        start of stroke
    p2 : dictionary with "x" and "y"
        end of stroke
    p3 : dictionary with "x" and "y"
        point

def perpendicular_distance(p3, p1, p2):
    """
    Calculate the distance from p3 to the stroke defined by p1 and p2.
    The distance is the length of the perpendicular from p3 on p1.

    Parameters
    ----------
    p1 : dictionary with "x" and "y"
        start of stroke
    p2 : dictionary with "x" and "y"
        end of stroke
    p3 : dictionary with "x" and "y"
        point
    """
    px = p2['x']-p1['x']
    py = p2['y']-p1['y']

    squared_distance = px*px + py*py
    if squared_distance == 0:
        # The line is in fact only a single dot.
        # In this case the distance of two points has to be
        # calculated
        line_point = Point(p1['x'], p1['y'])
        point = Point(p3['x'], p3['y'])
        return line_point.dist_to(point)

    u = ((p3['x'] - p1['x'])*px + (p3['y'] - p1['y'])*py) / squared_distance

    if u > 1:
        u = 1
    elif u < 0:
        u = 0

    x = p1['x'] + u * px
    y = p1['y'] + u * py

    dx = x - p3['x']
    dy = y - p3['y']

    # Note: If the actual distance does not matter,
    # if you only want to compare what this function
    # returns to other results of this function, you
    # can just return the squared distance instead
    # (i.e. remove the sqrt) to gain a little performance

    dist = math.sqrt(dx*dx + dy*dy)
    return dist