title: how can I find a shortest line (2 end points will be fine) from a group of points which is intersect with another given line segment
body: <p><img src="https://i.stack.imgur.com/z7IRC.png" alt="Picture" /></p>
  <p>Say I got a bunch of points(red points) and a blue <strong>line segment</strong>, i want to find a line(2 points) which is intersect with the blue <strong>line segment</strong> and the sum of two end points' perpendicular distance to the blue <strong>line segment</strong> is the shortest distance .</p>
  <p>P in this picture above is CD and the blue <strong>line segment</strong> intersect point.</p>
  <p>I only know that they should be on the blue line's different side (left/right or above/below).</p>
  <p>But there are still serveral variants can make this go south.Like AB and CE in this picture.</p>
  <p>Edit : At first i thought i only need to make sure both of two end points' projection point lies on the blue <strong>line segment</strong>.But if I do so,there might be not so many good points for this case.I might just throw the only solution away.</p>
  <p>Edit2 : The background is about image processing.Find 2 reliable points (say line <strong>M</strong>) near given line segment say <strong>L</strong>,if they intersect with each other then in another image they still does.It's about find line <strong>L</strong>'s candidates in another image.</p>
  <p>Edit3 :
  Some python codes,but it's just my first thought.</p>
  <p>It's not finished so it's not tested yet.</p>
  <pre class="lang-py prettyprint-override"><code>class Point:
      def __init__(self):
          self.point = (0, 0)
          self.dist = float(Inf)
  
      def update(self, point, dist):
          self.point = point
          self.dist = dist
  
  
      for l0 in lines0:
          # contains shortest perpendicular distance point on each side
          temp = [Point(), Point()]
          for p0 in points0:
              x1, y1, x2, y2 = l[0]
              # define given line L
              line = lsrl.Line(lsrl.Point(x1, y1),
                               lsrl.Point(x2, y2))
  
              # define point from points
              point = lsrl.Point(p0[0], p0[1])
  
              # perpendicular distance
              dist = lsrl.distToLine(line, point)
  
              # which side on return 0,1,2
              side = lsrl.determineSide(line, point)
              # lies on the given line
              if side == 2:
                  pass
              if dist &lt; temp[side].dist:
                  # meet a better point then update
                  temp[side].update(p0, dist)
  
  </code></pre>