# How to judge whether two meshes intersect？

**URL:** <https://forum.babylonjs.com/t/how-to-judge-whether-two-meshes-intersect/36159>\
**Category:** Questions\
**Tags:** mesh\
**Created:** [December 1, 2022, 7:19am UTC](https://forum.babylonjs.com/t/how-to-judge-whether-two-meshes-intersect/36159 "2022-12-01T07:19:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hbwow123](https://avatars.discourse-cdn.com/v4/letter/h/8dc957/32.png) [@hbwow123](https://forum.babylonjs.com/u/hbwow123)\
**Post date:** [December 1, 2022, 7:19am UTC](https://forum.babylonjs.com/t/how-to-judge-whether-two-meshes-intersect/36159/1 "2022-12-01T07:19:57Z")

</div>

Hello，I’m sorry to bother you，i have a question：how to judge whether two meshes intersect？  
for example：

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/3/b/3b21bae3a217bbb3ca6f3a6d0977008086ba1ec2.png)

The box intersects the cylinder。

Is there a simple method or function to determine if two meshes intersect？

thanks for your help！

---

<div class="post-metadata">

**Author:** ![Takemura](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/takemura/32/25836_2.png) [@Takemura](https://forum.babylonjs.com/u/Takemura)\
**Post date:** [December 1, 2022, 8:05am UTC](https://forum.babylonjs.com/t/how-to-judge-whether-two-meshes-intersect/36159/2 "2022-12-01T08:05:37Z")

</div>

Suiting your example, I would use

```auto
box.intersectsMesh(cylinder, false)

```

to get `true` boolean returned.

Docs:

> **[Mesh Intersections | Babylon.js Documentation](https://doc.babylonjs.com/features/featuresDeepDive/mesh/interactions/mesh_intersect)**
>
> Learn all about mesh intersections in Babylon.js.

---

<div class="post-metadata">

**Author:** ![hbwow123](https://avatars.discourse-cdn.com/v4/letter/h/8dc957/32.png) [@hbwow123](https://forum.babylonjs.com/u/hbwow123)\
**Post date:** [December 1, 2022, 8:11am UTC](https://forum.babylonjs.com/t/how-to-judge-whether-two-meshes-intersect/36159/3 "2022-12-01T08:11:33Z")

</div>

thanks，Is this method suitable for any complex mesh？

---

<div class="post-metadata">

**Author:** ![Takemura](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/takemura/32/25836_2.png) [@Takemura](https://forum.babylonjs.com/u/Takemura)\
**Post date:** [December 1, 2022, 8:26am UTC](https://forum.babylonjs.com/t/how-to-judge-whether-two-meshes-intersect/36159/4 "2022-12-01T08:26:18Z")

</div>

If you set precise parameter (second one) to true, so Intersection is determined by OBB which is explained here:

> **[Bounding volume](https://en.wikipedia.org/wiki/Bounding_volume)**
>
> In computer graphics and computational geometry, a bounding volume for a set of objects is a closed volume that completely contains the union of the objects in the set. Bounding volumes are used to improve the efficiency of geometrical operations by using simple volumes to contain more complex objects. Normally, simpler volumes have simpler ways to test for overlap.
> A bounding volume for a set of objects is also a bounding volume for the single object consisting of their union, and the other way...

But I doubt this would work for i.e. inside a torus (ring), because the bounding box encompasses the hole of the ring and extends over the roundings. For this you might need an Physics Engine.

Edit: I made an example to showcase the issue inside a torus:

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

Depending on your scenario, using several rays might also be enough to check the intersections on faces/triangles, but it can turn into a lot of work if you have several forms of meshes. Another idea would be to use the more “performance-heavy” Constructive Solid Geometry:

> **[Merging Meshes | Babylon.js Documentation](https://doc.babylonjs.com/features/featuresDeepDive/mesh/mergeMeshes#merging-meshes-with-constructive-solid-geometry)**
>
> Learn how to merge meshes in Babylon.js.

Or maybe there is a external library that offers triangle intersection.
