检测是否可以将一个rect放入另一个rect [英] Detect if one rect can be put into another rect

查看:146
本文介绍了检测是否可以将一个rect放入另一个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?

推荐答案

这是一个很好的问题!当且仅当满足这些条件的一个时,带有边pq(p >= q)的较小矩形才能完全适合具有边的较大矩形ab(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):

请参见以供参考

因此,如果我们有变量abpq,我们可以通过评估来检查是否可以进行这种矩形排列:

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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆