Sign in to follow this  

Bounding Sphere Radius and Point Intersection

Recommended Posts

Just got a quick question demonstrated in the following example:

Q1. You can see a sphere mesh being constructed with a diameter of 4, yet the bounding sphere of said mesh has a radius of '3.4641016151377544'.  Shouldn't it be ~2?

Q2. I may be misunderstanding BoundingSphere.intersectsPoint, but after picking a mesh from the scene, an additional check is done to see if said point exists within the bounding sphere.  This returns true even when dragging across the plane,  far away from the sphere.  Why is this happening?

Snippet of BoundingSphere.intersectsPoint

// pick from scene, ignore ray helper, don't use fast pick
const pick = scene.pick(scene.pointerX, scene.pointerY, m => !== 'ray', false)

// if we have a hit and the point exists within bounding sphere
if (pick.hit && bs.intersectsPoint(pick.pickedPoint)) {


Thank you!

Share this post

Link to post
Share on other sites

what is happening is we are relying on a distance calculation that for some reason is not doing it

here is a work around.


var min = Number.POSITIVE_INFINITY;
    var max = Number.NEGATIVE_INFINITY;
    var va = ['x','y','z'];
    for(var i=0; i<3; i++){

    var distance = max-min;
    var radius = distance*0.5;

    console.log(radius, "real Radius");


Share this post

Link to post
Share on other sites

Thanks for the quick response and details Pryme8!

Doesn't this mean that each operation performance against the Bounding Sphere is potentially incorrect? EG intersectsPoint, isInFrustum.  Assuming they depend on the internal radius, not 'realRadius'.

Share this post

Link to post
Share on other sites

ehhhhh, maybe honestly...  I mean it kinda would seem that way.

The distance.length() calc seems to be the problem.
but Im not sure if everything else is working correctly, thats why I left the old stuff and just did a secondary calc.

When I get back from lunch Ill dig more into this math.

Share this post

Link to post
Share on other sites

Q1 : I guess there's a misunderstanding about what is the bounding sphere of a mesh here, of any mesh (a sphere or a box, or anything). The bounding sphere is simply the sphere embedding the mesh bounding box !

In the particular case where the mesh itself is a sphere, well, it is contained in a bounding box greater than it, this bounding box being contained in its bounding sphere greater than the bounding box.

That's why the bounding sphere radius is always greater than the contained spherical mesh radius. 

If you want a better explanation, please have a read at the part  starting by "As you may know, a mesh -so a solid particle- is inside its bounding ..." here :

In the case of spherical mesh the ratio between the bounding sphere radius and the contained sphere radius is sqrt(3)

Share this post

Link to post
Share on other sites


var r = BABYLON.Vector3.Distance(bs.maximum, bs.minimum);
r /= Math.sqrt(3);
console.log(r, "real Radius");

I had to divide it in half as well, cause ratio of sqrt 3 just gave me the diameter.

Share this post

Link to post
Share on other sites
const min = new BABYLON.Vector3(-0.5, -0.5, -0.5)
const max = new BABYLON.Vector3(0.5, 0.5, 0.5)
const pnt = new BABYLON.Vector3(50, 50, 50)
const boundingSphere = new BABYLON.BoundingSphere(min, max)
// result is true
const result = boundingSphere.intersectsPoint(pnt)

The bounding sphere check above always returns true, although the point doesn't exist within the boundingSphere.

Share this post

Link to post
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.