# How to get more accurate bounding box when local rotation does not help?

**URL:** <https://forum.babylonjs.com/t/how-to-get-more-accurate-bounding-box-when-local-rotation-does-not-help/49645>\
**Category:** Questions\
**Tags:** boundingbox\
**Created:** [April 14, 2024, 10:03am UTC](https://forum.babylonjs.com/t/how-to-get-more-accurate-bounding-box-when-local-rotation-does-not-help/49645 "2024-04-14T10:03:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![s207152](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/s207152/32/27550_2.png) [@s207152](https://forum.babylonjs.com/u/s207152)\
**Post date:** [April 14, 2024, 10:03am UTC](https://forum.babylonjs.com/t/how-to-get-more-accurate-bounding-box-when-local-rotation-does-not-help/49645/1 "2024-04-14T10:03:19Z")

</div>

Hi all,

As I play around bounding box, it looks like the current bounding box implementation is AABB rotated according to mesh local rotation.

> **[Babylon.js Playground](https://playground.babylonjs.com/#KQV9SA%23450)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

I have modified the playground of Mesh Intersection from docs.  
From left to right:

1. AABB
2. OBB with local rotation
3. OBB with baked rotation as vertex data

As you can see, the 3rd bounding box is actually the same as AABB.  
I would prefer to get result similar to 2nd bounding box, is there any way to get more accurate bounding box?

---

<div class="post-metadata">

**Author:** ![s207152](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/s207152/32/27550_2.png) [@s207152](https://forum.babylonjs.com/u/s207152)\
**Post date:** [April 15, 2024, 4:51pm UTC](https://forum.babylonjs.com/t/how-to-get-more-accurate-bounding-box-when-local-rotation-does-not-help/49645/2 "2024-04-15T16:51:46Z")

</div>

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:

1. Yuka.js  
The rotation is not quite right but at least it is much better than the AABB version.

> **[Babylon.js Playground](https://playground.babylonjs.com/#KQV9SA%23457)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

1. 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.

> **[Babylon.js Playground](https://playground.babylonjs.com/#KQV9SA%23451)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

Credit: [Cgal library webassembly port](https://forum.babylonjs.com/t/cgal-library-webassembly-port/41484)

---

<div class="post-metadata">

**Author:** ![waverider404](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/waverider404/32/17464_2.png) [@waverider404](https://forum.babylonjs.com/u/waverider404)\
**Post date:** [April 15, 2024, 7:50pm UTC](https://forum.babylonjs.com/t/how-to-get-more-accurate-bounding-box-when-local-rotation-does-not-help/49645/3 "2024-04-15T19:50:17Z")

</div>

Nice! I plan to expose most of the cgal functions, make it easier to use.

For the intersection issue you can probably do refreshBoundingInfo or use raycaster instead
