%%Author: Justin Cawood
%%License: LPPL 1.3c
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{simpleoptics}[2019/09/07 v1.1.1 Simple Optics Package]
\RequirePackage{tikz}
\newcommand{\straightline}[4]{
\draw (#1, #2) -- (#3, #4);
}
%\mirror{x}{y}{focal length}{height}
\newcommand{\mirror}[4]{
\pgfmathsetmacro{\mirrorX}{#1}
\pgfmathsetmacro{\mirrorY}{#2}
\pgfmathsetmacro{\mirrorRadius}{2*#3}
\pgfmathsetmacro{\mirrorHeight}{#4}
\pgfmathsetmacro{\startAngle}{asin(\mirrorHeight/\mirrorRadius)}
\begin{scope}[yshift=\mirrorY cm]
\draw (\mirrorX,\mirrorHeight) arc[start angle=180-\startAngle,delta angle=2*\startAngle,radius=\mirrorRadius];
\end{scope}
}
%\lens{x}{y}{focal length}{height}{thickness}
\newcommand{\lens}[5]{
\pgfmathsetmacro{\lensX}{#1}
\pgfmathsetmacro{\lensY}{#2}
\pgfmathsetmacro{\lensRadius}{2*#3}
\pgfmathsetmacro{\lensHeight}{#4}
\pgfmathsetmacro{\lensThickness}{#5}
\pgfmathsetmacro{\lensXright}{\lensX +(0.5*\lensThickness)}
\pgfmathsetmacro{\lensXleft}{\lensX-(0.5*\lensThickness)}
\mirror{\lensXleft}{\lensY}{\lensRadius}{\lensHeight}
\mirror{\lensXright}{\lensY}{-\lensRadius}{\lensHeight}
\begin{scope}[yshift=\lensY cm]
\straightline{\lensXleft}{\lensHeight}{\lensXright}{\lensHeight}
\straightline{\lensXright}{-\lensHeight}{\lensXleft}{-\lensHeight}
\end{scope}
}
%\biconvexlens{x}{y}{focal length}{height}{thickness}
\newcommand{\biconvexlens}[5]{
\lens{#1}{#2}{#3}{#4}{#5}
}
%\biconcavelens{x}{y}{focal length}{height}{thickness}
\newcommand{\biconcavelens}[5]{
\lens{#1}{#2}{-#3}{#4}{#5}
}
%\concaveconvexlens{x}{y}{focal length}{height}{thickness}
\newcommand{\concaveconvexlens}[5]{
\pgfmathsetmacro{\lensX}{#1}
\pgfmathsetmacro{\lensY}{#2}
\pgfmathsetmacro{\lensRadius}{-2*#3}
\pgfmathsetmacro{\lensHeight}{#4}
\pgfmathsetmacro{\lensThickness}{#5}
\pgfmathsetmacro{\lensXright}{\lensX +(0.5*\lensThickness)}
\pgfmathsetmacro{\lensXleft}{\lensX-(0.5*\lensThickness)}
\mirror{\lensXleft}{\lensY}{\lensRadius}{\lensHeight}
\mirror{\lensXright}{\lensY}{\lensRadius}{\lensHeight}
\begin{scope}[yshift=\lensY cm]
\straightline{\lensXleft}{\lensHeight}{\lensXright}{\lensHeight}
\straightline{\lensXright}{-\lensHeight}{\lensXleft}{-\lensHeight}
\end{scope}
}
%\convexconcavelens{x}{y}{focal length}{height}{thickness}
\newcommand{\convexconcavelens}[5]{
\concaveconvexlens{#1}{#2}{-#3}{#4}{#5}
}
%\rightplanoconvexlens{x}{y}{focal length}{height}{thickness}
\newcommand{\rightplanoconvexlens}[5]{
\pgfmathsetmacro{\lensX}{#1}
\pgfmathsetmacro{\lensY}{#2}
\pgfmathsetmacro{\lensRadius}{2*#3}
\pgfmathsetmacro{\lensHeight}{#4}
\pgfmathsetmacro{\lensThickness}{#5}
\pgfmathsetmacro{\lensXright}{\lensX +(0.5*\lensThickness)}
\pgfmathsetmacro{\lensXleft}{\lensX-(0.5*\lensThickness)}
\mirror{\lensXleft}{\lensY}{\lensRadius}{\lensHeight}
\begin{scope}[yshift=\lensY cm]
\straightline{\lensXleft}{\lensHeight}{\lensXright}{\lensHeight}
\straightline{\lensXright}{-\lensHeight}{\lensXleft}{-\lensHeight}
\straightline{\lensXright}{\lensHeight}{\lensXright}{-\lensHeight}
\end{scope}
}
%\leftplanoconvexlens{x}{y}{focal length}{height}{thickness}
\newcommand{\leftplanoconvexlens}[5]{
\pgfmathsetmacro{\lensX}{#1}
\pgfmathsetmacro{\lensY}{#2}
\pgfmathsetmacro{\lensRadius}{2*#3}
\pgfmathsetmacro{\lensHeight}{#4}
\pgfmathsetmacro{\lensThickness}{#5}
\pgfmathsetmacro{\lensXright}{\lensX +(0.5*\lensThickness)}
\pgfmathsetmacro{\lensXleft}{\lensX-(0.5*\lensThickness)}
\mirror{\lensXright}{\lensY}{-\lensRadius}{\lensHeight}
\begin{scope}[yshift=\lensY cm]
\straightline{\lensXleft}{\lensHeight}{\lensXright}{\lensHeight}
\straightline{\lensXright}{-\lensHeight}{\lensXleft}{-\lensHeight}
\straightline{\lensXleft}{\lensHeight}{\lensXleft}{-\lensHeight}
\end{scope}
}
%\rightplanoconcavelens{x}{y}{focal length}{height}{thickness}
\newcommand{\rightplanoconcavelens}[5]{
\rightplanoconvexlens{#1}{#2}{-#3}{#4}{#5}
}
%\leftplanoconcavelens{x}{y}{focal length}{height}{thickness}
\newcommand{\leftplanoconcavelens}[5]{
\leftplanoconvexlens{#1}{#2}{-#3}{#4}{#5}
}