# 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 on other sites

I'm sure it's all wrong, but for a quickie should work

someone better at math should help

middle_point.hip

##### 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.

##### Share on other sites

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

##### 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 );

intersect_spheres.hipnc

Edited by konstantin magnus

##### 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);
vector x_pos = a + normalize(delta) * x_dist;
return x_pos;
}```

Check this thread for hips.

• 1

##### Share on other sites

@vtrvtr @konstantin magnus @f1480187 This looks great! I'll look into it a bit later tonight, thanks a lot!

## 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