Jump to content
  • Advertisement
Sign in to follow this  
mrbig

Separating Two Intersecting Spheres

This topic is 4356 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

I'm sorry for the stupid question, but... how do I correctly separate two intersecting spheres?

Share this post


Link to post
Share on other sites
Advertisement
I would suggest using the vector that goes from one center to the other. Evaluate the speed of both spheres along this vector through projection, and determine how much you have to move back in time for the spheres to be merely tangent (assume speed is uniform). Then, move each sphere back by its velocity multiplied by the aforementioned time.

Share this post


Link to post
Share on other sites
I need a static test.
I want to know how much to move one sphere along an arbitrary direction to make it stop penetrating the other.

Share this post


Link to post
Share on other sites
You don't want to choose an arbitrary direction.

You probably want to choose the direction that results in the minimum translation necessary to separate them.

This direction is the normalised delta between the two sphere centers.

The distance (D) is the sum of the sphere radii minus the magnitude of the delta. Add 0.5 * D * delta to the position of one sphere, and -0.5 * D * delta to the position of the other.

e.g.

Vector delta = sphere2.pos - sphere1.pos;
D = delta.NormaliseSafe(); // returns the original length
sphere2.pos += 0.5f * D * delta;
sphere1.pos -= 0.5f * D * delta;

Share this post


Link to post
Share on other sites
That's an obvious solution, but it is wrong.

ZOMG IT'S A SPHEER111!!!COSINE(-1)!

'A' shows a sphere traveling downwards, colliding with another sphere in its new position.
'B' shows the results of the suggested solution.
'C' shows the correct solution.

The sphere should be pushed back in the direction of the velocity, i.e. upwards.
Thanks anyway.

[EDIT]

Yes, I know it would be hardly noticeable in real-time, but still, isn't there a better solution?

[Edited by - mrbig on August 17, 2006 10:04:21 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by mrbig
That's an obvious solution, but it is wrong.
MrRowl's solution isn't wrong; it is the standard solution to the problem of resolving a discrete intersection between two spheres.

It appears though that you're asking a different question: how far do you need to move one sphere along an arbitrary vector to resolve an intersection. MrRowl mentioned that typically you want to resolve the intersection along the minimum penetration vector (which is true), and gave the solution to that particular problem.

Out of curiosity, why do you want to resolve the intersection in an arbitrary direction?

Share this post


Link to post
Share on other sites
Ah - I see - I guess you didn't ask the right question (inserting the word static into the question was a bit misleading, you must admit!) :)

I guess you would form the quadratic equation:

d = f(t)

where d is the distance between your red sphere centre and your blue sphere at "time" t (t = 0 gives the blue sphere, t = 1 gives the white sphere).

Then solve to find the two values of t where d = redRadius+blueRadius. Take the minimum value of t (assuming it's real and > 0).

Share this post


Link to post
Share on other sites
A common trick for this type of situation is make one of the spheres into a point and change the radius of the other one to be the sum of the two original radii. You are left with the problem of finding the intersection of a ray and a sphere.

Share this post


Link to post
Share on other sites
Quote:
Original post by mrbig
Yes, I know it would be hardly noticeable in real-time, but still, isn't there a better solution?


Could you explain, in detail, why my solution does not correspond to your needs?

All my solution uses is the current and previous position (or velocity) of the spheres. If all you have is the current position, there is no better solution than simply moving the two spheres along the line through their centers. If you have the previous position or the velocity, my solution works. What's the catch?

Share this post


Link to post
Share on other sites
For the record, I ask the right question, you just read them wrong. :P

I asked, "how do I correctly separate two intersecting spheres?", which was too general, perhaps unclear, but not incorrect.

Therefore I clarified it in my second post:

"I need a static test.
I want to know how much to move one sphere along an arbitrary direction to make it stop penetrating the other."

The way I asked it, the problem doesn't involve any velocity or time, therefore, is static.

And assuming that Mr. Rowl was trying to answer my question, his solution IS wrong.
The attached picture shows why it can sometimes be not very plausible.

And here's the key point:
Actually, I need to resolve the collision in the direction of the velocity, but since I was talking about a static test, I generalized it as "an arbitrary direction", to avoid confusion, which I clearly haven't. :P

And finally, ToohrVyk, you quote me in a reply to another person!
See how you all got it all wrong? :P

But all that really doesn't matter.
The solution to my question (yet again) appears to involve complex calculations.
Especially considering the fact that I'm planning to approximate my objects using spherical voxels. (Yes, I know it's madness. But hell, why not try it?)
I'll stick with Mr. Rowl's standard (and inexact) solution.
It shouldn't be too much apparent, especially with the collision response generated for my voxel objects, which would draw the user's attention with its oddness.

Thanks for your help, everybody!

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!