0

Okay, I need help maximizing the area of a rectangle in the sliver object that can be many different shapes. I've already done most of the work.

I'm working in C# with a kinect and the depth pixels.

This image is just the best representation of what I'm talking about that I could find.

enter image description here

I need to produce a rectangle in this area on the x, y plane that maximizes the area while having every edge be solid.

I already have the solid shape represented as a list of points on the x, y plane. So I have the shape on the 2D plane. Kind of like this:

enter image description here

To simplify the problem, I'm just going to produce a rectangle with edges that are parallel to the x and y lines. I'm not looking for code. I just need some direction or an algorithm that I can read up on and attempt to implement.

If any clarification is needed, please let me know.

Jared
  • 25,627
  • 7
  • 56
  • 61
Cheddar
  • 28
  • 5

2 Answers2

0

If you just needs bounding rectangle you can traverse the list of points. Store minimum and maximum of X and Y (like minX, minY, maxX, maxY). Go through the whole list, and do a 4 if check on each of points like:

if(point.X < minX) minX = point.X
if(point.Y < minY) minY = point.Y
if(point.X > maxX) maxX = point.X
if(point.Y > maxY) maxY = point.Y

This will give you the bounding rectangle. Min and Max are two points that represent, depending on your coordinate system, upper left and lower right point, which you can easily use to draw the rectangle.

iamsed
  • 43
  • 1
  • 8
0

Have a look at the Largest Empty Rectangle problem. Here is one article with an algorithm to compute its solutions.

More precisely, it is a problem that consists in searching the largest area that does not contain any point given a set of points. In your case you can apply it to some points that would describe the edge of your 2D shape, plus some points on the outside. Then the procedure of the article would compute the largest rectangle in the yellow area. I did apply such a procedure to find the largest part of an image that does not contain transparent pixels. It worked well but was a bit slow.

The solution applies to a set of points (i.e. no segments) but you can easily compute an approximate solution with an approximation of your shape.

Julien
  • 2,139
  • 1
  • 19
  • 32