# Babylon Intersect with Sphere ..Question

## Recommended Posts

hello,guys ,There is a question.erm.....i set the balloon1'X from 0 to 9,to check if it intersect with the red Sphere ,The console shows "6"(the right answer should be "2") which means this balloon is always intersect with the red ball....why..i'm confused.. http://www.babylonjs-playground.com/#1LS9HN

Thanks for u time..

##### Share on other sites

In this playground  http://www.babylonjs-playground.com/#1LS9HN#1  the loop for re-positioning the balloon is done ten times with the following results for each k

 0 TRUE 1 TRUE 2 TRUE 3 TRUE 4 TRUE 5 TRUE 6 FALSE 7 FALSE 8 FALSE 9 FALSE

So intersectsMesh is working but why is it giving positive results for the small values of k when it appears that the sphere and balloon are not intersecting?

This is because the intersection is based not on the meshes themselves but the bounding boxes of the meshes (shown as white cube outlines).

This PG http://www.babylonjs-playground.com/#1LS9HN#2  shows that while the sphere and mesh overlap their bounding boxes do ans so intersectsMesh is true.

Another point which may be of interest is that if you want to see the balloon move then loops will not work. You need to re-draw the balloon on each rendering of a new frame, for example

Of course this does not solve the problem of knowing when the sphere and balloon intersect as spheres.

There is a brand new method which may turn out to be of help but it is so new I have not tried it yet.

##### Share on other sites

4 hours ago, JohnK said:

In this playground  http://www.babylonjs-playground.com/#1LS9HN#1  the loop for re-positioning the balloon is done ten times with the following results for each k

 0 TRUE 1 TRUE 2 TRUE 3 TRUE 4 TRUE 5 TRUE 6 FALSE 7 FALSE 8 FALSE 9 FALSE

So intersectsMesh is working but why is it giving positive results for the small values of k when it appears that the sphere and balloon are not intersecting?

This is because the intersection is based not on the meshes themselves but the bounding boxes of the meshes (shown as white cube outlines).

This PG http://www.babylonjs-playground.com/#1LS9HN#2  shows that while the sphere and mesh overlap their bounding boxes do ans so intersectsMesh is true.

Another point which may be of interest is that if you want to see the balloon move then loops will not work. You need to re-draw the balloon on each rendering of a new frame, for example

Of course this does not solve the problem of knowing when the sphere and balloon intersect as spheres.

There is a brand new method which may turn out to be of help but it is so new I have not tried it yet.

Thank u JohnK,and now i have totally understand how intersectsMesh works.

but i still wanna check if two meshs real intersection,not by BoundingBox....So,i'm tring to write a method to make it ,i've read the source code about intersectsMesh method.,,but i dont have any idea...

any idea for that?I can never thank you enough ( for your support).

##### Share on other sites

Sorry forgot to paste the link I was referring to

this new method should help with intersections but have not studied it yet.

##### Share on other sites

OKay ,thx anyway.i'll have look at it .and will try my best to study it ,thx.

##### Share on other sites

Had a play around with new methods and works provided green balloon is much smaller than red sphere. The new method will soon be available without putting the code into PG.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.