%% examples/optics-complete-ray-diagrams.tex
%%
%% Lens panels use Snell-law ray tracing for n=1.50 at both interfaces.
%% Mirror panels show the usual paraxial construction.

\documentclass[tikz, border=6mm]{standalone}
\usepackage{tikzphysics}

\begin{document}
\begin{tikzpicture}[
  ray/.style={red!75!black, very thick, ->},
  extension/.style={red!55!black, densely dashed},
  axis/.style={gray, densely dashed},
  every label/.style={font=\scriptsize},
  title/.style={font=\small\bfseries}
]
  %% Converging lens: R=3cm, edge thickness=.2cm, aperture=25deg,
  %% and n(lens)/n(air)=1.50.  The exit coordinates and focus below are
  %% obtained by applying Snell's law at both circular interfaces.
  \begin{scope}[xshift=0cm,yshift=0cm]
    \draw[axis] (-3.6,0) -- (3.6,0);
    \coordinate[label=below:$F$] (LF) at (2.93841,0);
    \fill (LF) circle (1.2pt);
    \node[convex-lens, convex lens radius=3cm,
          convex lens thickness=0.2cm,
          convex lens aperture angle=25] (L) at (0,0) {};
    \coordinate (Lexitlow) at ($(L.center)+(0.29194,-0.72588)$);
    \coordinate (Lexithigh) at ($(L.center)+(0.29194,0.72588)$);
    \draw[ray] ($(L.20)+(-3,0)$) -- (L.20) -- (Lexitlow) -- (LF);
    \draw[ray] ($(L.50)+(-3,0)$) -- (L.50) -- (L.back-50) -- (LF);
    \draw[ray] ($(L.80)+(-3,0)$) -- (L.80) -- (Lexithigh) -- (LF);
    \node[title] at (0,1.75) {Convex lens, $n=1.50$};
  \end{scope}

  %% Diverging lens with the same R, centre thickness, aperture, and index.
  \begin{scope}[xshift=8.5cm,yshift=0cm]
    \draw[axis] (-3.6,0) -- (3.6,0);
    \coordinate[label=below:$F$] (DF) at (-2.54285,0);
    \fill (DF) circle (1.2pt);
    \node[concave-lens, concave lens radius=3cm,
          concave lens thickness=0.2cm,
          concave lens aperture angle=25] (D) at (0,0) {};
    \coordinate (Dexitlow) at ($(D.center)+(0.21232,-0.81319)$);
    \coordinate (Dexithigh) at ($(D.center)+(0.21232,0.81319)$);
    \draw[extension] (DF) -- (Dexitlow);
    \draw[extension] (DF) -- (Dexithigh);
    \draw[ray] ($(D.20)+(-3,0)$) -- (D.20) -- (Dexitlow)
      -- ($(DF)!2.25!(Dexitlow)$);
    \draw[ray] ($(D.50)+(-3,0)$) -- (D.50) -- (D.back-50) -- (3.4,0);
    \draw[ray] ($(D.80)+(-3,0)$) -- (D.80) -- (Dexithigh)
      -- ($(DF)!2.25!(Dexithigh)$);
    \node[title] at (0,1.75) {Concave lens, $n=1.50$};
  \end{scope}

  %% Concave mirror: parallel rays return through a real focus.
  \begin{scope}[xshift=0cm,yshift=-5.5cm]
    \draw[axis] (-3.6,0) -- (3.6,0);
    \coordinate[label=below:$F$] (MF) at (-2.5,0);
    \fill (MF) circle (1.2pt);
    \node[concave-mirror, mirror radius=5cm,
          mirror thickness=0.22cm,
          mirror aperture angle=22] (M) at (0,0) {};
    \draw[ray] ($(M.20)+(-3,0)$) -- (M.20) -- (MF);
    \draw[ray] ($(M.50)+(-3,0)$) -- (M.50) -- (MF);
    \draw[ray] ($(M.80)+(-3,0)$) -- (M.80) -- (MF);
    \node[title] at (0,2.15) {Concave mirror (paraxial)};
  \end{scope}

  %% Convex mirror: reflected rays diverge from a virtual focus.
  \begin{scope}[xshift=8.5cm,yshift=-5.5cm]
    \draw[axis] (-3.6,0) -- (3.6,0);
    \coordinate[label=below:$F$] (VMF) at (2.5,0);
    \fill (VMF) circle (1.2pt);
    \node[convex-mirror, mirror radius=5cm,
          mirror thickness=0.22cm,
          mirror aperture angle=22] (VM) at (0,0) {};
    \draw[extension] (VM.20) -- (VMF);
    \draw[extension] (VM.80) -- (VMF);
    \draw[ray] ($(VM.20)+(-3,0)$) -- (VM.20)
      -- ($(VMF)!2.15!(VM.20)$);
    \draw[ray] ($(VM.50)+(-3,0)$) -- (VM.50) -- (-3.4,0);
    \draw[ray] ($(VM.80)+(-3,0)$) -- (VM.80)
      -- ($(VMF)!2.15!(VM.80)$);
    \node[title] at (0,2.15) {Convex mirror (paraxial)};
  \end{scope}
\end{tikzpicture}
\end{document}
