I'm trying to determine if two cubes overlap. I've read up on overlapping rectangles, but I'm not sure how to translate it into the third dimension.
My goal is to generate a number of randomly positioned and sized non-overlapping cubes.
These cubes are represented on a x,y,z Cartesian plane.
The accepted answer is wrong and very confusing. Here is what I have come up with.
Determining overlap in the x plane
if (cubeA.maxX > cubeB.minX)
if (cubeA.minX < cubeB.maxX)
Determining overlap in the y plane
if (cubeA.maxY > cubeB.minY)
if (cubeA.minY < cubeB.maxY)
Determining overlap in the z plane
if (cubeA.maxZ > cubeB.minZ)
if (cubeA.minZ < cubeB.maxZ)
if you AND all of these conditions together and the result is true, you know that the cubes intersect at some point.
Credit: https://silentmatt.com/rectangle-intersection/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With