title: How to extend a line segment in Python?
body: <p>I have a line segment defined as its starting and ending points.</p>
  
  <pre><code>L = [(x1, y1), (x2, y2)] 
  </code></pre>
  
  <p>So</p>
  
  <pre><code>               (x1, y1)                       (x2, y2)
  L:                A-------------------------------B
  </code></pre>
  
  <p>I now wish to <strong>extend the line</strong> by pulling apart these two points like so</p>
  
  <pre><code>              a                                         a
  L:      A'--------A-------------------------------B-----------B'
  </code></pre>
  
  <p>So I need to update the coordinates of point <code>A</code> and <code>B</code>.</p>
  
  <p>Suppose <code>A'A = B'B = a</code></p>
  
  <p>How to do it in Python?</p>
  
  <p><a href="https://stackoverflow.com/questions/19310735/extending-a-line-segment-in-matplotlib">This question</a> may be quite related, but mine mainly focuses on the algorithm that does the task, instead of visualizing it in the figure.</p>