## Diagonal Placement of boxes

## Diagonal Placement of boxes

(OP)

I am working on a problem related to fitting a rectangular box diagonally inside another, larger, rectangular box. Please see diagram here.

I have searched the web for similar problems/solutions, but have only found notes indicating that the solution will be based on a quartic equation which will be difficult to solve.

But I am hopeful that there might be some simple approximation that might yield reasonable results.

Any suggestions or insights on how to solve this problem would be much appreciated.

I have searched the web for similar problems/solutions, but have only found notes indicating that the solution will be based on a quartic equation which will be difficult to solve.

But I am hopeful that there might be some simple approximation that might yield reasonable results.

Any suggestions or insights on how to solve this problem would be much appreciated.

Code what you mean,

and mean what you code!

But by all means post your code!

Razalas

## RE: Diagonal Placement of boxes

I don't understand your question and there is no diagram at that link.

mmerlinn

http://mmerlinn.com

"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Steven Raymond

## RE: Diagonal Placement of boxes

One more known would be that the MAX L value would be...

MAX L: < (P

^{2}+ Q^{2})^{.5}Skip,

_{Just traded in my old subtlety...for a NUANCE!}## RE: Diagonal Placement of boxes

my apologies for the difficulty in reaching the diagram.

When you click that link, under the section called "Stuff", there is a button, labelled "Diagonal Placement", which opens a pdf file containing the diagram.

Code what you mean,

and mean what you code!

But by all means post your code!

Razalas

## RE: Diagonal Placement of boxes

Nothing happens when I click that link.

mmerlinn

http://mmerlinn.com

"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Steven Raymond

## RE: Diagonal Placement of boxes

I clicked the link and got the .pdf file.

Skip,

_{Just traded in my old subtlety...for a NUANCE!}## RE: Diagonal Placement of boxes

You have 4 unknowns (a, b, c, d) and only 3 equations defining.

The FOURTH might be...

P * Q = a * b + c * d + L * W

Skip,

_{Just traded in my old subtlety...for a NUANCE!}## RE: Diagonal Placement of boxes

if you hate geometry and don't like solving things precisely, you can relatively easily turn this into a binary search. For example: consider the bottom edge of the smaller box (as a line). Assuming it's an interesting length, it can be placed leftmost with its left end in the bottom left corner of the big box, and then it can be pushed rightwards until its right end hits the top right corner of the big box.

In any position, we can extend the small box's sides at rightangles upwards until either the left edge hits the left side of the big box, or until the right edge hits the top of the big box. Obviously in the leftmost position, it's the left edge that rules (giving width zero) and in the rightmost, it's the right edge that rules (also giving width zero).

Somewhere between the two, there's a position where both edges touch simultaneously, and this is the best-fit widest box (I think, I'm right aren't I??).

If all this is true, then you could, inefficiently, solve this just by doing a binary search where you look to see if a new position of the bottom edge is a left or right cut-off, and then search whichever side of the new position you need. Eventually either the length of the left side of the small box will become indistinguishable from the length of the right, or the change in position will become too tiny to see. This should correspond to the best width.

But this would be a strange and contorted way to do things, I think.