Calculating the diffraction of electrons or X-rays by carbon nanotubes