Determine if two meshes intersect in any way

I’m wondering if there is a simple way to determine if two meshes intersect in any way?

Not just a vertex, but all parts of the mesh.

Thanks

Simple way? Probably not.

I’m guessing the only way for a 100% accurate intersection test between two meshes (assuming no pre-processing/pre-setup is done) is to go through them both on a polygon-by-polygon basis (e.g. triangle-by-triangle) and do the intersection tests that way. Depending on how complex your models are this could be computationally costly.

If there is indeed a simple way I’d be interested in hearing it :eyebrowlift2:

I think, one should investigate how the boolean modifier ‘intersect’ works ???
But this is probably too much, because you need to know only ONE intersection of, yes what:
vertex vertex? two faces? two edges, other possibilities???

I’m not sure what the best approach is.
Check to see if any face intersects any other face.
Would that be enough?
If so, how to do?

Thanks

A quick way would be to compare bounding boxes first. If you get an intersection on the bounding box. Create a new box from the two intersections. Then create a list of vertices from each mesh that resides in the new box. At that point you would be at the standard grunt compare level. But by culling out faces using the bounding box first may offer some speed up.

Is this just an esoteric exercise in coding or do you have a specific scene in mind that your are trying to solve? The BGE physics system can already detect mesh level collision. If you are trying to meet a scene requirement perhaps there is another approach without coding that can get you there.

Nothing esoteric here Atom, although sometimes, I just like to solve problems for the sake of solving them.

I’m putting the finishing touches on an addon, and I’m trying to understand what is possible.

Testing for vertices in a mesh doesn’t always work.
In the picture below, the two cubes are intersecting, but neither of them has any vertices in the other cube.


Hi terrachild,

This is another function which exists in the Blender source code (in C) but hasn’t been exposed to Python. I’m working on implementing it now since it seems easier than the other ones we’ve been doing.

Cheers,
Truman

@terrachild: Yeah, but you do have an intersection because the first test was met. The bounding boxes.

Colliding spheres should be quicker as a test.

This relies upon face-vertex and edge-edge functions.

I read: convex objects … that is easier, surely …

If I get your meaning… Absolutely, I was doing this for concave shapes the other week and I found that it was best to convert them into sets of convex shapes before running my checks.

Later I may go into the Blender source and try to find how it does it’s triangle mesh and convex hull collision detection calculations with other objects (I may need a week or two to fully get to grips with it though!!!)

@terrachild: Yeah, but you do have an intersection because the first test was met. The bounding boxes.

Yes, but this is a best case scenario. It’s a cube!
Bounding boxes don’t hug the contours of more complex meshes.
I was hoping for something more accurate.

Not yet, I’ll give it a whirl and see what happens.
Thanks.

If this is about cubes… Then I remember reading something in a programming gems years ago about aligning the boxes to each other… right now can’t think how it worked?