Detect if one rect can be put into another rect

后端 未结 4 1633
春和景丽
春和景丽 2021-02-13 06:39

This problem is different from testing if one rect is in another rect.

Known information is the sides length of two rects.

How to calculate if one rect can be pu

4条回答
  •  野性不改
    2021-02-13 07:20

    Well, it looks like A.R.S. solution is true, still I'll try to post my solution, it's harder, but it'll let you to build a concrete embedding of one rectangle into another (if possible).

    Let us suppose that a>b and p > q. Solution is obvious if a > p and b > q. The problem can also be solved if a and b>q. Take a look at the attached photo, in it you'll need only last system of inequalities (if you interested you can look how it was derived)

    All you need is to make sure that last system of inequalities has a solution lying between 0 and 1. To do it you need to solve each inequality as equation (as usual quadratic equation). If there are no solution (that's improbable) the solution of inequality is whole real line. If equation has two (maybe equal) solutions t_1 and t_2 the solution of inequality is segment [-infinity, t_1] united with [t_2, infinity]. After you got solutions of both inequalities you should intersect them. Now we should recollect that t is cos of an angle (between 0 and pi/2), so inequality should have solutions between 0 and 1. In that case second rectangle can be embedded into first one. And if you take e.g. t_1 (smaller root of equations) you can build a concreate embedding of rectangles.

    enter image description here

提交回复
热议问题