How to skew a box to fit inside another under certain conditions

91 Views Asked by At

I guess my question is either fairly simple or impossible to solve.

I have two boxes. One (I'll call child box) inside another (I'll call parent box). The parent box has width x and height y. The child box has height y, but its width is unknown.

For the past 7 hours I have been trying to create a formula that will give me the width of the child box when it has been skewed under certain conditions:

  • Its lower left corner has to stay in the lower left corner
  • After the skewing, its upper right corner has to touch the upper right corner of the parent box
  • I have to be in control over the child box's width, when looking at it as if you rotated it, instead of skewing it

I have made an image to try and clear things up

enter image description here

In this example, the child box has a width of 1, when looking at it with the same angle as we skewed it.

So the formula I'm looking for, is one where I can get the distance of the part marked with a question mark, given only x, y and 1.

I have been looking into a whole lot of Cos Sin Tan, as well as Sec, Csc and Cot, but haven't gotten anywhere with these.

Also, if you see things that could be changed to make this question more clear for others, don't hesitate to do so. I don't know math syntax

1

There are 1 best solutions below

5
On BEST ANSWER

Let's let the parent box have dimension $x, y$. Let's let the child box have horizontal width $w$ (That you're trying to find a formula for) and cross-sectional width $λ$. In your case you let $λ = 1$, but I think we can be a bit more general here. Let's also say there's an angle $θ$ on the right side of $w$ that the child box is skewed. I don't want to relate $w$ to θ, but I will use it as an intermediate variable.

From the large triangle we can find that $\sinθ = \frac{y}{\sqrt{y^2 + (x - w)^2}}$.

If we bring the bar defining $λ$ as far down as possible, we can see it makes another triangle in the child box. Using this triangle, we can show that $\sinθ = \frac{λ}{w}$ So:

$$\frac{y}{\sqrt{y^2 + (x - w)^2}} = \frac{λ}{w}$$

Cleaning that up as a quadratic for w:

$$(y^2 - λ^2)w^2 + 2λ^2xw - (λ^2x^2 + λ^2y^2) = 0$$

And using the quadratic formula to solve:

$$w = \frac{yλ\sqrt{x^2 + y^2 - λ^2} - xλ^2}{y^2 - λ^2}$$

EDIT: I derped. Hopefully it's fixed now.