I'm working on implementing a GR (general relativity) raytracer for the purposes of displaying realistic visuals of a black hole against some fixed imagery (pictures of stars, for example.) I don't understand a lot of the language in general relativity, so I would like some help with the mathematics of it. Please bear with me, I am a programmer not a physicist.

Suppose I have three vectors (in 3-dimensional space), p (black hole position), p0 (light ray origin), v0 (light ray direction) and the mass M of the Schwarzschild black hole, how do I find the resultant direction of the light ray v1 after it has been fully influenced by the black hole? I understand that this might involve using some form of the geodesic equation:

\begin{equation} \frac{d^2x^\mu}{ds^2} + \Gamma^\mu_{\nu\lambda}\frac{dx^\nu}{ds}\frac{dx^\lambda}{ds} = 0 \end{equation}

I believe my use case requires a formulation of this equation integrated at infinity (to find vector v1.) I understand if the problem is non-trivial and cannot be explained or simplified to a single equation, and in this case I would highly appreciate pointers for better understanding of the topic. Numerical methods are more than acceptable.


  • During research I saw that proper time could be taken to be the time of an observer positioned at infinity, for simplicity. I don't know how to do this in practice.
  • The black hole in question is not rotating.
  • The black hole does not have charge. (?)
  • $\begingroup$ your project is very cool! I have a bachelor in physics and im doing a master in theoretical physics atm, i have a passion for coding since a long time. I feel the question doesnt belong here too well, but do you feel like collaborating on this? $\endgroup$
    – lucabtz
    Feb 24, 2022 at 18:16
  • 1
    $\begingroup$ I think unfortunately this question might be too broad, but I don't know of any resource for this that isn't just a general relativity book. Not saying that one can't exist, only that I don't know of any. $\endgroup$
    – Javier
    Feb 24, 2022 at 22:10

1 Answer 1


Indeed you need the geodesic equation, though you do not need its time dependence, but only its shape. This simplifies the problem a lot and you end up having to integrate an ODE to get the solution you want.

I will do the steps needed to obtain this equation. Start from the Schwartzchild metric \begin{equation} ds^2 = \left(1 - \frac{2MG}r \right)dt^2 - \left(1 - \frac{2MG}r \right)^{-1}dr^2 - r^2(d\theta^2 + \sin^2\theta \ d\phi^2) \end{equation} Now we consider the symmetries of the action \begin{equation} S[x] = \frac1 2 \int d\lambda \ g_{\mu\nu}\frac{dx^\mu}{d\lambda}\frac{dx^\nu}{d\lambda} \end{equation} The coordinates $t$ and $\phi$ are cyclic and the corresponding conserved Noether charges are energy and angular momentum. (There is an additional symmetry under reparametrizations $\lambda^\prime = \lambda + \epsilon(\lambda)$ but we do not need it). The expressions for energy and angular momentum are \begin{equation} E = g_{tt}\frac{dt}{d\lambda} = \left(1 - \frac{2MG}r\right)\frac{dt}{d\lambda} \end{equation}

\begin{equation} L = - g_{\phi\phi}\frac{d\phi}{d\lambda} = r^2 \frac{d\phi}{d\lambda} \end{equation}

Light-like geodesics are given by \begin{equation} g_{\mu\nu}\frac{dx^\mu}{d\lambda}\frac{dx^\nu}{d\lambda} = 0 \end{equation} also your points p, p0 and the vector v0 together identify a plane which after a rotation we can say it is the plane $\theta = \frac \pi 2$ (I already considered this is the expression of $L$).

So we can write the equation for the light geodesics as \begin{equation} \frac{E^2}{1- 2MG/r} - \frac 1 {1 - 2MG/r}\dot{r}^2 - \frac{L^2}{r^2} = 0 \end{equation} ($\dot{r} = dr/d\lambda$). Now we eliminate $\lambda$ in the equation, so we have an equation for the function $r(\phi)$, the light ray path on the plane defined above.

\begin{equation} \frac{E^2}{1- 2MG/r} - \frac 1 {1 - 2MG/r}\frac{L^2}{r^4}\left(\frac{dr}{d\phi}\right)^2 - \frac{L^2}{r^2} = 0 \end{equation}

You can than manipulate this equation a bit and end up with a second order equation. First we introduce the variable $u = 1/r$, then $du = -r^{-2}dr$ and we have hence \begin{equation} \frac{E^2}{1-2MGu} - \frac {L^2} {1- 2MGu}\left(\frac{du}{d\phi}\right)^2 - L^2u^2 = 0 \end{equation}

Then we cast it into \begin{equation} \frac{E^2}{2L^2} = \frac 1 2 \left(\frac{du}{d\phi}\right)^2 + \frac {u^2} {2} (1 - 2MGu) \end{equation}

This looks like the energy of a particle of unit mass in the potential $V(u) = \frac {u^2} {2} (1 - 2MGu)$ and of energy $E^2/2L^2$ (with time replaced by $\phi$). Deriving with respect to $\phi$ we obtain the equation \begin{equation} \frac{d^2u}{d\phi^2} = - \frac{dV}{du} \end{equation}

which you can integrate via numerical methods

  • $\begingroup$ Thanks a lot for the insight. I would love to collaborate but this is for my final year thesis and the work must largely be my own. I will gladly include your contributions as reference in the final paper, though (this is actually mandated by my University.) This has been helpful but I'm not sure how I would calculate E, L or r in this equation, and I'm guessing this will need integrating to remove the derivative? I have sent you an email (the one on your GitHub) if this makes communication easier. $\endgroup$
    – curz46
    Feb 25, 2022 at 13:52
  • $\begingroup$ $E$, $L$ need to be calculated via the initial conditions, I will workout the formulas in terms of the data you have when I have time. $r$ is just the Schwarzchild radius wich is related to the radial distance from the black hole $\endgroup$
    – lucabtz
    Feb 25, 2022 at 16:18
  • $\begingroup$ $L/E$ is the impact parameter $b$. The deflection of light only depends on this, not $E$ and $L$ separately. $\endgroup$
    – ProfRob
    Feb 25, 2022 at 20:49
  • $\begingroup$ This looks promising, but I don't quite understand. Should I plug in V'(u) for dV? If this is the final equation to integrate, shouldn't it increase inversely proportional to the distance of the photon from the black hole? I know u=1/r, but the Schwarzchild radius (r) from the black hole is a fixed value dependent on its mass. Since we see d^2u/dϕ^2 on the left side, this would imply that the Schwarzchild radius changes over time if I'm not mistaken. Perhaps I am misunderstanding the definition for r? $\endgroup$
    – curz46
    Feb 28, 2022 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.