Can anyone recommend an efficient port to CSharp of any of the public AABB/triangle intersection algorithms.
I've been looking at Moller's approach, described abstractly here, and if I were to port it, I would probably start from this C++ version. This C++ library by Mike Vandelay seems like it could also be a great starting point.
...or... any other "wheel" that can take a triangle of Vector3's and tell me if it intersects with an AABB), relatively efficiently.
There seem to be a variety of algorithms, but most seem to be written in c++, or just described abstractly in white papers and I need a c# specific implementation for our application. Efficiency is not key, but c# is. (though efficiency is obviously nice too of course ;p )
Any C# options, before I wade through a "math" port ;) would be greatly appreciated! Thanks.
For any two convex meshes, to find whether they intersect, you need to check if there exist a separating plane. If it does, they do not intersect. The plane can be picked from any face of either shape, or the edge cross-products.
The plane is defined as a normal and an offset from Origo. So, you only have to check three faces of the AABB, and one face of the triangle.
A good example is the box (±10, ±10, ±10) and the triangle (12,9,9),(9,12,9),(19,19,20). None of the faces can be used as a separating plane, yet they do not intersect. The separating axis is <1,1,0>, which is obtained from the cross product between <1,0,0> and <-3,3,0>.
I noticed a small bug in this implementation which leads to false negatives. If your triangle has one edge parallel to one axis (for example (1, 0, 0)), then you will have a null vector when computing
This will lead to equality in the test below and give you a false negative.
replace <= and >= by < and > at line
(strict comparers to remove those cases).
Works well except for that!
Thank you