Exchange of volume between spheres until they no longer intersect Let's say we have two spheres (named $1$ & $2$) whose sizes are stored as radii ($r_1$ and $r_2$) with centres being $d$ distance apart.
Now when the two spheres intersect (id est, $d < r_1 + r_2$) I want to 'drain' the volume of one sphere into the other precisely such that there is no intersect, yet no gap either (thus $d = r'_1 + r'_2$).
The larger sphere will siphon from the smaller sphere. Let $1$ be larger; $v_1 > v_2$.

My thought coming into this was that it would be simple, I'm just making one smaller, and one larger, but the larger one would have grown 'slower' because of it already being larger (probably due to the relationship between volume and radius, $v = \frac{4\pi r^3}{3}$).
But I'm having trouble deducing the volume, $\Delta v$, that would be needed to shift between the spheres (which won't move during the instantaneous exchange) to influence the radii correctly.
Given that the volume is 'traded' between the two ($v'_1 = v_1 + \Delta v$, $v'_2 = v_2 - \Delta v$), the sum volume of the two spheres will be conserved ($v_1 + v_2 = v'_1 + v'_2$).
I'm writing the program such that the mathematical expression won't need to be robust enough to accept a lot of corner cases, so we can assume some things (like the centre of the smaller sphere will not be inside the larger sphere's bounds) if it helps.
One of the things we tried (when we couldn't solve the cube-root-containing simultaneous equations we came up with) was finding the volume of the intersection, and just using that as $\Delta v$ (the resultant spheres still had radii that overlapped).
 A: The total volume of the two spheres is $$\frac{4 \pi}{3} r_1^3 + \frac{4 \pi}{3} r_2^3.$$ We're looking for a configuration in which the radii of the two spheres are $R$ and $d - R$ for the prescribed distance $d$ and some (large ball) radius $R$; by construction these radii must satisfy
$$\frac{4\pi}{3} R^3 + \frac{4\pi}{3} (d - R)^3 = \frac{4 \pi}{3} r_1^3 + \frac{4 \pi}{3} r_2^3.$$
We may cancel the common factor of $\frac{4\pi}{3}$, and expanding the parenthetical quantity and canceling helpfully eliminates the cubic terms in $R$. Then, rearranging leaves a quadratic equation in $R$, to which we can apply the Quadratic Formula:
$$3 d R^2 - 3 d^2 R + \left(d^3 - r_1^3 - r_2^3\right) = 0.$$
You might like to check out the excellent game Osmos, which uses a similar mechanic in 2 dimensions.
A: Upvote Travis' answer for the workings, but the solution wasn't written.
For posterity the simplified answer I found [from it] was:
$$\text{let } r'_2 = d - r'_1$$
$$\begin{align}
r'_1 &= \frac{d}{2}(1 + \sqrt{1 - \frac{4}{3}(1 - \frac{r_1^3 + r_2^3}{d^3})})\\
&= \frac{d}{2}(1 + \sqrt{\frac{1}{3}(\frac{4(r_1^3 + r_2^3)}{d^3} - 1)})
\end{align}$$

Also I decided I may want to use circles [trading area] instead of spheres [trading volume], and with the solution in this form it was really easy to modify (without proofs or reasoning) to get this answer:
$$r'_1 = \frac{d}{2}(1 + \sqrt{1 - 2(1 - \frac{r_1^2 + r_2^2}{d^2})})$$
Sanity test/verification
A: It turns out I'm going to store the values in volume (actually, as mass, but the density is uniform) so it is more useful, for me at least, to have the equation as a function of volumes outputting a volume.
Using the existing solution, substitute in the equation for volume.
$\because r = \sqrt[3]{\frac{3v}{4\pi}}, \therefore r^3 = \frac{3v}{4\pi}$:
$$\begin{align}
r'_1 &= \frac{d}{2}(1 + \sqrt{1 - \frac{4}{3}(1 - \frac{3}{4\pi d^3}(v_1 + v_2))})\\
&= \frac{d}{2}(1 + \sqrt{\frac{v_1 + v_2}{\pi d^3} - \frac{1}{3}})
\end{align}$$
Using $v = \frac{4\pi r^3}{3}$:
$$v'_1 = \frac{\pi d}{6}\left(1 + \sqrt{\frac{v_1 + v_2}{\pi d^3} - \frac{1}{3}}\right)^3$$
Obviously $v'_2 = v_1 + v_2 - v'_1$ and it still works :) compare with the other solution's output
