What I want to know is: what is the formula that defines the relationship between them?
The formula is the thin lens formula,
$$ {1\over f} = {1\over o} + {1\over i} $$
where \$o\$ is the object distance, \$i\$ is the image distance, and \$f\$ is the focal length of the lens.
In the mathematics of optics, the optical power of a lens is the inverse of the lens's focal length: \$P = 1/f\$. This power is often measured in diopters, in unit of \$[\mathrm{meter}^{-1}]\$. So you could alternately phrase the thin lens formula as "the optical power of a thins is the sum of the surface powers of the lens".
Playing with the interactive optics tool, you noted how \$o\$ and \$i\$ are related when \$i\$ is \$3f\$, \$2f\$, and \${3\over2}f\$. But what happens when \$i = f\$? Well, the tool won't allow the object side to move out of frame, but if you notice that as \$i\$ approaches \$f\$, \$o\$ gets large very quickly.
In fact, let's take the limit of the thin lens formula as \$o\$ approaches infinity:
$$\require{cancel}\begin{align}\lim_{o\to\infty}{1\over f} &= \cancelto{0}{1\over o} + {1\over i} \\
&= {1\over i}\end{align}$$
Therefore, when focusing at infinity, the image distance \$i = f\$. This is actually the definition of focal length of a lens: the distance at which a lens focuses a "pencil" of collimated light (i.e., parallel rays) to a point.
Now, I assume this is valid for all convex lenses. Is it also true for modern camera lenses?
It's true, "ish", for all convex lenses, including modern (and older) camera lenses. Realize that the thin-lens formula is an approximation. It assumes a lens is "sufficiently thin", meaning the lens thickness is very small compared to its surface powers (the radii of curvature of the surfaces). And it also assumes we're talking about rays in the paraxial approximation, meaning rays that are almost parallel to the optical axis, so that it allows us to simplify trigonometry so that \$\sin\theta \approx \theta\$ (and \$\tan\theta\approx\theta\$), for sufficiently small \$\theta\$. (This is similar to how we solve the simple pendulum problem in physics by assuming the pendulum deviation \$\theta\$ is small enough that \$\sin\theta\approx\theta\$)
For non-macro distances, meaning the object is far enough away that the image magnification is much less than 1, say at least 10 focal lengths away, the thin lens formula works well for complex (multi-element) lenses. But the problem is figuring out, where to measure \$o\$ and \$i\$ from?
In photography, at non-macro distances the details of the object distance and image distance don't really matter to us. Whatever the image distance is, we don't care, as long as the object we're focusing on is in focus. Is it what it is.
At macro distances, we don't care about the image distance per se; rather, we are concerned about the transverse magnification. The magnification is simply the ratio of the height of the image to the real world object height, which can be deduced from similar triangles from \$i\$ and \$o:\$
$$\begin{align} M &= {h_i \over h_o} \\
&= {i\over o}
\end{align}$$
Using algebra on the thin lens formula,
$$\begin{align}M &= {i-f \over f} \\
&= {f\over o-f}\end{align}$$
Macro distances, that is where the object is very close to the lens and \$M \ge 1\$, usually involve setting the lens magnification using the focal dial, and then precisely moving the entire camera+lens forward or backward to achieve the correct plane of focus (and usually a bit of repetitive fiddling between the two).
Additionally, another problem is that the stated focal lengths of camera lenses are nominal, not precise. For most prime lenses, you can rely on the focal length to calculate the angle of view when the lens is focused at infinity, using the pinhole projection formula (for non-fisheye and non-wide-angle lenses):
$$ AOV = 2\arctan{d\over 2f} $$
Here, \$d\$ is the size of the sensor in the dimension you're measuring the angle of view. For vertical AOV, \$d\$ is the sensor's height / vertical measurement. For horizontal AOV, \$d\$ is the sensor's width / horizontal measurement.