如何检查一个盒子是否适合另一个盒子(允许任何旋转) [英] How to check if a box fits into another box (any rotations allowed)

查看:62
本文介绍了如何检查一个盒子是否适合另一个盒子(允许任何旋转)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有两个盒子(每个盒子都是一个矩形长方体又名长方体).我需要编写一个函数来确定尺寸为(a,b,c)的盒子是否可以放入尺寸为(A,B,C)的盒子中,假设允许以任何角度旋转(不仅是90°).

Suppose I have two boxes (each of them is a rectangular cuboid, aka rectangular parallelepiped). I need to write a function that decides if the box with dimensions (a, b, c) can fit into the box with dimensions (A, B, C), assuming any rotations by any angles are allowed (not only by 90°).

棘手的部分是内盒的边缘可能不平行于外盒的相应边缘.例如,尺寸为(a,b)非常薄但长度为 1<&如果√3沿其主对角线放置,则可以放入单位立方(1、1、1)中.

The tricky part is the edges of the inner box may be not parallel to corresponding edges of the outer one. For example, a box that is very thin in the dimensions (a, b) but with length 1 < c < √3 can fit into a unit cube (1, 1, 1) if placed along its main diagonal.

我已经看到了 [1]

I've seen questions [1], [2] but they seem to cover only rotations by 90°.

推荐答案

如果一个盒子可以放在另一个盒子里,或者如果盒子具有相同的中心,那么它也可以适合.因此,仅旋转就足以检查,不需要翻译.

If one box can fit inside the other than it can fit also if boxes have same center. So only rotation is enough to check, translation is not needed to check.

2D情况:对于位于(0,0).这意味着 X 的角是(+-A,+ -B).

2D case: For boxes X=(2A,2B) and x=(2a,2b) positioned around (0,0). That means corners of X are (+-A, +-B).

 ---------(A,B)
            |
 -----------(a,b)
(0,0)         |
 -----------(a,-b)
            |
 ---------(A,-B)

围绕(0,0)旋转 x ,拐角始终位于半径 sqrt(a ^ 2+ b ^ 2).如果圆的一部分位于框 X 内,并且如果圆的一部分位于 X 内,则圆弧长度足以在距离 2a 上放置2个点2b ,则 x 可以容纳在 X 内.为此,我们需要计算 C 与线 x = A y = B 的交点,并计算这些交点之间的距离.如果距离等于或大于 2a 2b ,则 x 可以容纳在 X 中.

Be rotating x around (0,0), corners are always on circle C with radius sqrt(a^2+b^2). If part of circle lie inside box X, and if part inside X has enough arc length to place 2 points on distance 2a or 2b, than x can fit inside X. For that we need to calculate intersection of C with lines x=A and y=B, and calculate distance between these intersection. If distance is equal or grater than 2a or 2b, than x can fit inside X.

3D情况:类似.对于位于(0,0,0)周围的 X =(2A,2B,2C) x =(2a,2b,2c)的盒子>.围绕(0,0,0)旋转 x ,所有角在半径为 sqrt(a ^ 2 + b ^ 2 + c ^ 2).要查看球盒相交部分上是否有足够的空间,请找到球与平面的交点 x = A y = B z = C ,并检查是否有足够的空间适合四边形(2a,2b)(2a,2c)(2b,2c)在那个球体部分上.检查零件边界上的点是否有足够的距离就足够了.对于这一部分,我不确定有效的方法,也许找到相交部分的中心"并检查其与边界的距离会有所帮助.

3D case: Similar. For boxes X=(2A,2B,2C) and x=(2a,2b,2c) positioned around (0,0,0). Rotating x around (0,0,0), all corners move on sphere with radius sqrt(a^2+b^2+c^2). To see is there enough space on sphere-box intersection part, find intersection of sphere with planes x=A, y=B and z=C, and check is there enough space to fit any of quads (2a,2b), (2a,2c) or (2b,2c) on that sphere part. It is enough to check are points on part border on sufficient distance. For this part I'm not sure about efficient approach, maybe finding 'center' of intersection part and checking it's distance to border can help.

这篇关于如何检查一个盒子是否适合另一个盒子(允许任何旋转)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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