Debian Codegraph @

texmf-dist/tex/latex/simpleoptics/simpleoptics.sty

raw
1 %%Author: Justin Cawood
2 %%License: LPPL 1.3c
3
4 \NeedsTeXFormat{LaTeX2e}
5 \ProvidesPackage{simpleoptics}[2019/09/07 v1.1.1 Simple Optics Package]
6 \RequirePackage{tikz}
7
8 \newcommand{\straightline}[4]{
9 \draw (#1, #2) -- (#3, #4);
10 }
11
12 %\mirror{x}{y}{focal length}{height}
13 \newcommand{\mirror}[4]{
14
15
16 \pgfmathsetmacro{\mirrorX}{#1}
17 \pgfmathsetmacro{\mirrorY}{#2}
18
19 \pgfmathsetmacro{\mirrorRadius}{2*#3}
20 \pgfmathsetmacro{\mirrorHeight}{#4}
21
22 \pgfmathsetmacro{\startAngle}{asin(\mirrorHeight/\mirrorRadius)}
23
24
25 \begin{scope}[yshift=\mirrorY cm]
26 \draw (\mirrorX,\mirrorHeight) arc[start angle=180-\startAngle,delta angle=2*\startAngle,radius=\mirrorRadius];
27 \end{scope}
28 }
29
30 %\lens{x}{y}{focal length}{height}{thickness}
31 \newcommand{\lens}[5]{
32
33
34 \pgfmathsetmacro{\lensX}{#1}
35 \pgfmathsetmacro{\lensY}{#2}
36 \pgfmathsetmacro{\lensRadius}{2*#3}
37 \pgfmathsetmacro{\lensHeight}{#4}
38 \pgfmathsetmacro{\lensThickness}{#5}
39
40 \pgfmathsetmacro{\lensXright}{\lensX +(0.5*\lensThickness)}
41 \pgfmathsetmacro{\lensXleft}{\lensX-(0.5*\lensThickness)}
42
43 \mirror{\lensXleft}{\lensY}{\lensRadius}{\lensHeight}
44 \mirror{\lensXright}{\lensY}{-\lensRadius}{\lensHeight}
45
46 \begin{scope}[yshift=\lensY cm]
47 \straightline{\lensXleft}{\lensHeight}{\lensXright}{\lensHeight}
48 \straightline{\lensXright}{-\lensHeight}{\lensXleft}{-\lensHeight}
49 \end{scope}
50 }
51
52 %\biconvexlens{x}{y}{focal length}{height}{thickness}
53 \newcommand{\biconvexlens}[5]{
54 \lens{#1}{#2}{#3}{#4}{#5}
55 }
56
57 %\biconcavelens{x}{y}{focal length}{height}{thickness}
58 \newcommand{\biconcavelens}[5]{
59 \lens{#1}{#2}{-#3}{#4}{#5}
60 }
61
62 %\concaveconvexlens{x}{y}{focal length}{height}{thickness}
63 \newcommand{\concaveconvexlens}[5]{
64 \pgfmathsetmacro{\lensX}{#1}
65 \pgfmathsetmacro{\lensY}{#2}
66 \pgfmathsetmacro{\lensRadius}{-2*#3}
67 \pgfmathsetmacro{\lensHeight}{#4}
68 \pgfmathsetmacro{\lensThickness}{#5}
69
70 \pgfmathsetmacro{\lensXright}{\lensX +(0.5*\lensThickness)}
71 \pgfmathsetmacro{\lensXleft}{\lensX-(0.5*\lensThickness)}
72
73 \mirror{\lensXleft}{\lensY}{\lensRadius}{\lensHeight}
74 \mirror{\lensXright}{\lensY}{\lensRadius}{\lensHeight}
75
76 \begin{scope}[yshift=\lensY cm]
77 \straightline{\lensXleft}{\lensHeight}{\lensXright}{\lensHeight}
78 \straightline{\lensXright}{-\lensHeight}{\lensXleft}{-\lensHeight}
79 \end{scope}
80 }
81
82 %\convexconcavelens{x}{y}{focal length}{height}{thickness}
83 \newcommand{\convexconcavelens}[5]{
84 \concaveconvexlens{#1}{#2}{-#3}{#4}{#5}
85 }
86
87 %\rightplanoconvexlens{x}{y}{focal length}{height}{thickness}
88 \newcommand{\rightplanoconvexlens}[5]{
89 \pgfmathsetmacro{\lensX}{#1}
90 \pgfmathsetmacro{\lensY}{#2}
91 \pgfmathsetmacro{\lensRadius}{2*#3}
92 \pgfmathsetmacro{\lensHeight}{#4}
93 \pgfmathsetmacro{\lensThickness}{#5}
94
95 \pgfmathsetmacro{\lensXright}{\lensX +(0.5*\lensThickness)}
96 \pgfmathsetmacro{\lensXleft}{\lensX-(0.5*\lensThickness)}
97
98 \mirror{\lensXleft}{\lensY}{\lensRadius}{\lensHeight}
99
100 \begin{scope}[yshift=\lensY cm]
101 \straightline{\lensXleft}{\lensHeight}{\lensXright}{\lensHeight}
102 \straightline{\lensXright}{-\lensHeight}{\lensXleft}{-\lensHeight}
103 \straightline{\lensXright}{\lensHeight}{\lensXright}{-\lensHeight}
104 \end{scope}
105 }
106
107 %\leftplanoconvexlens{x}{y}{focal length}{height}{thickness}
108 \newcommand{\leftplanoconvexlens}[5]{
109 \pgfmathsetmacro{\lensX}{#1}
110 \pgfmathsetmacro{\lensY}{#2}
111 \pgfmathsetmacro{\lensRadius}{2*#3}
112 \pgfmathsetmacro{\lensHeight}{#4}
113 \pgfmathsetmacro{\lensThickness}{#5}
114
115 \pgfmathsetmacro{\lensXright}{\lensX +(0.5*\lensThickness)}
116 \pgfmathsetmacro{\lensXleft}{\lensX-(0.5*\lensThickness)}
117
118 \mirror{\lensXright}{\lensY}{-\lensRadius}{\lensHeight}
119
120 \begin{scope}[yshift=\lensY cm]
121 \straightline{\lensXleft}{\lensHeight}{\lensXright}{\lensHeight}
122 \straightline{\lensXright}{-\lensHeight}{\lensXleft}{-\lensHeight}
123 \straightline{\lensXleft}{\lensHeight}{\lensXleft}{-\lensHeight}
124 \end{scope}
125 }
126
127 %\rightplanoconcavelens{x}{y}{focal length}{height}{thickness}
128 \newcommand{\rightplanoconcavelens}[5]{
129 \rightplanoconvexlens{#1}{#2}{-#3}{#4}{#5}
130 }
131
132 %\leftplanoconcavelens{x}{y}{focal length}{height}{thickness}
133 \newcommand{\leftplanoconcavelens}[5]{
134 \leftplanoconvexlens{#1}{#2}{-#3}{#4}{#5}
135 }