Commit a1e57f44 authored by James Harle's avatar James Harle
Browse files

add in distance function to replace the depreciated mlab ones

......@@ -9,7 +9,7 @@ import numpy as np
from matplotlib.lines import Line2D
from matplotlib.patches import Polygon
from matplotlib.artist import Artist
from matplotlib.mlab import dist_point_to_segment
from pynemo.utils.nemo_bdy_lib import dist_point_to_segment
from matplotlib.widgets import RectangleSelector
......
......@@ -127,4 +127,29 @@ def bdy_transport():
Keyword arguments:
"""
raise NotImplementedError
def dist(self, x, y):
"""
Return the distance between two points.
"""
d = x-y
return np.sqrt(np.dot(d, d))
def dist_point_to_segment(p, s0, s1):
"""
Get the distance of a point to a segment.
*p*, *s0*, *s1* are *xy* sequences
This algorithm from
http://geomalgorithms.com/a02-_lines.html
"""
v = s1 - s0
w = p - s0
c1 = np.dot(w, v)
if c1 <= 0:
return dist(p, s0)
c2 = np.dot(v, v)
if c2 <= c1:
return dist(p, s1)
b = c1 / c2
pb = s0 + b * v
return dist(p, pb)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment