Assume you have a regular grid of circular obstacles, defined by the equation:
$$\left[\textrm{mod}\left(x-x_{0}+\frac{d_{x}}{2},d_{x}\right)-\frac{d_{x}}{2}\right]^{2}+\left[\textrm{mod}\left(y-y_{0}+\frac{d_{y}}{2},d_{y}\right)-\frac{d_{y}}{2}\right]^{2}\le R^{2}\\R\leq\frac{1}{2}\min\left\{ d_{x},d_{y}\right\}$$
Where $d_{x,y}$ are the distances between the circles in each axis, $\left(x_0,y_0\right)$ is the center of a specific circle, and $R$ is the radues of the circles.
Assume also that in such a grid, we shoot a laser ray from location $\mathbf{r_0}$ with direction $\theta$ (I made a simple Desmos plot of the situation here).
In this setup, is there a closed-form way to find the location of the first hit of the ray with the obstacles?
I searched and found many answers to questions similar to this one, but couldn't find an exact match, nor could I convert their answer to fit my question. If you successfully find an existing answer, this will suffice too.
Thanks a lot!

Another view at the problem is the following. For simplicity assume $\mathbf{r}_0 = (0,0)$ and $d_x=d_y=1$, $x_0=y_0=0$ (The ray actually starts in a circle, however, we will disregard this hit later). This is only for reasons of presentation and I believe that the idea generalizes to the general setting that you presented.
Let $r_x,r_y$ be the unit-length vector, which is perpendicular to your ray. Now, projecting the circles onto this vector, will give line segments on that vector. If such a line segment includes the origin, the ray will hit a circle. The circles have centers $t_x,t_y \in \mathbb{N}$, whose projection onto the line is $t_xr_x + t_yr_y$. The condition for a ray to hit a circle with center $r_x,r_y$ eventually is thus $$ (t_xr_x+t_yr_y)^2 \leq R^2. $$ Since you want to find the first hit of the ray with a circle, the problem that you are looking to solve is $$ \min_{t_x,t_y \in \mathbb{N}} t_x^2+t_y^2~\text{ s.t. } (t_xr_x+t_yr_y)^2 \leq R^2.$$ This is a non-linear integer optimization problem, which you could try and solve with standard solvers. You might want to take care that you only consider those $t_x,t_y$ that are actually in the correct direction (the projection also gives you solutions which are behind your ray).