How to find an arbitrarily oriented minimum bounding box in c++

后端 未结 5 734
不知归路
不知归路 2021-02-06 23:58

So let\'s say I have a list of N pairs of positive long coordinates (points).
How do I find the smallest rectangle containing all of them?
The rectangle can also have fl

5条回答
  •  深忆病人
    2021-02-07 00:43

    I don't know if this would be of help to you, but here's my thoughts on how I'd approach the problem.

    You'll need functions to find your "corner-most" points (in your example, the left 2 and right 2 points). Given those 4 points, connect them with lines.

    (Note in your example image, the top point would not be contained by the generated rectangle, so...) You'll then need a function to determine if the rectangle generated contains all given points; if not, extend the endpoints (in this case, the top 2 points of the generated rectangle) by N (which is either a single measure ... say a pixel, or if you're smart, the distance to the point that's out of bounds plus/minus one dependant on the direction) and re-evaluate.

提交回复
热议问题