How to judge whether two meshes intersect?

Hello,I’m sorry to bother you,i have a question:how to judge whether two meshes intersect?
for example:

The box intersects the cylinder。

Is there a simple method or function to determine if two meshes intersect?

thanks for your help!

Suiting your example, I would use

box.intersectsMesh(cylinder, false)

to get true boolean returned.

Docs:

3 Likes

thanks,Is this method suitable for any complex mesh?

If you set precise parameter (second one) to true, so Intersection is determined by OBB which is explained here:

But I doubt this would work for i.e. inside a torus (ring), because the bounding box encompasses the hole of the ring and extends over the roundings. For this you might need an Physics Engine.

Edit: I made an example to showcase the issue inside a torus:

Depending on your scenario, using several rays might also be enough to check the intersections on faces/triangles, but it can turn into a lot of work if you have several forms of meshes. Another idea would be to use the more “performance-heavy” Constructive Solid Geometry:

Or maybe there is a external library that offers triangle intersection.

4 Likes