arRay
will be a General-Relativistic Ray-Tracing code in Dyalog APL.
APL (A Programming Language) is an array programming language. This is a completely different (and for the most part obscure) paradigm compared to most other languages out there. APL shines in producing terse and efficient code when used for manipulations of matrices. I think that problem of General-Relativistic Ray-Tracing can be cast in these terms, so I wanted to see what it could come out.
Note: I started learning APL last in December 2022, so this code will likely be terrible.
According to General Relativity, light does not travel on straight lines and its motion is influenced by massive bodies (such as our Sun). Light rays travel on null geodesics, which are special curves in spacetime. General-relativistic ray-tracing consists in finding such curves given the initial position of the camera.
Let
First, we need to generate the initial data. Our initial data will consist of a grid of photons initially on our camera. Then, we integrate the photons backward in time towards the black hole. Each photon is described by the 8-element state that contains its four-position and four-momentum.
For the initial data, we need to specify five parameters: d
, the distance from
the black hole, i
and j
, the inclination and azimuthal angle of the camera,
N
and F
are the number of pixels and the field-of-view (we assume a square
camera). From these variables, we define a Cartesian coordinate system
For a given
In this first implementation, we solve the ODEs with a forward Euler's method,
which is the simplest way to solve an ODE. With this method, we move from the
In this, we defined $ \Gamma^\mu_{\alpha\beta}(\lambda_{i}) = \Gamma^\mu_{\alpha\beta}(x^\mu(\lambda_{i})) $.
For each photon, we set two termination conditions: either the photon gets very close to the horizon, or it goes too far. So, we define two parameters that control whether to continue the integration or not depending on the spatial position of the photon with respect to the horizon.