def distance(mypoint, myline):
    """
    Calculates the distance from a point to a line
    """
    
    x, y = mypoint
    
    A, B, C = myline
    
    return np.abs(A*x + B*y + C) / np.sqrt(np.power(A,2)+np.power(B,2))
    
    

mypoint = (5,1)
myline = (3,-1, 1)
distance(mypoint, myline) # 15/np.sqrt(10) = 4.743416


mypoint = (0.25, 0.50)
myline = (1, -1, 0) # identity line
distance(mypoint, myline)

"""
Explanation: <H2>Distance from a point to a line</H2>

\begin{equation}
\frac{|Ax+By+C|}{\sqrt{A^2+B^2}}. 
\end{equation}
End of explanation
"""


def distance_idline(mypoint):
    """
    Calculates the distance from a point to the identity line
    """
    
    x, y = mypoint
    
    return np.abs(x-y) / np.sqrt(2)

myfoo = (0.5, 0.5)
distance_idline(myfoo) # must be zero

distance_idline(mypoint) # must be 0.1767

mypoint= (0,1)
distance_idline(mypoint) #maximal separation is 1/sqrt(2)

1/np.sqrt(2) # voila!

"""
Explanation: <H2>Distance from a point the identity line</H2>

\begin{equation}
\frac{|x - y|}{\sqrt{2}}. 
\end{equation}
End of explanation
"""


