title: Merge 2d line segments
body: <p>I am looking for a way to join together 2D line segments. A line segment is made of up two vector points, the start of the line segment and the end point of the line segment. </p>
  
  <p>I want to join line segments that look like they should form the same straight line, I don't want to join the line segments if they are of completely different orientations but happen to have 2 points close to each other. The system I am going to use this in is a computer vision system so the line segments obtained are not going to be perfect i.e. the orientations might be slightly off, the segments might not be full length e.t.c.</p>
  
  <p>I think the following 3 examples cover the sort of line segments I want to join together:</p>
  
  <p><img src="https://i.stack.imgur.com/CTAZw.png" alt="Example"></p>
  
  <p>Thanks</p>