Intersection

A student asked me yesterday how to intersect two boxes. He wants to do it in 3D, but it occurred to me that if you take the right approach, there might be a “good enough” algorithm that would work equally well in any number of dimensions. Which means I could just give a 2D version as an example, and the student could then easily extend that to 3D.

By “good enough”, I mean it might fail on really difficult cases, like extremely long and skinny boxes, but it would do just fine on the more common kinds of boxes that are roughly equal in size and not extremely distorted in shape.

This is the example I ended up writing this morning and sharing with the student. If you’re a code developer and you’re interested, feel free to view source. The entire algorithm is just a few dozen lines of Javascript code.

Leave a Reply

Your email address will not be published. Required fields are marked *