In this work, a direct algorithm for modeling optical systems using freeform surfaces is considered, which allows you to form a given illumination distribution of illuminating image systems of diffraction quality. Using the proposed ray tracing algorithm based on the laws of geometric optics, a database of optical systems for further training of the neural network is formed. To increase efficiency, the algorithm is tested on a sample of 10,000 pairs of various optical systems. Using a neural network, the inverse problem of calculating optical systems is solved - according to the given parameters of the object and image, the neural network generates a result in the form of a design of freeform optical elements. Further training of the neural network will speed up the design of new optical systems, and the potential for its learning opens up new opportunities for the development of better and more efficient optical systems.