\documentclass{article}

%\usepackage{axodraw4j}
\begin{document}

\section{Photon: linear}

This is the algorithm used to draw photon lines as extracted from the axodraw
code. The snippet below draws a photon line from $(0,0)$ to $(L,0)$,
with $N$ wiggles (ie half-wavelengths) and amplitude $A$.
The line just has to be rotated and moved to it's final position.

\begin{verbatim}

    N = 2 * getWiggles();
    if (isSymmetric) {
        N = N + 1;
    }

    A = getAmp() / 2;

    delta = L / N;
    c = (4 / 3) * delta / pi;
    amp = -(4 / 3) * A;

    for ( int j = 1; j <= N; j++ ) {
        xj = (j - 1) * delta;
        Bezier( xj, 0,
                xj + c, amp,
                xj + delta - c, amp,
                xj + delta, 0 );
        amp = -amp;
    }
\end{verbatim}

%=========================

\pagebreak

\section{Photon: arcs and loops}

This is the algorithm used to draw photon arcs and loops as extracted from
the axodraw code. The snippet below draws a photon arc centered at the origin,
with radius $r$ and start point at $(r,0)$. The opening angle is $oa$
(in radians) which is positive (negative) for clockwise (anti-clockwise) arcs,
and equal to $2\pi$ for loops.
$N$ is the number of wiggles (ie half-wavelengths) and $A$ the amplitude.
The arc/loop just has to be rotated and moved to it's final position.

\begin{verbatim}
    N = 2 * getWiggles();
    if (isArc and isSymmetric) {
        N = N + 1;
    }

    A = -getAmp() / 2;  (+getAmp() / 2 for loops)

    delta = oa / N;
    cp = cos(delta);        sp = sin(delta);
    cp2 = cos(delta / 2);   sp2 = sin(delta / 2);

    moveTo(r, 0);

    for (int j = 1; j <= N; j++) {
        thetaj = (j - 1) * delta;
        A = -A;

        cs = cos(thetaj);   sn = sin(thetaj);

        beta = r * oa / pi / A / N;
        tt = (sp - cp * beta) / (cp + sp * beta);
        amp1 = (8 * (r + A) * (beta * cp2 - sp2)
                - (beta * (4 + cp) + 3 * tt * cp - 4 * sp) * r)
                / (3 * (beta - tt));

        x1 = (8 * (r + A) * cp2 - (1 + cp) * r) / 3 - amp1;
        y1 = (x1 - r) * beta;
        x2 = amp1;
        y2 = (amp1 - r * cp) * tt + r * sp;
        x3 = r * cp;
        y3 = r * sp;

        curveTo(x1 * cs - y1 * sn, x1 * sn + y1 * cs,
                x2 * cs - y2 * sn, x2 * sn + y2 * cs,
                x3 * cs - y3 * sn, x3 * sn + y3 * cs);
    }
\end{verbatim}

\end{document}
