I'm trying to write a piece of code that calculates a diffraction pattern similar to an X-ray experiment using a FFT.
From my knowledge, the diffraction pattern for point particles can be calculated from the following formula:
$$ S(\mathbf{k}) = \left| \int_V d\mathbf{r}\rho(\mathbf{r})e^{-i\mathbf{k}\cdot\mathbf{r}} \right|^2 $$
which is basically the structure factor and $\rho(\mathbf{r})$ is the density function.
My shot on this was to first discretise the above formula using a box of side $r_{max}$: $$ S(\mathbf{k}) = \frac{r_{max}}{M} \sum_{lmn}^M \rho_{lmn} e^{-i\frac{r_{max}}{M}\left( k_x l + k_y m +k_z n \right)} $$ Now, I'm not sure how to discretise the wavevector and how this discretization will correspond to the lmn indices of the FFT: $$ A_{lmn} = \sum_{ijk}^M a_{ijk} e^{-i2\pi\frac{1}{M}\left( l i + mj +nk \right)} $$
An other detail I'm unsure of is how to get a 2D image corresponding to the diffraction pattern. What I though of, was that $\mathbf{k} = \mathbf{k}_S - \mathbf{k}_I$, where S is for the scattered light and I for the incident and I can set $\mathbf{k}_I = (\frac{2\pi}{\lambda},0,0)$. In approximation, the scattered and incident waves have the same magnitude $\frac{2\pi}{\lambda}$ so for a pixel of the screen (which has a distance d from the sample) with coordinates $x,y$, I have: $$ \mathbf{k}_S = \frac{2\pi}{\lambda} \frac{(d, x, y)}{\sqrt{d^2 + x^2 + y^2}} $$ and consequently I can calculate a scattering wave-vector for each pixel.
As I mentioned I'm not so sure how to discretise my scattering wave-vector and how this corresponds to the FFT wave-vectors, and on the last step of finding the correct wave-vectors for each pixel. Could you perhaps help me out?