As you might know there's a really awesome algorithm for finding the largest area rectangle that lies inside a given polygon in the D3plus library.
If I use this algorithm with EPSG:4326 (WGS84) coordinates the result looks pretty reasonable as you can see in the following image:
My problem is that I have to work with the swiss CRS which is EPSG:2056 (LV95). If I use the same algorithm but with swiss coordinates the following happens:
You might think to solve this problem I could just convert the coordinates between the CRS. But this doesn't work because of the distortions:
I've created an example where the problem is shown: https://stackblitz.com/edit/largest-rectangle
Does somebody know why it doesn't work with swiss coordinates? Or even better, has a solution that works?
- D3plus source: https://github.com/d3plus/d3plus
- Documentation of the algorithm: https://github.com/d3plus/d3plus-shape#largestRect
- Blog post that describes the algorithm: https://web.archive.org/web/20210506163248/https://d3plus.org/blog/behind-the-scenes/2014/07/08/largest-rect/