A diffraction grating in 3D
Channel: Nils Berglund
Date: 2022-04-07

This 3D remake of the video https://youtu.be/mgC3gw2kbBE shows the working of a diffraction grating. Diffraction gratings are used for a variety of purposes, that include splitting an incoming wave into several beams that travel in different directions. Here an oscillating point source generates a circular wave that encounters a line of regularly spaced circular obstacles. This creates an interference pattern, with more energy traveling in particular directions.
This simulation has two parts, showing the same evolution with two different color gradients:
Wave amplitude: 0:00
Wave energy: 0:57
In the first part, the color hue depends on the height (amplitude) of the wave, with yellow indicating positive values, and purple indicating negative values. The luminosity depends on the cosine of the angle between the normal vector to the surface, and a fixed direction, to emulate the effect of a far away single light source illuminating the surface. 
In the second part, both the height of the 3D surface and its color hue show the energy of the wave, in the same way as the video https://youtu.be/PpKqNk_G2Hw (the energy is the sum of the kinetic and potential energy, which are proportional, respectively, to the square of the time derivative of the wave height, and to the square of the norm of its spatial gradient). 
The 3D projection has been improved over previous 3D simulations. Instead of using a linear transformation from 3D to 2D space, the 2D coordinates are computed by finding the intersection between the 3D point, and a plane located between the observer and the system, at right angles with a line between observer and center of the picture. I believe this method, which is used in ray-tracing, goes back to the painter Albrecht Dürer. 
The boundary conditions in the simulation are absorbing on the sides of the displayed rectangular region, but they do not work perfectly, which is why one seems reflections on the sides. 

Render time: 50 minutes
Color scheme: Part 1 - Parula, originally from Matlab
https://www.mathworks.com/help/matlab/ref/colormap.html
Part 2 - Magma by Nathaniel J. Smith and Stefan van der Walt
https://github.com/BIDS/colormap

Music: "Cast of Pods" by Doug Maxwell@dougmaxwell9118

See also https://images.math.cnrs.fr/Des-ondes-dans-mon-billard-partie-I.html for more explanations (in French) on  a few previous simulations of wave equations. 

The simulation solves the wave equation by discretization. The algorithm is adapted from the paper https://hplgit.github.io/fdm-book/doc/pub/wave/pdf/wave-4print.pdf 
C code: https://github.com/nilsberglund-orleans/YouTube-simulations
https://www.idpoisson.fr/berglund/software.html
Many thanks to my colleague Marco Mancini for helping me to accelerate my code!