python:关于三维装箱问题的算法研究-4-解决判断两个立方体是否重叠判断

def Projection3D(a,adata,b,bdata):
    """
    判断三面投影是否重叠
    按逻辑,如果两个立方体不重叠,在OXY,OXZ,OYZ上最多允许有一个投影面发生重叠(三维问题转二维)
	"""
    overlap = 0 #计算有几个面重叠
    if b[0]>=a[0]+adata[0] or a[0]>=b[0]+bdata[0] or b[1]>=a[1]+adata[1] or a[1]>=b[1]+bdata[1]:
    	"""
    	按逻辑,如果两个方形不重叠
    	在两个轴方向上,只要有一边超出另一个物体的长度范围即可(二维转一维)
    	下同理
    	"""
        # print("底面不重叠")
        pass
    else:
        # print("底面重叠")
        overlap = overlap +1
    if b[0]>=a[0]+adata[0] or a[0]>=b[0]+bdata[0] or b[2]>=a[2]+adata[2] or a[2]>=b[2]+bdata[2]:
        # print("长侧面不重叠")
        pass
    else:
        # print("长侧面重叠")
        overlap = overlap +1
    if b[1]>=a[1]+adata[1] or a[1]>=b[1]+bdata[1] or b[2]>=a[2]+adata[2] or a[2]>=b[2]+bdata[2]:
        # print("宽侧面不重叠")
        pass
    else:
        # print("宽侧面重叠")
        overlap = overlap +1
    return overlap #如果这个值大于1则判断两个方体重叠

你可能感兴趣的:(算法学习,python,算法)