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.
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.

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.

I imagine that the following steps are required:
- Group the different points into straights lines. This means approximating each line “between” the points that form it.
- Drawing those lines, getting rid of the separate points used to construct the lines.
- Find the points where each two lines intersect.
- Measure the distance between those points. However not all distances between all points are interesting. For example diagonals within a frame are irrelevant.
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.
Thank you in advance!
New Image