Jump to content
Skybar

Intersection position of 2 spheres

Recommended Posts

I'm trying to find the position where 2 spheres intersect eachother. Just a location in the middle. If they both have the same radius it's pretty straightforward, I put both centroids into a Mix VOP with bias at 0.5. But if they're NOT the same radius I just can't figure it out. I suppose I need some sort of bias towards the smaller sphere, but I don't know where to get that from. I'm sure it's possible to calculate somehow from the centroids and radii, at least I think so but I can't get it right. Dialling it in manually doesn't really work when the spheres move. Does anyone have a clue?

Share this post


Link to post
Share on other sites

@sasho78 Hey thanks! Yeah that's about how far I've gotten as well. See picture what I mean. For same size spheres it works perfectly, but when they're not it's a little bit off.

sphereIntersect.jpg

Share this post


Link to post
Share on other sites

Sorry if this kind of answer isn't allowed, but this link explains it fairly straight forwardly 

 

 

Share this post


Link to post
Share on other sites

You can point a normal from one sphere's center to the other and multiply that by its own radius plus half the overlap of the spheres radii.

float rad_1 = ch("../sphere1/scale");
float rad_2 = ch("../sphere2/scale");

@N = normalize(@opinput1_P - @P);
@dist = distance(@P, @opinput1_P);
@diff = @dist - (rad_1 + rad_2);
@ibtw = rad_1 + ( @diff / 2 );

vector pos = @P + (@N * @ibtw );
addpoint(0, pos);

intersect_spheres.hipnc

Edited by konstantin magnus
added hip file

Share this post


Link to post
Share on other sites

Another way:

vector sphere_x_sphere_pos(vector a, b; float rada, radb)
{
    vector delta = b - a;
    float dist = length(delta);
    float x_dist = (rada*rada - radb*radb + dist*dist) / (2 * dist);
    vector x_pos = a + normalize(delta) * x_dist;
    return x_pos;
}

Check this thread for hips.

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×