1

I have a list of points depicting a shape. In C# need to find the Minimum Bounding Rectangle (MBR) for that shape. However, all the solutions I have been able to find result in a MBR that is relative to the x and y axis, not to the shape itself. As an example, (the shape is not fixed, could be anything);

MBR auto-generated

What I would really like is something like this;

MBR manually drawn

Currently I am using the getBoundingRectangle in accord.net. The only thing I can think of would be to try 1->90 degree rotations, until the size of the bounding rectangle was minimized.

EDIT: I have found a good reference for the problem here;

Best fit rectangles

It has the code for the solution in processing.js here (see GenBox);

Solution in processing.js But I would really like a C# solution

CarbonMan
  • 4,350
  • 12
  • 54
  • 75
  • I don't know C# so I can't answer this but a common way is to find the angle of rotation of the shape, undo the rotation so that the shape is horizontal, use the logic to find the MBR with respect to the x and y axis, then redo the rotation on that shape to achieve the final answer. Have a look at this post to determine how to find the angle that a rectangular shape makes if you know the four corners. This is probably adaptable to the shape you have: http://stackoverflow.com/questions/13002979/how-to-calculate-rotation-angle-from-rectangle-points – rayryeng Nov 12 '16 at 04:48
  • 1
    This is a non-trivial topic. I found some algorithms for calculating it here https://www.geometrictools.com/Documentation/MinimumAreaRectangle.pdf – Bradley Uffner Nov 12 '16 at 04:48
  • @rayryeng thanks, though I don't really have 4 corners, even the shape showing is just an example. I'll edit to make that clearer – CarbonMan Nov 12 '16 at 05:18
  • @BradleyUffner Nice link. Thanks for sharing. – rayryeng Nov 12 '16 at 05:43
  • @BradleyUffner good link, at least it might be handy as a reference – CarbonMan Nov 12 '16 at 05:57

0 Answers0