Algorithm to check if two boxes overlap

后端 未结 2 1684
挽巷
挽巷 2021-01-04 03:07

I have understood the algorithm in case of rectangles but I am confused with the boxes with x, y, z and height as value given. The conditions for not overlapping are 1) Box

2条回答
  •  花落未央
    2021-01-04 03:51

    if(xMin1 <= xMax2 || xMax1 >= xMin2)
     
    if(yMin1 <= yMax2 || yMax1 >= yMin2)
    
    if(zMin1 <= zMax2 || zMax1 >= zMin2)
    

    All of these conditions have to be true for the boxes to not be overlapped.

    Also I assumed that the box edges could lay on the same x,y,z co-ordinates.

    If not, just take the equal signs outs.

    if(xMin1 < xMax2 || xMax1 > xMin2)
     
    if(yMin1 < yMax2 || yMax1 > yMin2)
    
    if(zMin1 < zMax2 || zMax1 > zMin2)
    

提交回复
热议问题