检测是否可以将一个rect放入另一个rect [英] Detect if one rect can be put into another rect
问题描述
此问题与测试一个rect是否在另一个rect中不同.
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 put into another rect?
推荐答案
这是一个很好的问题!当且仅当满足这些条件的一个时,带有边p
和q
(p >= q
)的较小矩形才能完全适合具有边的较大矩形a
和b
(a >= b
):
This is a great question! If and only if one of these conditions is satisfied does a smaller rectangle with sides p
and q
(p >= q
) fit completely into a larger rectangle with sides a
and b
(a >= b
):
或
请参见此以供参考
因此,如果我们有变量a
,b
,p
,q
,我们可以通过评估来检查是否可以进行这种矩形排列:
So if we had variables a
, b
, p
, q
, we could check if such a rectangle arrangement would be possible by evaluating:
(p <= a && q <= b) || (p > a &&
b >= (2*p*q*a + (p*p-q*q)*sqrt(p*p+q*q-a*a)) / (p*p+q*q))
编辑:感谢@amulware在他的评论中发布了此备用版本:
Thanks to @amulware for posting this alternate version in his comment:
这篇关于检测是否可以将一个rect放入另一个rect的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!