# Boundingbox of object with rotation

**URL:** <https://discourse.threejs.org/t/boundingbox-of-object-with-rotation/45289>\
**Category:** Questions\
**Tags:** box3, boundingbox\
**Created:** [November 29, 2022, 1:16pm UTC](https://discourse.threejs.org/t/boundingbox-of-object-with-rotation/45289 "2022-11-29T13:16:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fluqz](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/fluqz/32/6279_2.png) [@Fluqz](https://discourse.threejs.org/u/Fluqz)\
**Post date:** [November 29, 2022, 1:16pm UTC](https://discourse.threejs.org/t/boundingbox-of-object-with-rotation/45289/1 "2022-11-29T13:16:42Z")

</div>

Hey, Im trying to use Box3 on a rotated model. The result I get is wrong.

I guess the images demonstrate the problem pretty good. All objects are rotated around the y axis.

What I dont understand is why the boundingbox is not “touching” the geometry anymore? I know the boundingbox is axis aligned and increases volume when rotated, but it should fit the object exactly, shouldnt it? Is this intentionally?

Here is the object with rotation = 0 and rotation = .7. (Boundingbox on each nested object)

 ![Screenshot 2022-11-29 at 13.36.35](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/2/c/2c44a3d9af75dcf6b966f4ad35284c57d6d72773.jpeg)

Here is a comparison to a BoxGeometry with rotation. There is a gap between boundingbox and model, but no gap between the boundingbox and cube

 ![Screenshot 2022-11-29 at 13.58.15](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/3/1/31441b23429706667790d8dc1e696d808d4587c7.jpeg)

[Test files](https://discourse.threejs.org/uploads/short-url/2lpnmBDXRAEUO2SuI7ALMAMjda8.zip) (137.0 KB)

Code:

```javascript
// Inside loading callback

            obj = gltf.scene

            scene.add(obj)

            obj.rotation.y = .7
            obj.updateMatrix()

            const box = new THREE.Box3().setFromObject(obj)

            // box.applyMatrix4(obj.matrixWorld)
            
            const h = new THREE.Box3Helper(box)

            scene.add(h)

```

Applying the matrixWorld as shown in the docs, does increase the size of the boundingbox even more.

---

<div class="post-metadata">

**Author:** ![Lawrence3DPK](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/lawrence3dpk/32/29184_2.png) [@Lawrence3DPK](https://discourse.threejs.org/u/Lawrence3DPK)\
**Post date:** [November 29, 2022, 3:02pm UTC](https://discourse.threejs.org/t/boundingbox-of-object-with-rotation/45289/2 "2022-11-29T15:02:54Z")

</div>

bounding boxes are non inclusive of the rotation of objects and will always return the min and max dimensions of a given object, you will find the [OBB](https://threejs.org/docs/#examples/en/math/OBB) class is what you’ll need to use for your case as it returns an oriented bounding box relative to the updated matrix of an object, I hope this helps.

---

<div class="post-metadata">

**Author:** ![Fluqz](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/fluqz/32/6279_2.png) [@Fluqz](https://discourse.threejs.org/u/Fluqz)\
**Post date:** [November 29, 2022, 6:35pm UTC](https://discourse.threejs.org/t/boundingbox-of-object-with-rotation/45289/3 "2022-11-29T18:35:39Z")

</div>

Hey thanks for your reply. Can you explain what you said? As mentioned boundingboxes are axes aligned, but they still take rotation into account, as seen in img2, where the rotated cuboid is framed exactly inside of the boundingbox. On the other hand my model is not framed exactly, au contraire the boundingbox is actually way bigger than the model.

Here I painted the desired boundingbox in red. The yellow boundingboxes are calculated via Box3

 ![Screenshot 2022-11-29 at 13.58.15](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/2/0/20040d87fe991a4cb795113c82b5c3803cf877d0.png)

The oriented boundingbox looks nice, but it looks like its only for cubes? Not for cuboids

---

<div class="post-metadata">

**Author:** ![Fluqz](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/fluqz/32/6279_2.png) [@Fluqz](https://discourse.threejs.org/u/Fluqz)\
**Post date:** [December 1, 2022, 12:11pm UTC](https://discourse.threejs.org/t/boundingbox-of-object-with-rotation/45289/4 "2022-12-01T12:11:09Z")

</div>

I wonder, is this something exceptional? Doesnt look like a big deal to me at first. I checked the model in blender and tested it in two projects. Cant really figure out whats happening

---

<div class="post-metadata">

**Author:** ![prisoner849](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/prisoner849/32/535_2.png) [@prisoner849](https://discourse.threejs.org/u/prisoner849)\
**Post date:** [December 1, 2022, 12:43pm UTC](https://discourse.threejs.org/t/boundingbox-of-object-with-rotation/45289/5 "2022-12-01T12:43:41Z")

</div>

@Fluqz  
See, what happens here: [three.js/Box3.js at 309b00afb6dcbc5e6c58e72f10eaa8d2e8888c83 · mrdoob/three.js · GitHub](https://github.com/mrdoob/three.js/blob/309b00afb6dcbc5e6c58e72f10eaa8d2e8888c83/src/math/Box3.js#L202L229)  
If you won’t set the second parameter of `.setFromObject()` method to `true` (by default, it’s `false`), you’ll get exactly what you have on the pic with that bent and rotated figure, kind of AABB of OBB.

---

<div class="post-metadata">

**Author:** ![Fluqz](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/fluqz/32/6279_2.png) [@Fluqz](https://discourse.threejs.org/u/Fluqz)\
**Post date:** [December 1, 2022, 5:40pm UTC](https://discourse.threejs.org/t/boundingbox-of-object-with-rotation/45289/6 "2022-12-01T17:40:39Z")

</div>

That worked! Thanks a lot man 😃
