Given an orbit's semi-major axis a, eccentricity e, and a radial distance r, you can recover the true anomaly — where the body sits along its orbit. Here's the compact Julia routine I use.

The math

From the orbit equation, the eccentric anomaly E satisfies cos E = (a - r) / (a·e), and the true anomaly f follows via the half-angle relation. Wrapping it in atan keeps it stable across quadrants.

The code

function radial_kepler(r, a, e; direction=1)
    e >= 1 && error("Only elliptical orbits (e < 1) supported")
    cosE = clamp((a - r) / (a * e), -1.0, 1.0)
    E = acos(cosE)
    f = 2 * atan(sqrt((1 + e) / (1 - e)) * tan(E / 2))
    return direction * f
end

a, e, r = 1.0, 0.1, 0.9        # r = a(1 - e): perihelion
println("True anomaly (deg): ", rad2deg(radial_kepler(r, a, e)))

At perihelion the true anomaly is zero — exactly what comes back, a nice sanity check.

Why Julia

For math-heavy numeric work Julia hits a sweet spot: the syntax reads like the equations, and it runs at near-C speed without dropping into another language.