A little math optimisation here. I need your help since college is so far away... I'm trying to find something really specific. Lets be as precise as possible.
Let R be a bounding rectangle, of any size and aspect ratio (if necessary, lets assume aspect ratio will not exceed 2/1 and 1/2).
Let C be a circle, whose center is inside R, and one point at least is inside R. Some points however might be out of R.
Let r be an arbitrary aspect ratio, possibly different from R aspect ratio.
Is there a known algorithm to size and position a rectangle R' with aspect ratio r, that is fully intersecting R, so that R' n C is maximal (n for intersect, don't know how to input MathML here).
I tend to think a perfect solution might not exist in polynomial time, so good approximates will do the job, even iterative solutions that can be stopped after a timeout.
I expect R and R' to be non rotated, i.e. their sides are either parallel to unit vector or perpendicular to it. But a solution where two sides of R are parallel to two sides of R', and both are rotated arbitrarily will fit perfectly, I would be in a specific case then.
Thanks you much,
Mathieu
Some observations that may be helpful:
1) As Henry said in the comments "you get an optimum if R'
is as big as possible, so it will either have the same height or the same width as R
. This will just leave one parameter (one dimensional position) to optimize."
2) Now you have rectangle R'
than can be slid along the height of R
or along the width of R
. I believe you will find that if you move R'
such that its center is as close to the center of the circle as possible that it will cover the most area.
3) Is the ratio r
always width/height for example, or can it also be height/width? In other words, can R'
be rotated to better fit within R
? If so, you will have to consider two answers if r != 1
. To compare, you will need to compute the area of the intersection of R'
and your circle. This is probably the hardest part of the problem. Are you give the radius of the circle, or do you just know that some part of the edge intersects R
?
4) If R
is not parallel and perpendicular to the axes, you can apply a translation to bring the center of the circle to the origin (0, 0)
, and then a rotation to make R
be aligned to the axes. Then solve to find the coordinates of the corners of R'
, and then apply the reverse rotation, and reverse translation to the coordinates of the corners of R'
to find the final solution.