Jump to content
  • Advertisement
Sign in to follow this  
falcon80

sphere and cube intersection

This topic is 4740 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello I have designed one sphere and a cube with the functions GlutwriteCube and to glutWriteShpere or to glutSolidSphere and glutSolidCube. Now I would have to calculate and to visualize the result of their intersection. who can help to make this me? thanks and sorry for my English

Share this post


Link to post
Share on other sites
Advertisement
In the case of an axis aligned box, you can use the following function:

bool BoundsDescriptor::sphereOverlapsAABB(const Tuple3f &sphrCen, float radius)
{
float s, d = 0;
for(int i=0 ; i<3 ; i++ )
{
if(sphrCen < minEndAABB )
{
s = sphrCen - minEndAABB;
d += s*s;
}
else
if(sphrCen > maxEndAABB)
{
s = sphrCen - maxEndAABB;
d += s*s;
}
}
return d <= radius*radius;
}



where minEndAABB is located at cubeCenter - (halfWidth, halfHeight, halfDepth) and maxEndAABB is at cubeCenter + (halfWidth, halfHeight, halfDepth).

PS: Besides the fact that this method would only tell you whether your geometry overlaps, I predict this thread will be moved to the Math forums in 1, 2, 3...
[pig]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I have found: Construtive solid geometry (CSG) but is not successful to find the code. someone can help me

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I have found: Construtive solid geometry (CSG) but is not successful to find the code. someone can help me

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!