title: Construct lines from multiple 2D points and measure the distance between those lines
body: <p>Multiple points on a 2D plane are given. They represent a window frame of mostly rectangular form with some possible variations. The points which are part of each side are not guaranteed to form a perfect line. Each side of the window should be measured.</p>
  
  <p>A rotating electronic device attached to a window measures the distance in all directions providing a 360 degree measurements. By using the rotation angle and the distance, a set of points are plotted on a 2D coordinate system. So far so good.</p>
  
  <p><img src="https://i.ibb.co/CsTPsh5/dots.png" alt="Points in a 2D plane"></p>
  
  <p><br/>
  Now comes the harder part. The measured window frame could have some variations. The points should be converted to straight lines and the length of each line should be measured.</p>
  
  <p><img src="https://i.ibb.co/qjDLS3n/1.png" alt="">
  <img src="https://i.ibb.co/pnm8Yzr/2.png" alt=""></p>
  
  <p>I imagine that the following steps are required:</p>
  
  <ol>
  <li>Group the different points into straights lines. This means approximating each line “between” the points that form it.</li>
  <li>Drawing those lines, getting rid of the separate points used to construct the lines. </li>
  <li>Find the points where each two lines intersect.</li>
  <li>Measure the distance between those points. However not all distances between all points are interesting. For example diagonals within a frame are irrelevant.</li>
  </ol>
  
  <p>Any Java libraries dealing with geometry that could solve the problem are acceptable. I will write the solution in Kotlin/Java, but any algorithmic insights or code examples and ideas in any other languages or pseudo code are welcome.</p>
  
  <p>Thank you in advance!
  <hr>
  <strong>New Image</strong>
  <a href="https://i.stack.imgur.com/BQNtC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BQNtC.png" alt="enter image description here"></a></p>