I have done some more searching about the topic, looks like what I’m looking for is call Minimum volume bounding box (MVBB) / Optimal bounding box.
Thanks to the efforts of this awesome community, I could stand on the shoulders of giants by using other libraries with little boilerplate.
Here are 2 versions I came up with:
- Yuka.js
The rotation is not quite right but at least it is much better than the AABB version.
- CGAL (using wasm)
The visualization looks exactly what I want. But I’m not sure how to do intersection test on the generated OBB without box directions.
Credit: Cgal library webassembly port