Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Diagonal Placement of boxes

Status
Not open for further replies.

razalas

Programmer
Apr 23, 2002
237
US
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.

Code what you mean,
and mean what you code!
But by all means post your code!

Razalas
 
[ ]

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

mmerlinn


"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
 

One more known would be that the MAX L value would be...
[tt]
MAX L: < (P[sup]2[/sup] + Q[sup]2[/sup])[sup].5[/sup]
[/tt]


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Mmerlin,

my apologies for the difficulty in reaching the diagram.[purpleface]

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
 
[&nbsp;]
Nothing happens when I click that link.

mmerlinn


"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
 


I clicked the link and got the .pdf file.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 



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

The FOURTH might be...
[tt]

[/tt]
P * Q = a * b + c * d + L * W

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
never trust a Friday afternoon suggestion based on 30 sec thought, but:

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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top