I am implementing a visibility problem between a point and the sun, which I have described in my previous question. I am using the function mathutils.geometry.intersect_ray_tri() to test if there is an object between the point and the sun. However, these objects that are potential obstructions have many triangles (which are iterated and the function is run for each), so to speed up the computations I need to create a bounding box for each object, and test it first.
I have found some solutions, for instance this one, which involves creating the basic cube at the origin with the edge length of 2, and then translating it, rotating it and rescaling it with the following functions:
bound_box.dimensions = obj.dimensions
bound_box.location = obj.location
bound_box.rotation_euler = obj.rotation_euler
The box perfectly encompasses the object, but the problem is that its dimensions are not native because the cube is deformed into a cuboid to fit the object, so the function mathutils.geometry.intersect_ray_tri() still considers it to be a cube at the origin with the dimensions (2,2,2), and the results are very wrong (or I am doing something wrong in the process).
Other solutions seem to be similar, and the mathutils intersection function doesn't work. Is there a way to create a cuboid that serves as a minimum bounding box, and that it'd work in such analysis?
Perhaps another solution would be to fix the above described distorted cube, so that it works in mathutils.geometry.intersect_ray_tri() but I don't know how to do that.