Question

This is a follow-up of a previous question of mine that was resolved.

I'm trying to develop a mesh collision method in order to penalize inter-penetrations. For this reason I started working with CGAL, and I have a working first attempt by closely following this example ("Example for Finding Intersecting 3D Triangles").

However it seems that it detects all adjacent triangles cases as collisions (and now it seems pretty obvious that the method would do this).

Is there any way to detect actual collisions of non-neighboring triangles only? Ideally the collision detection method should take care of this before creating the output, avoiding thus the need to filter-out the final vector of colliding triangles and the computational burden that comes with this.

The structure of my triangles is a triangle-soup, ie. stored in a vector with no specific ordering.

Was it helpful?

Solution

The solution I found was the following (though not sure if this is the optimal one):

In the callback function of the collision check

  • First read the IDs of the triangles

id1 = a.handle() - coll_Triangles.begin();

id2 = b.handle() - coll_Triangles.begin();

  • Check if triangles are degenerate (if true, return)

a.handle()->is_degenerate()

  • Check the vertices-ID of the triangles. If they share a vertex-ID, return

this is obvious, not pseudocode here :)

  • Only if the above hold true, do the actual intersection test between triangles

CGAL::do_intersect( *(a.handle()), *(b.handle())

  • If the last command returns true, then you have two non-adjacent triangles colliding. Congratulations :)

The do_intersect has to happen as the last step, after all other tests, otherwise the computational load is quite big and in vain.

Another possible speedup is to use half-open instead of closed boxes. I found that during greedy checks between all triangle pairs this leads to a speedup (~50%), but I assume that this could lead to missing some collisions (e.g. in the case of touch).

CGAL::Box_intersection_d::HALF_OPEN
CGAL::Box_intersection_d::CLOSED
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top