The Cornu Spiral can be calculated using Feynman's method for path integrals of light propagation. We will approximate this integral using the following discretisation.
Consider a mirror as in this image, where
S is the light source and
P the point where we collect light. We assume the light bounces in a straight ray from
S to each point in the mirror and then to point
P. We divide the mirror into
N segments, in this example 13, labelled
M, so that the path length of the light is
SN is the distance from
S to mirror segment
N, and similar for
P. (Note that in the image the distance of points
P to the mirror has been shortened a lot, for visual purposes. The block
Q is rather irrelevant, and placed purely to ensure reflection via the mirror, and avoid direct light from
For a given wave number
k the phasor of a ray of light can be calculated as
exp(i k R), where
i is the imaginary unit. Plotting all these phasors head to tail from the left mirror segment to the right leads to the Cornu spiral. For 13 elements and the values described below this gives:
N, i.e. a lot of mirror segments, the spiral approaches the "true" Cornu spiral. See this image using various values for
For a given
x(n) be the x-coordinate centre of the n-th mirror segment (
n = 0,1,2,...,N):
x(n) := n/N-0.5
SN(n) be the distance of
S = (-1/2, 1000) to the n-th mirror segment:
SN(n) := sqrt((x(n)-(-1/2))^2 + 1000^2)
NP(n) := sqrt((x(n)-1/2)^2 + 1000^2)
So the total distance travelled by the n-th light ray is
R(n) := SN(n) + NP(n)
Then we define the phasor (a complex number) of the light ray going through the n-th mirror segment as
P(n) = exp(i * 1e6 * R(n))
We now consider the cumulative sums (as an approximation to an integral)
C(n) = P(0)+P(1)+...+P(n)
The goal is now plotting a piecewise linear curve through the points
(C(0), C(1), ..., C(n)), where the imaginary part of
C(n) should be plotted against its real part.
The input should be the number of elements
N, which has a minimum of 100 and a maximum of at least 1 million elements (more is of course allowed).
The output should be a plot or image in any format of at least 400×400 pixels, or using vector graphics. The colour of the line, axes scale etc are unimportant, as long as the shape is visible.
Since this is code-golf, the shortest code in bytes wins.
Please note that this is not an actual Cornu spiral, but an approximation to it. The initial path integral has been approximated using the Fresnel approximation, and the mirror is both not of infinite length and not containing an infinite number of segments, as well as mentioned it is not normalised by the amplitudes of the individual rays.