0
$\begingroup$

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.

$\endgroup$
  • 2
    $\begingroup$ Try applying the transformations to the mesh with bpy.ops.object.transform_apply(location=False, rotation=True, scale=True). The object should be active. $\endgroup$ – Jaroslav Jerryno Novotny Dec 30 '14 at 10:34
5
$\begingroup$

I implemented a minimum bounding box algorithm as an addon that simply attempts to fit a box from many different directions. It is not exact, however it is robust :-)

https://github.com/patmo141/object_bounding_box

enter image description here

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.