mikedh / trimesh

Python library for loading and using triangular meshes.
https://trimesh.org
MIT License
3.01k stars 582 forks source link

What exactly is OBB transfrom #471

Closed hongtaowu67 closed 5 years ago

hongtaowu67 commented 5 years ago

Hi there,

I am wondering which oriented bounding box does the apply_obb function work on? From https://en.wikipedia.org/wiki/Minimum_bounding_box, there are two kinds of oriented bounding boxes, i.e., "Arbitrarily oriented minimum bounding box" and the "Object-oriented minimum bounding box"? Is it one of the two oriented bounding box as pointed out in the link or something else?

Personally, I think it is the "Arbitrarily oriented minimum bounding box" which takes the minimum bounding rectangle of the object and has nothing to do with any frame/axis.

Thanks!

mikedh commented 5 years ago

Hey, you can check out what it's doing internally in trimesh.bounds. Long story short: the OBB is a rectangular solid with one face coincident to the convex hull, so we basically check every face on the hull within a tolerance. It will be arbitrarily oriented, as the sides may be +/- 180 degrees.

hongtaowu67 commented 5 years ago

Thanks! I am trying to understand the trimesh.bounds with your answer. From my understanding, the OBB is trying to find a face on the convex hull and use it as one of the OBB rectangle surfaces. You were saying that the face on the convex hull is checked within a tolerance. I am not sure what does it mean. Could you kindly provide more insight?

mikedh commented 5 years ago

So if the convex hull has a lot of faces (i.e. a smoothly curved convex surface, like a sphere) we speed it up by combining vectors within an angle tolerance (i.e. less than 1 degree). If we didn't do that, the computation can be arbitrarily slow on things like extremely finely tessellated spheres.

hongtaowu67 commented 5 years ago

I see. Thank you! But how do you choose which face of the convex hull to be the one which coincident to the OBB rectangle solid?

mikedh commented 5 years ago

For each face it calculates the minimum area 2D OBB for the projected vertices, which is then turned in to a volume. After calculating the OBB volume for every candidate face on the hull, it takes uses the one with the minimum volume.

hongtaowu67 commented 5 years ago

Thanks! That is crystal clear.

hongtaowu67 commented 5 years ago

Hi there, I am wondering if there is any academic citation I can use to cite this OBB algorithm?

Thanks.

mikedh commented 5 years ago

I couldn't find a quote that said exactly "one face of the minimum volume oriented bounding box of a triangular mesh is guaranteed to be coincident with one face of the convex hull of that mesh," but it seemed pretty heavily implied in this paper: https://pdfs.semanticscholar.org/a76f/7da5f8bae7b1fb4e85a65bd3812920c6d142.pdf

HerveGlz commented 4 years ago

Hi there, Thanks a lot Mikedh for this very informative explanation ! Now I get a better understanding of how your OBB computational algorithm works.

May I ask you why did you decide to select this method instead of a Principal Component Analysis related one ? You can find a bit more information here if ou want : http://codextechnicanum.blogspot.com/2015/04/find-minimum-oriented-bounding-box-of.html http://jamesgregson.blogspot.com/2011/03/latex-test.html

I am asking you this question since in term of computational performances and result accuracy, I wonder which solution is the best. Do you have any idea ?

Warm regards, Hervé

ghost commented 3 years ago

PCA is less accurate, and often produces non optimum results