Debian Codegraph @

texmf-dist/tex/latex/tikz-optics/tikzlibraryoptics.code.tex

raw
1 \iffalse
2 The tikzoptics library
3
4 Copyright (C) 2013-2016 by
5 Michel Fruchart <[email protected]>
6
7 This work may be distributed and/or modified under the conditions of
8 the LaTeX Project Public License (LPPL), version 1.3c, which can be
9 found at the address:
10 https://www.latex-project.org/lppl/lppl-1-3c/
11
12 Alternatively, it may be distributed and/or modified under the conditions of
13 the GNU General Public License (GNU GPL), version 2, which can be found
14 at the address:
15 https://www.gnu.org/licenses/gpl-2.0.en.html
16 or any later version published by the Free Software Foundation.
17 \fi
18 \makeatletter
19
20
21 \def\tikzopticsversion{0.2.3}
22 \def\tikzopticsversiondate{2017-03-11}
23
24
25 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26 % errors from this library
27 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28 \def\opticserror#1{\pgfutil@packageerror{tikz/optics}{#1}{}}
29
30
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32 % handler |collect unknowns|
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34 % from http://tex.stackexchange.com/questions/81821/filtering-options-with-pgfkeys/81985#81985
35 % used by /tikz/optics/->n-
36 %
37 \pgfkeys{
38 /handlers/.collect unknowns/.style = {
39 unknown options/.initial = {},
40 .unknown/.code = {%
41 \letcs\reserved{pgfk@\pgfkeyscurrentpath/unknown options}%
42 \csedef{pgfk@\pgfkeyscurrentpath/unknown options}{%
43 \ifx\reserved\empty\else\expandonce\reserved,\fi
44 \expandonce\pgfkeyscurrentname
45 \ifx\pgfkeysnovalue##1\else=\expandonce\pgfkeyscurrentvalue\fi
46 }%
47 }
48 }
49 }
50
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 % defining |optics| family
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54
55 \pgfkeys{
56 /tikz/.cd,
57 optics/.is family,
58 optics/.search also={/tikz},
59 }
60
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62 % [use optics]
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 \pgfkeys{
65 /tikz/use optics/.append code={
66 \pgfkeys{
67 /tikz/.cd,
68 % shapes
69 % FIXME il ne devrait pas y avoir de logique (ni de valeurs par défaut) ici, seulement l'export dans l'espace de nom commun
70 lens/.prefix style={shape=lens,optics,draw},
71 slit/.prefix style={shape=slit,optics,draw},
72 double slit/.prefix style={shape=double slit,optics,draw},
73 thin optics element/.prefix style={shape=thin optics element,optics,draw},
74 polarizer/.prefix style={shape=polarizer,optics,draw,object aspect ratio=0.1},
75 generic optics io/.prefix style={shape=generic optics io,optics,draw},
76 sensor/.prefix style={shape=sensor,optics,object aspect ratio=1,draw},
77 sensor line/.prefix style={shape=sensor line,optics,draw},
78 mirror/.prefix style={shape=mirror,optics,draw},
79 spherical mirror/.prefix style={shape=spherical mirror,optics,draw},
80 thick optics element/.prefix style={shape=thick optics element,optics,draw,object aspect ratio=0.1},
81 heat filter/.prefix style={shape=thick optics element,optics,draw, object aspect ratio=0.05},
82 double amici prism/.prefix style={shape=double amici prism,optics,draw, prism height=1cm, prism apex angle=60},
83 % styles
84 screen/.prefix style={optics,/tikz/optics/screen},
85 diffraction grating/.style={optics,/tikz/optics/diffraction grating},
86 grid/.style={optics, /tikz/optics/grid},
87 semi-transparent mirror/.style={optics, /tikz/optics/semi-transparent mirror},
88 diaphragm/.style={optics, /tikz/optics/diaphragm},
89 beam splitter/.prefix style={optics,/tikz/optics/beam splitter},
90 generic lamp/.prefix style={optics,/tikz/optics/generic lamp},
91 generic sensor/.prefix style={optics,/tikz/optics/generic sensor},
92 halogen lamp/.prefix style={optics,/tikz/optics/halogen lamp},
93 spectral lamp/.prefix style={optics,/tikz/optics/spectral lamp},
94 laser/.prefix style={optics,/tikz/optics/laser},
95 laser'/.prefix style={optics,/tikz/optics/laser'},
96 concave mirror/.prefix style={optics, /tikz/optics/concave mirror},
97 convex mirror/.prefix style={optics, /tikz/optics/convex mirror},
98 % arrows (styles)
99 ->-/.prefix style={optics,/tikz/optics/->-={##1}},
100 -<-/.prefix style={optics,/tikz/optics/-<-={##1}},
101 ->>-/.prefix style={optics,/tikz/optics/->>-={##1}},
102 -<<-/.prefix style={optics,/tikz/optics/-<<-={##1}},
103 ->>>-/.prefix style={optics,/tikz/optics/->>>-={##1}},
104 -<<<-/.prefix style={optics,/tikz/optics/-<<<-={##1}},
105 ->>>>-/.prefix style={optics,/tikz/optics/->>>>-={##1}},
106 -<<<<-/.prefix style={optics,/tikz/optics/-<<<<-={##1}},
107 ->n-/.prefix style={optics,/tikz/optics/->n-={##1}},
108 -<n-/.prefix style={optics,/tikz/optics/-<n-={##1}},
109 }
110 }
111 }
112
113 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114 % We need some existing tikz libraries and tex packages.
115 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116 \usetikzlibrary{decorations,decorations.markings, decorations.pathreplacing}
117 \usepackage{etoolbox}
118
119
120 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121 % Key |object height|
122 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
123
124 \pgfkeys{/tikz/optics/.cd,
125 object height/.initial=2cm,
126 }
127
128 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
129 % Shape [thin optics element]
130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 \pgfdeclareshape{thin optics element}
132 {
133 \savedanchor{\center}{
134 \pgfpointorigin
135 }
136 \anchor{center}{\center}
137
138 \savedmacro\objectHeight{%
139 \edef\objectHeight{\pgfkeysvalueof{/tikz/optics/object height}}%
140 }
141
142 \savedanchor{\north}{
143 \pgf@x=0cm%
144 \pgf@y=\objectHeight%
145 \pgf@y=0.5\pgf@y%
146 }
147 \anchor{north}{\north}
148
149 \savedanchor{\south}{
150 \pgf@x=0cm%
151 \pgf@y=\objectHeight%
152 \pgf@y=-0.5\pgf@y%
153 }
154 \anchor{south}{\south}
155
156 \anchor{east}{\center}
157 \anchor{west}{\center}
158
159 \anchorborder{%
160 \pgf@xb=\pgf@x% xb/yb is target
161 \pgf@yb=\pgf@y%
162 \south%
163 \pgf@xa=\pgf@x% xa/ya is se
164 \pgf@ya=\pgf@y%
165 \north%
166 \advance\pgf@x by-\pgf@xa%
167 \advance\pgf@y by-\pgf@ya%
168 \pgf@xc=.5\pgf@x% x/y is half width/height
169 \pgf@yc=.5\pgf@y%
170 \advance\pgf@xa by\pgf@xc% xa/ya becomes center
171 \advance\pgf@ya by\pgf@yc%
172 \edef\pgf@marshal{%
173 \noexpand\pgfpointborderrectangle
174 {\noexpand\pgfpoint{\the\pgf@xb}{\the\pgf@yb}}
175 {\noexpand\pgfpoint{\the\pgf@xc}{\the\pgf@yc}}%
176 }%
177 \pgf@process{\pgf@marshal}%
178 \advance\pgf@x by\pgf@xa%
179 \advance\pgf@y by\pgf@ya%
180 }
181
182 \backgroundpath
183 {
184 \north \pgf@xa=\pgf@x \pgf@ya=\pgf@y
185 \south \pgf@xb=\pgf@x \pgf@yb=\pgf@y
186
187 \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
188 \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
189 }
190 }
191
192
193 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
194 % Shape [lens]
195 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
196 \newif\iftikz@optics@lens@converging
197 \tikz@optics@lens@convergingtrue
198
199 % keys
200 % - focal lens is used to define anchors |east focus| and |west focus|
201 % - lens height is used to define anchors |lens north| and |lens south|
202 % - lens type (converging or diverging)
203 \pgfkeys{/tikz/optics/.cd,
204 focal length/.initial=1cm,
205 lens height/.initial=0.8,
206 lens type/.is choice,
207 lens type/converging/.code={\tikz@optics@lens@convergingtrue},
208 lens type/diverging/.code={\tikz@optics@lens@convergingfalse}
209 }
210 \pgfdeclareshape{lens}
211 {
212 \savedanchor{\center}{
213 \pgfpointorigin
214 }
215 \anchor{center}{\center}
216
217 \savedmacro\focalLength{%
218 \edef\focalLength{\pgfkeysvalueof{/tikz/optics/focal length}}%
219 }
220
221 \savedmacro\objectHeight{%
222 \edef\objectHeight{\pgfkeysvalueof{/tikz/optics/object height}}%
223 }
224
225 \savedmacro\lensHeight{%
226 \pgfmathparse{\pgfkeysvalueof{/tikz/optics/lens height}}%
227 \ifpgfmathunitsdeclared%
228 \pgfmathsetlengthmacro{\lensHeight}{\pgfkeysvalueof{/tikz/optics/lens height}}%
229 \else%
230 \pgfmathsetlengthmacro{\lensHeight}{\pgfkeysvalueof{/tikz/optics/lens height}*\pgfkeysvalueof{/tikz/optics/object height}}%
231 \fi%
232 }
233
234 \savedanchor{\lensnorth}{
235 \pgfpointorigin
236 \pgf@y=\lensHeight%
237 \pgf@y=0.5\pgf@y%
238 }
239 \anchor{lens north}{\lensnorth}
240
241 \savedanchor{\lenssouth}{
242 \pgfpointorigin
243 \pgf@y=\lensHeight%
244 \pgf@y=-0.5\pgf@y%
245 }
246 \anchor{lens south}{\lenssouth}
247
248 \savedanchor{\north}{
249 \pgf@x=0cm%
250 \pgf@y=\objectHeight%
251 \pgf@y=0.5\pgf@y%
252 }
253 \anchor{north}{\north}
254
255 \savedanchor{\south}{
256 \pgf@x=0cm%
257 \pgf@y=\objectHeight%
258 \pgf@y=-0.5\pgf@y%
259 }
260 \anchor{south}{\south}
261
262 \savedanchor{\eastfocal}{
263 \pgf@x=\focalLength%
264 \pgf@y=0cm%
265 }
266 \anchor{east focal point}{\eastfocal}
267 \anchor{east focus}{\eastfocal}
268
269
270 \savedanchor{\westfocal}{
271 \pgf@x=-\focalLength%
272 \pgf@y=0cm%
273 }
274 \anchor{west focal point}{\westfocal}
275 \anchor{west focus}{\westfocal}
276
277 \anchor{east}{\center}
278 \anchor{west}{\center}
279
280 \inheritanchorborder[from=thin optics element]
281
282 \backgroundpath
283 {
284 \north \pgf@xb=\pgf@x \pgf@yb=\pgf@y
285 \south \pgf@xa=\pgf@x \pgf@ya=\pgf@y
286
287 \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
288 \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
289
290 \iftikz@optics@lens@converging
291 \pgfsetarrowsstart{lens arrow}
292 \pgfsetarrowsend{lens arrow}
293 \else
294 \pgfsetarrowsstart{lens arrow reversed}
295 \pgfsetarrowsend{lens arrow reversed}
296 \fi
297 }
298 }
299
300
301 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
302 % Shape [slit]
303 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
304 % keys : slit height
305 \pgfkeys{/tikz/optics/.cd,
306 slit height/.initial=0.1
307 }
308
309 \pgfdeclareshape{slit}
310 {
311 \savedanchor{\center}{
312 \pgfpointorigin
313 }
314 \anchor{center}{\center}
315 \anchor{slit center}{\center}
316 % TODO par cohérence ?
317
318 \savedmacro\objectHeight{%
319 \edef\objectHeight{\pgfkeysvalueof{/tikz/optics/object height}}%
320 }
321
322 \savedmacro\slitHeight{%
323 \pgfmathparse{\pgfkeysvalueof{/tikz/optics/slit height}}%
324 \ifpgfmathunitsdeclared%
325 \pgfmathsetlengthmacro{\slitHeight}{\pgfkeysvalueof{/tikz/optics/slit height}}%
326 \else%
327 \pgfmathsetlengthmacro{\slitHeight}{\pgfkeysvalueof{/tikz/optics/slit height}*\pgfkeysvalueof{/tikz/optics/object height}}%
328 \fi%
329 }
330
331 \savedanchor{\north}{
332 \pgf@x=0cm%
333 \pgf@y=\objectHeight%
334 \pgf@y=0.5\pgf@y%
335 }
336 \anchor{north}{\north}
337
338 \savedanchor{\south}{
339 \pgf@x=0cm%
340 \pgf@y=\objectHeight%
341 \pgf@y=-0.5\pgf@y%
342 }
343 \anchor{south}{\south}
344
345 \savedanchor{\slitnorth}{
346 \pgf@x=0cm%
347 \pgf@y=\slitHeight%
348 \pgf@y=0.5\pgf@y%
349 }
350 \anchor{slit north}{\slitnorth}
351
352 \savedanchor{\slitsouth}{
353 \pgf@x=0cm%
354 \pgf@y=\slitHeight%
355 \pgf@y=-0.5\pgf@y%
356 }
357 \anchor{slit south}{\slitsouth}
358
359 \anchor{east}{\center}
360 \anchor{west}{\center}
361
362 \inheritanchorborder[from=thin optics element]
363
364 \backgroundpath
365 {
366 % erreurs possibles dans la spécification du dessin
367 \pgfmathparse{notless(\slitHeight, \objectHeight)}
368 \ifnum\pgfmathresult=1
369 \opticserror{<slit height> should be strictly lower than <object height> (in slit)}
370 \fi
371 \north \pgf@xa=\pgf@x \pgf@ya=\pgf@y
372 \slitnorth \pgf@xb=\pgf@x \pgf@yb=\pgf@y
373 \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
374 \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
375
376 \south \pgf@xa=\pgf@x \pgf@ya=\pgf@y
377 \slitsouth \pgf@xb=\pgf@x \pgf@yb=\pgf@y
378 \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
379 \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
380 }
381 }
382
383
384
385
386 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
387 % Shape [double slit]
388 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
389 % keys :
390 % - slit height : (relative) height of the holes (each)
391 % - slit separation : (relative) distance between the centers of the holes
392 \pgfkeys{/tikz/optics/.cd,
393 object height/.initial=2cm,
394 slit height/.initial=0.075,
395 slit separation/.initial=0.2
396 }
397
398 \pgfdeclareshape{double slit}
399 {
400 \savedanchor{\center}{
401 \pgfpointorigin
402 }
403 \anchor{center}{\center}
404
405 \savedmacro\objectHeight{%
406 \edef\objectHeight{\pgfkeysvalueof{/tikz/optics/object height}}%
407 }
408
409 \savedmacro\slitHeight{%
410 \pgfmathparse{\pgfkeysvalueof{/tikz/optics/slit height}}%
411 \ifpgfmathunitsdeclared%
412 \pgfmathsetlengthmacro{\slitHeight}{\pgfkeysvalueof{/tikz/optics/slit height}}%
413 \else%
414 \pgfmathsetlengthmacro{\slitHeight}{\pgfkeysvalueof{/tikz/optics/slit height}*\pgfkeysvalueof{/tikz/optics/object height}}%
415 \fi%
416 }
417
418 \savedmacro\slitSeparation{%
419 \pgfmathparse{\pgfkeysvalueof{/tikz/optics/slit separation}}%
420 \ifpgfmathunitsdeclared%
421 \pgfmathsetlengthmacro{\slitSeparation}{\pgfkeysvalueof{/tikz/optics/slit separation}}%
422 \else%
423 \pgfmathsetlengthmacro{\slitSeparation}{\pgfkeysvalueof{/tikz/optics/slit separation}*\pgfkeysvalueof{/tikz/optics/object height}}%
424 \fi%
425 }
426
427 \savedmacro\macro@slitOneCenter{
428 \def\macro@slitOneCenter{
429 \pgfpointorigin
430 \pgf@ya=\slitSeparation
431 \pgf@ya=0.5\pgf@ya
432 \advance \pgf@y by \pgf@ya
433 }
434 }
435
436 \savedmacro\macro@slitTwoCenter{
437 \def\macro@slitTwoCenter{
438 \pgfpointorigin
439 \pgf@ya=\slitSeparation
440 \pgf@ya=-0.5\pgf@ya
441 \advance \pgf@y by \pgf@ya
442 }
443 }
444
445 \savedanchor{\north}{
446 \pgf@x=0cm%
447 \pgf@y=\objectHeight%
448 \pgf@y=0.5\pgf@y%
449 }
450 \anchor{north}{\north}
451
452 \savedanchor{\south}{
453 \pgf@x=0cm%
454 \pgf@y=\objectHeight%
455 \pgf@y=-0.5\pgf@y%
456 }
457 \anchor{south}{\south}
458
459 % slit 1
460 \savedanchor{\slitOneCenter}{
461 \macro@slitOneCenter
462 }
463 \anchor{slit 1 center}{\slitOneCenter}
464
465 \savedanchor{\slitOneNorth}{
466 \macro@slitOneCenter
467 \pgf@ya = \slitHeight
468 \pgf@ya = 0.5\pgf@ya
469 \advance \pgf@y by \pgf@ya
470 }
471 \anchor{slit 1 north}{\slitOneNorth}
472
473 \savedanchor{\slitOneSouth}{
474 \macro@slitOneCenter
475 \pgf@ya = \slitHeight
476 \pgf@ya = -0.5\pgf@ya
477 \advance \pgf@y by \pgf@ya
478 }
479 \anchor{slit 1 south}{\slitOneSouth}
480
481 % slit 2
482 \savedanchor{\slitTwoCenter}{
483 \macro@slitTwoCenter
484 }
485 \anchor{slit 2 center}{\slitTwoCenter}
486
487 \savedanchor{\slitTwoNorth}{
488 \macro@slitTwoCenter
489 \pgf@ya = \slitHeight
490 \pgf@ya = 0.5\pgf@ya
491 \advance \pgf@y by \pgf@ya
492 }
493 \anchor{slit 2 north}{\slitTwoNorth}
494
495 \savedanchor{\slitTwoSouth}{
496 \macro@slitTwoCenter
497 \pgf@ya = \slitHeight
498 \pgf@ya = -0.5\pgf@ya
499 \advance \pgf@y by \pgf@ya
500 }
501 \anchor{slit 2 south}{\slitTwoSouth}
502
503 \anchor{east}{\center}
504 \anchor{west}{\center}
505
506 \inheritanchorborder[from=thin optics element]
507
508 \backgroundpath
509 {
510 % erreurs possibles dans les spécifications du dessin
511 \pgfmathparse{notgreater(\slitSeparation, \slitHeight)}
512 \ifnum\pgfmathresult=1
513 \opticserror{<slit separation> should be strictly lower than <slit height> (in double slit)}
514 \fi
515 \pgfmathparse{notless(\slitSeparation+\slitHeight, \objectHeight)}
516 \ifnum\pgfmathresult=1
517 \opticserror{<slit height> plus <slit separation> should be strictly lower than <object height> (in double slit)}
518 \fi
519 \north \pgf@xa=\pgf@x \pgf@ya=\pgf@y
520 \slitOneNorth \pgf@xb=\pgf@x \pgf@yb=\pgf@y
521 \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
522 \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
523
524 \slitOneSouth \pgf@xa=\pgf@x \pgf@ya=\pgf@y
525 \slitTwoNorth \pgf@xb=\pgf@x \pgf@yb=\pgf@y
526 \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
527 \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
528
529 \slitTwoSouth \pgf@xa=\pgf@x \pgf@ya=\pgf@y
530 \south \pgf@xb=\pgf@x \pgf@yb=\pgf@y
531 \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
532 \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
533 }
534 }
535
536
537
538 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
539 % Shape [mirror]
540 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
541 % keys
542 % - mirror decoration separation
543 % - mirror decoration amplitude
544 \pgfkeys{/tikz/optics/.cd,
545 object height/.initial=2cm,
546 mirror decoration separation/.initial=0.15cm,
547 mirror decoration amplitude/.initial=0.125cm,
548 }
549
550 \pgfdeclareshape{mirror}
551 {
552 \savedanchor{\center}{
553 \pgfpointorigin
554 }
555 \anchor{center}{\center}
556
557 \savedmacro\objectHeight{%
558 \edef\objectHeight{\pgfkeysvalueof{/tikz/optics/object height}}%
559 }
560
561 \savedanchor{\north}{
562 \pgf@x=0cm%
563 \pgf@y=\objectHeight%
564 \pgf@y=0.5\pgf@y%
565 }
566 \anchor{north}{\north}
567
568 \savedanchor{\south}{
569 \pgf@x=0cm%
570 \pgf@y=\objectHeight%
571 \pgf@y=-0.5\pgf@y%
572 }
573 \anchor{south}{\south}
574
575 \anchor{east}{\center}
576 \anchor{west}{\center}
577
578 % bof
579 \inheritanchorborder[from=thin optics element]
580
581 \backgroundpath
582 {
583 \north \pgf@xa=\pgf@x \pgf@ya=\pgf@y
584 \south \pgf@xb=\pgf@x \pgf@yb=\pgf@y
585 % We use a border decoration to make a mirror (hachures).
586 % First set the decoration parameters :
587 % - decoration angle
588 % l'angle est 45-180 et on multiplie l'amplitude par -1 pour que la décoration commence et finisse par un trait (c'est un peu louche mais bon)
589 \def\pgfdecorationsegmentangle{45-180}%
590 % - decoration step length
591 \pgfmathparse{\pgfkeysvalueof{/tikz/optics/mirror decoration separation}}
592 \ifpgfmathunitsdeclared%
593 \pgfmathsetlengthmacro{\pgfdecorationsegmentlength}{\pgfkeysvalueof{/tikz/optics/mirror decoration separation}}%
594 \else%
595 \pgfmathsetlengthmacro{\pgfdecorationsegmentlength}{\pgfkeysvalueof{/tikz/optics/mirror decoration separation}*\pgfkeysvalueof{/tikz/optics/object height}}%
596 \fi%
597 % magouillons pour que \pgfdecorationsegmentlength soit un multiple de la longueur ...
598 \pgfmathsetmacro\initialstep{\pgfdecorationsegmentlength}
599 \pgfmathsetmacro\totallength{\pgfkeysvalueof{/tikz/optics/object height}}
600 \pgfmathsetmacro\newstep{\totallength/floor(\totallength/\initialstep)}
601 \pgfmathsetlengthmacro{\pgfdecorationsegmentlength}{\newstep}
602 % fin magouille
603 % - decoration amplitude
604 % on multiplie par -1 pour que ça aille dans le bon sens (pour éviter des problèmes louches)
605 \pgfmathparse{\pgfkeysvalueof{/tikz/optics/mirror decoration amplitude}}
606 \ifpgfmathunitsdeclared%
607 \pgfmathsetlengthmacro{\pgfdecorationsegmentamplitude}{-1*\pgfkeysvalueof{/tikz/optics/mirror decoration amplitude}}%
608 \else%
609 \pgfmathsetlengthmacro{\pgfdecorationsegmentamplitude}{-1*\pgfkeysvalueof{/tikz/optics/mirror decoration amplitude}*\pgfkeysvalueof{/tikz/optics/object height}}%
610 \fi%
611 % Use decoration.
612 \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
613 \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
614 \pgfdecoratecurrentpath{border} %
615 % dessin du miroir (trait)
616 \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
617 \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
618 }
619 }
620
621 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
622 % Shape [spherical mirror]
623 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
624 % keys :
625 % - spherical mirror angle : the aperture angle of the mirror
626 % - spherical mirror type (concave or convex)
627 % - spherical mirror orientation (ltr or rtl)
628 % The properties of the decoration are controled by the same parameters as in [mirror].
629 % Height is controled by |object height|, as usual.
630 \pgfkeys{/tikz/optics/spherical mirror angle/.initial=150}
631
632 \newif\iftikz@optics@sphericalmirror@concave
633 \tikz@optics@sphericalmirror@concavetrue
634 \pgfkeys{/tikz/optics/.cd,
635 spherical mirror type/.is choice,
636 spherical mirror type/concave/.code={\tikz@optics@sphericalmirror@concavetrue},
637 spherical mirror type/convex/.code={\tikz@optics@sphericalmirror@concavefalse}
638 }
639
640 \newif\iftikz@optics@sphericalmirror@ltr
641 \tikz@optics@sphericalmirror@ltrtrue
642 \pgfkeys{/tikz/optics/.cd,
643 spherical mirror orientation/.is choice,
644 spherical mirror orientation/ltr/.code={\tikz@optics@sphericalmirror@ltrtrue},
645 spherical mirror orientation/rtl/.code={\tikz@optics@sphericalmirror@ltrfalse}
646 }
647
648 % shortcuts (styles) : [concave mirror] and [convex mirror]
649 \pgfkeys{/tikz/optics/.cd,
650 concave mirror/.style={optics, spherical mirror, /tikz/optics/spherical mirror type=concave},
651 convex mirror/.style={optics, spherical mirror, /tikz/optics/spherical mirror type=convex},
652 }
653
654 \pgfdeclareshape{spherical mirror}{%
655 \savedmacro\installsphericalmirrorparameters{%
656 %
657 % Define a \centerpoint
658 %
659 \pgfextract@process\centerpoint{%
660 \pgfpointorigin
661 }%
662 %
663 % Define height
664 %
665 \pgfmathsetlengthmacro\height{\pgfkeysvalueof{/tikz/optics/object height}}%
666 %
667 % Function to define angle from radius
668 % use e.g. [spherical mirror angle=from_radius(2cm)] instead of e.g. [spherical mirror angle=90]
669 % This can seem somewhat ridiculous as we will undo this when calculating \radius, however it helps providing a simpler API.
670 % This function has to be defined before parsing \pgfkeysvalueof{/tikz/optics/spherical mirror angle}.
671 %
672 \pgfmathdeclarefunction{from_radius}{1}{
673 \begingroup
674 \pgfmathparse{notless(2*#1,\height)}
675 \ifnum\pgfmathresult=0
676 \opticserror{(in /tikz/optics/spherical mirror angle=from_radius(R)) : for a spherical mirror, the radius R cannot be smaller than half the height </tikz/optics/object height>. Set a bigger radius of a smaller height.}
677 \fi
678 \newdimen\angle
679 \pgfmathsetlength\angle{2*asin(\height/(2*#1))}
680 \pgf@x=\angle
681 \pgfmathreturn\pgf@x
682 \endgroup
683 }
684 %
685 % Define angle
686 %
687 \pgfmathsetmacro\angle{\pgfkeysvalueof{/tikz/optics/spherical mirror angle}}
688 %
689 % Compute radius from height and angle
690 %
691 \pgfmathsetlengthmacro\radius{\height/(2*sin(\angle/2))}
692 %
693 % Half of the sector angle is more useful.
694 %
695 \pgfmathmod{\angle}{360}%
696 \ifdim\pgfmathresult pt<0pt\relax%
697 \pgfmathadd@{\pgfmathresult}{360}%
698 \fi%
699 \let\angle\pgfmathresult%
700 \pgfmathdivide@{\pgfmathresult}{2}%
701 \let\halfangle\pgfmathresult%
702 %
703 % Get the start and end angles of the arc.
704 %
705 \iftikz@optics@sphericalmirror@concave
706 \iftikz@optics@sphericalmirror@ltr
707 \pgfmathsetmacro\startangle{-\halfangle}
708 \pgfmathsetmacro\endangle{+\halfangle}
709 \else
710 \pgfmathsetmacro\startangle{180-\halfangle}
711 \pgfmathsetmacro\endangle{180+\halfangle}
712 \fi
713 \else
714 \iftikz@optics@sphericalmirror@ltr
715 \pgfmathsetmacro\startangle{180-\halfangle}
716 \pgfmathsetmacro\endangle{180+\halfangle}
717 \else
718 \pgfmathsetmacro\startangle{-\halfangle}
719 \pgfmathsetmacro\endangle{+\halfangle}
720 \fi
721 \fi
722 %
723 % Calculate R cos(angle/2) and R sin(angle/2)
724 %
725 \pgfmathabs@{\halfangle}%
726 \pgfmathcos@{\pgfmathresult}%
727 \let\coshalfangle\pgfmathresult%
728 \pgfmathabs@{\halfangle}%
729 \pgfmathsin@{\pgfmathresult}%
730 \let\sinhalfangle\pgfmathresult%
731 \pgfmathsetlength\pgf@xa{\radius*\coshalfangle}
732 \edef\rcoshalfangle{\the\pgf@xa}%
733 \pgfmathsetlength\pgf@xa{\radius*\sinhalfangle}
734 \edef\rsinhalfangle{\the\pgf@xa}%
735 %
736 % Calculate the arc coordinates
737 %
738 \pgfextract@process\arcstart{%
739 \pgfqpointpolar{\startangle}{\radius}%
740 \pgf@xa\pgf@x%
741 \pgf@ya\pgf@y%
742 \centerpoint%
743 \advance\pgf@x\pgf@xa%
744 \advance\pgf@y\pgf@ya%
745 }%
746 \pgfextract@process\arcend{%
747 \pgfqpointpolar{\endangle}{\radius}%
748 \pgf@xa\pgf@x%
749 \pgf@ya\pgf@y%
750 \centerpoint%
751 \advance\pgf@x\pgf@xa%
752 \advance\pgf@y\pgf@ya%
753 }%
754 \def\convexrtlsetx#1#2{
755 \iftikz@optics@sphericalmirror@concave%
756 \iftikz@optics@sphericalmirror@ltr%
757 \advance\pgf@x by #1
758 \else% % => rtl
759 \advance\pgf@x by #2
760 \fi%
761 \else% % => convex
762 \iftikz@optics@sphericalmirror@ltr%
763 \advance\pgf@x by #2
764 \else% % => rtl
765 \advance\pgf@x by #1
766 \fi%
767 \fi%
768 }
769 \def\convexrtlinvert{%
770 \iftikz@optics@sphericalmirror@concave%
771 \iftikz@optics@sphericalmirror@ltr%
772 %nothing
773 \else% % => rtl
774 \pgf@x=-\pgf@x%
775 \fi%
776 \else% % => convex
777 \iftikz@optics@sphericalmirror@ltr%
778 \pgf@x=-\pgf@x%
779 \else% % => rtl
780 %nothing
781 \fi%
782 \fi%
783 }%
784 %
785 % Save everything.
786 % "NB \addtosavedmacro is currently experimental. May get changed." d'après le code où je l'ai piqué
787 %
788 \addtosavedmacro{\radius}%
789 %
790 \addtosavedmacro{\rcoshalfangle}%
791 \addtosavedmacro{\rsinhalfangle}%
792 %
793 \addtosavedmacro{\endangle}%
794 \addtosavedmacro{\startangle}%
795 %
796 \addtosavedmacro{\centerpoint}%
797 \addtosavedmacro{\arcstart}%
798 \addtosavedmacro{\arcend}%
799 \addtosavedmacro{\convexrtlinvert}%
800 %
801 }%
802 %
803 % Define anchors
804 %
805 \savedanchor\mirrorcenterpoint{%
806 \pgfpointorigin
807 }%
808 \savedanchor\centerpoint{%
809 \pgfpointorigin%
810 \advance\pgf@x by \radius%
811 \advance\pgf@x by \rcoshalfangle%
812 \iftikz@optics@sphericalmirror@concave%
813 \iftikz@optics@sphericalmirror@ltr%
814 %nothing
815 \else% % => rtl
816 \pgf@x=-\pgf@x%
817 \fi%
818 \else% % => convex
819 \iftikz@optics@sphericalmirror@ltr%
820 \pgf@x=-\pgf@x%
821 \else% % => rtl
822 %nothing
823 \fi%
824 \fi%
825 \divide\pgf@x by 2%
826 }%
827 \savedanchor\focalpoint{%
828 \pgfpointorigin%
829 \pgf@xa=\radius%
830 \advance\pgf@x by .5\pgf@xa%
831 \iftikz@optics@sphericalmirror@concave%
832 \iftikz@optics@sphericalmirror@ltr%
833 %nothing
834 \else% % => rtl
835 \pgf@x=-\pgf@x%
836 \fi%
837 \else% % => convex
838 \iftikz@optics@sphericalmirror@ltr%
839 \pgf@x=-\pgf@x%
840 \else% % => rtl
841 %nothing
842 \fi%
843 \fi%
844 }%
845 \savedanchor\north{%
846 \pgfpointorigin
847 \pgf@xa=0pt
848 \advance\pgf@xa by \rcoshalfangle
849 \advance\pgf@xa by \radius
850 \divide\pgf@xa by 2
851 \advance\pgf@x by \pgf@xa
852 \advance\pgf@y by \rsinhalfangle
853 \convexrtlinvert
854 }%
855 \savedanchor\arccenter{%
856 \centerpoint
857 \advance\pgf@x by \radius
858 \convexrtlinvert
859 }
860 \savedanchor\south{%
861 \pgfpointorigin
862 \pgf@xa=0pt
863 \advance\pgf@xa by \rcoshalfangle
864 \advance\pgf@xa by \radius
865 \divide\pgf@xa by 2
866 \advance\pgf@x by \pgf@xa
867 \advance\pgf@y by -\rsinhalfangle
868 \convexrtlinvert
869 }
870 \savedanchor\east{%
871 \pgfpointorigin
872 \convexrtlsetx{\radius}{\rcoshalfangle}
873 \convexrtlinvert
874 }
875 \savedanchor\west{%
876 \pgfpointorigin
877 \convexrtlsetx{\rcoshalfangle}{\radius}
878 \convexrtlinvert
879 }
880 \savedanchor\northwest{%
881 \pgfpointorigin
882 \convexrtlsetx{\rcoshalfangle}{\radius}
883 \advance\pgf@y by \rsinhalfangle
884 \convexrtlinvert
885 }
886 \savedanchor\southwest{%
887 \pgfpointorigin
888 \convexrtlsetx{\rcoshalfangle}{\radius}
889 \advance\pgf@y by -\rsinhalfangle
890 \convexrtlinvert
891 }
892 \savedanchor\northeast{%
893 \pgfpointorigin
894 \convexrtlsetx{\radius}{\rcoshalfangle}
895 \advance\pgf@y by \rsinhalfangle
896 \convexrtlinvert
897 }
898 \savedanchor\southeast{%
899 \pgfpointorigin
900 \convexrtlsetx{\radius}{\rcoshalfangle}
901 \advance\pgf@y by -\rsinhalfangle
902 \convexrtlinvert
903 }
904 \anchor{arc start}{%
905 \installsphericalmirrorparameters%
906 \arcstart%
907 }
908 \anchor{arc end}{%
909 \installsphericalmirrorparameters%
910 \arcend%
911 }
912 \anchor{focal point}{%
913 \installsphericalmirrorparameters%
914 \focalpoint
915 }
916 \anchor{focus}{%
917 \installsphericalmirrorparameters%
918 \focalpoint
919 }
920 \anchor{mirror center}{\mirrorcenterpoint}
921 \anchor{center}{\centerpoint}
922 \anchor{arc center}{\arccenter}
923 \anchor{north}{\north}%
924 \anchor{south}{\south}%
925 \anchor{east}{\east}%
926 \anchor{west}{\west}%
927 \anchor{north west}{\northwest}%
928 \anchor{south west}{\southwest}%
929 \anchor{north east}{\northeast}%
930 \anchor{south east}{\southeast}%
931 %
932 % Draw backgroundpath
933 %
934 \backgroundpath{%
935 \installsphericalmirrorparameters%
936 % We use a border decoration to make a mirror.
937 % First set the decoration parameters :
938 % - decoration angle
939 \iftikz@optics@sphericalmirror@concave
940 \def\pgfdecorationsegmentangle{45}%
941 \else
942 \def\pgfdecorationsegmentangle{-90-45}%
943 \fi
944 % - decoration step length
945 \pgfmathparse{\pgfkeysvalueof{/tikz/optics/mirror decoration separation}}
946 \ifpgfmathunitsdeclared%
947 \pgfmathsetlengthmacro{\pgfdecorationsegmentlength}{\pgfkeysvalueof{/tikz/optics/mirror decoration separation}}%
948 \else%
949 \pgfmathsetlengthmacro{\pgfdecorationsegmentlength}{\pgfkeysvalueof{/tikz/optics/mirror decoration separation}*\pgfkeysvalueof{/tikz/optics/object height}}%
950 \fi%
951 % magouillons pour que \pgfdecorationsegmentlength soit un multiple de la longueur ...
952 \pgfmathsetmacro\initialstep{\pgfdecorationsegmentlength}
953 \pgfmathsetmacro\totallength{(2*pi/360)*\angle*\radius}
954 \pgfmathsetmacro\newstep{\totallength/floor(\totallength/\initialstep)}
955 \pgfmathsetlengthmacro{\pgfdecorationsegmentlength}{\newstep}
956 % fin magouille
957 % - decoration amplitude
958 % on multiplie par -1 pour que ça aille dans le bon sens sans devoir modifier l'angle (pour éviter des problèmes louches)
959 \pgfmathparse{\pgfkeysvalueof{/tikz/optics/mirror decoration amplitude}}
960 \ifpgfmathunitsdeclared%
961 \pgfmathsetlengthmacro{\pgfdecorationsegmentamplitude}{-1*\pgfkeysvalueof{/tikz/optics/mirror decoration amplitude}}%
962 \else%
963 \pgfmathsetlengthmacro{\pgfdecorationsegmentamplitude}{-1*\pgfkeysvalueof{/tikz/optics/mirror decoration amplitude}*\pgfkeysvalueof{/tikz/optics/object height}}%
964 \fi%
965 % Now use decoration.
966 % Draw decoration of path : an arc of radius \radius from \arcstart to \arcend
967 \pgfpathmoveto{\arcstart}%
968 \pgfpatharc{\startangle}{\endangle}{\radius}%
969 \pgfdecoratecurrentpath{border} %
970 % Now draw the path.
971 \pgfpathmoveto{\arcstart}%
972 \pgfpatharc{\startangle}{\endangle}{\radius}%
973 }
974 %
975 % Anchor border
976 % This is needed for anchors .<angle> (like mirror.0, mirror.90, etc.) to work.
977 %
978 \anchorborder{%
979 % Save x and y
980 \edef\externalx{\the\pgf@x}%
981 \edef\externaly{\the\pgf@y}%
982 \installsphericalmirrorparameters%
983 % Use circular border
984 \pgfpointborderellipse{ \pgfpoint{\externalx}{\externaly} }{ \pgfpoint{\radius}{\radius} }%
985 }%
986 }
987
988
989
990 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
991 % Shape [thick optics element]
992 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
993 % keys :
994 % - object aspect ratio (alias : object width)
995 % ar = largeur/hauteur => largeur = ar * hauteur
996 \pgfkeys{/tikz/optics/.cd,
997 object aspect ratio/.initial=0.2,
998 object width/.style={/tikz/optics/object aspect ratio=#1}
999 }
1000
1001 \pgfdeclareshape{thick optics element}
1002 {
1003 \savedanchor{\center}{
1004 \pgfpointorigin
1005 }
1006 \anchor{center}{\center}
1007
1008 \savedmacro\objectHeight{%
1009 \edef\objectHeight{\pgfkeysvalueof{/tikz/optics/object height}}%
1010 }
1011
1012 \savedmacro\objectWidth{%
1013 \pgfmathparse{\pgfkeysvalueof{/tikz/optics/object aspect ratio}}
1014 \ifpgfmathunitsdeclared%
1015 \pgfmathsetlengthmacro{\objectWidth}{\pgfkeysvalueof{/tikz/optics/object aspect ratio}}%
1016 \else%
1017 \pgfmathsetlengthmacro{\objectWidth}{\pgfkeysvalueof{/tikz/optics/object aspect ratio}*\pgfkeysvalueof{/tikz/optics/object height}}%
1018 \fi%
1019 }
1020
1021 \savedanchor{\northeast}{
1022 \pgf@x=\objectWidth%
1023 \pgf@y=\objectHeight%
1024 \pgf@y=0.5\pgf@y%
1025 \pgf@x=0.5\pgf@x%
1026 }
1027 \anchor{north east}{\northeast}
1028
1029 \savedanchor{\southwest}{
1030 \pgf@x=\objectWidth%
1031 \pgf@y=\objectHeight%
1032 \pgf@y=-0.5\pgf@y%
1033 \pgf@x=-0.5\pgf@x%
1034 }
1035 \anchor{south west}{\southwest}
1036
1037 \anchor{north}{
1038 \center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1039 \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1040 \pgf@x=\pgf@xa
1041 \pgf@y=\pgf@yb
1042 }
1043
1044 \anchor{south}{
1045 \center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1046 \southwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1047 \pgf@x=\pgf@xa
1048 \pgf@y=\pgf@yb
1049 }
1050
1051 \anchor{east}{
1052 \center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1053 \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1054 \pgf@x=\pgf@xb
1055 \pgf@y=\pgf@ya
1056 }
1057
1058 \anchor{west}{
1059 \center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1060 \southwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1061 \pgf@x=\pgf@xb
1062 \pgf@y=\pgf@ya
1063 }
1064
1065 \anchor{north west}{
1066 \northeast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1067 \southwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1068 \pgf@x=\pgf@xb
1069 \pgf@y=\pgf@ya
1070 }
1071
1072 \anchor{south east}{
1073 \northeast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1074 \southwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1075 \pgf@x=\pgf@xa
1076 \pgf@y=\pgf@yb
1077 }
1078
1079 \inheritanchorborder[from=rectangle]
1080
1081 \backgroundpath
1082 {
1083 % rectangle
1084 \pgfpathrectanglecorners{\northeast}{\southwest}
1085 }
1086 }
1087
1088
1089
1090 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1091 % Shape [polarizer]
1092 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1093 \pgfdeclareshape{polarizer}
1094 {
1095 \savedanchor{\center}{
1096 \pgfpointorigin
1097 }
1098 \anchor{center}{\center}
1099
1100 \savedmacro\objectHeight{%
1101 \edef\objectHeight{\pgfkeysvalueof{/tikz/optics/object height}}%
1102 }
1103
1104 \savedmacro\objectWidth{%
1105 \pgfmathparse{\pgfkeysvalueof{/tikz/optics/object aspect ratio}}
1106 \ifpgfmathunitsdeclared%
1107 \pgfmathsetlengthmacro{\objectWidth}{\pgfkeysvalueof{/tikz/optics/object aspect ratio}}%
1108 \else%
1109 \pgfmathsetlengthmacro{\objectWidth}{\pgfkeysvalueof{/tikz/optics/object aspect ratio}*\pgfkeysvalueof{/tikz/optics/object height}}%
1110 \fi%
1111 }
1112
1113 \savedanchor{\northeast}{
1114 \pgf@x=\objectWidth%
1115 \pgf@y=\objectHeight%
1116 \pgf@y=0.5\pgf@y%
1117 \pgf@x=0.5\pgf@x%
1118 }
1119 \anchor{north east}{\northeast}
1120
1121 \savedanchor{\southwest}{
1122 \pgf@x=\objectWidth%
1123 \pgf@y=\objectHeight%
1124 \pgf@y=-0.5\pgf@y%
1125 \pgf@x=-0.5\pgf@x%
1126 }
1127 \anchor{south west}{\southwest}
1128
1129 \anchor{north}{
1130 \center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1131 \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1132 \pgf@x=\pgf@xa
1133 \pgf@y=\pgf@yb
1134 }
1135
1136 \anchor{south}{
1137 \center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1138 \southwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1139 \pgf@x=\pgf@xa
1140 \pgf@y=\pgf@yb
1141 }
1142
1143 \anchor{east}{
1144 \center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1145 \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1146 \pgf@x=\pgf@xb
1147 \pgf@y=\pgf@ya
1148 }
1149
1150 \anchor{west}{
1151 \center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1152 \southwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1153 \pgf@x=\pgf@xb
1154 \pgf@y=\pgf@ya
1155 }
1156
1157 \anchor{north west}{
1158 \northeast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1159 \southwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1160 \pgf@x=\pgf@xb
1161 \pgf@y=\pgf@ya
1162 }
1163
1164 \anchor{south east}{
1165 \northeast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1166 \southwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1167 \pgf@x=\pgf@xa
1168 \pgf@y=\pgf@yb
1169 }
1170
1171 \inheritanchorborder[from=rectangle]
1172
1173 \backgroundpath
1174 {
1175 % rectangle
1176 \pgfpathrectanglecorners{\northeast}{\southwest}
1177
1178 % diagonale du polariseur
1179 \northeast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1180 \southwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1181 \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
1182 \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
1183 }
1184 }
1185
1186 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1187 % Shape [double amici prism]
1188 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1189 % keys :
1190 % - prism height
1191 % - prism apex angle
1192 \pgfkeys{/tikz/optics/.cd,
1193 prism height/.initial=1.5cm,
1194 prism apex angle/.initial=60,
1195 }
1196 % Idea : we get
1197 % apexAngle
1198 % prismHeight
1199 % demiPrismWidth = tan(apexAngle/2)*prismHeight
1200 %
1201 % so we compute
1202 %
1203 % C = (0,0)
1204 % NE = (demiPrismWidth,0.5*prismHeight)
1205 % SW = (-2*demiPrismWidth,-0.5*prismHeight)
1206 % NW = (-demiPrismWidth,0.5*prismHeight)
1207 % SE = (2*demiPrismWidth,-0.5*prismHeight)
1208 %
1209 % N = (0,0.5*prismHeight)
1210 % S = (0,-0.5*prismHeight)
1211 % E = (3*0.5*demiPrismWidth,0)
1212 % W = (-3.0.5*demiPrismWidth,0)
1213 \pgfdeclareshape{double amici prism}
1214 {
1215 \savedanchor{\center}{
1216 \pgfpointorigin
1217 }
1218 \anchor{center}{\center}
1219
1220 \savedmacro\prismHeight{%
1221 \edef\prismHeight{\pgfkeysvalueof{/tikz/optics/prism height}}%
1222 }
1223
1224 \savedmacro\apexAngle{%
1225 \pgfmathsetlengthmacro{\apexAngle}{\pgfkeysvalueof{/tikz/optics/prism apex angle}}
1226 }
1227
1228 \savedmacro\demiPrismWidth{%
1229 \pgfmathsetlengthmacro{\demiPrismWidth}{tan(0.5*\pgfkeysvalueof{/tikz/optics/prism apex angle})*\pgfkeysvalueof{/tikz/optics/prism height}}
1230 }
1231
1232 \savedanchor{\northeast}{
1233 \pgf@x=\demiPrismWidth%
1234 \pgf@y=\prismHeight%
1235 \pgf@y=0.5\pgf@y%
1236 }
1237 \anchor{north east}{\northeast}
1238
1239 \savedanchor{\southwest}{
1240 \pgf@x=\demiPrismWidth%
1241 \pgf@y=\prismHeight%
1242 \pgf@x=-2\pgf@x%
1243 \pgf@y=-0.5\pgf@y%
1244 }
1245 \anchor{south west}{\southwest}
1246
1247 \savedanchor{\northwest}{
1248 \pgf@x=\demiPrismWidth%
1249 \pgf@y=\prismHeight%
1250 \pgf@x=-\pgf@x%
1251 \pgf@y=0.5\pgf@y%
1252 }
1253 \anchor{north west}{\northwest}
1254
1255 \savedanchor{\southeast}{
1256 \pgf@x=\demiPrismWidth%
1257 \pgf@y=\prismHeight%
1258 \pgf@x=2\pgf@x%
1259 \pgf@y=-0.5\pgf@y%
1260 }
1261 \anchor{south east}{\southeast}
1262
1263 \anchor{north}{
1264 \center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1265 \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1266 \pgf@x=\pgf@xa
1267 \pgf@y=\pgf@yb
1268 }
1269
1270 \savedanchor{\south}{
1271 \pgfpointorigin
1272 \pgf@y=\prismHeight%
1273 \pgf@y=-0.5\pgf@y%
1274 }
1275 \anchor{south}{\south}
1276
1277 \anchor{east}{
1278 \southeast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1279 \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1280 \pgf@x=\pgf@xa
1281 \advance\pgf@x by\pgf@xb
1282 \pgf@x=0.5\pgf@x
1283 \pgf@y=\pgf@ya
1284 \advance\pgf@y by\pgf@yb
1285 \pgf@y=0.5\pgf@y
1286 }
1287
1288 \anchor{west}{
1289 \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1290 \northwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1291 \pgf@x=\pgf@xa
1292 \advance\pgf@x by\pgf@xb
1293 \pgf@x=0.5\pgf@x
1294 \pgf@y=\pgf@ya
1295 \advance\pgf@y by\pgf@yb
1296 \pgf@y=0.5\pgf@y
1297 }
1298
1299 \inheritanchorborder[from=rectangle]
1300
1301 \backgroundpath
1302 {
1303 \northwest
1304 \pgfpathmoveto{\pgfpoint{\pgf@x}{\pgf@y}}
1305 \southwest
1306 \pgfpathlineto{\pgfpoint{\pgf@x}{\pgf@y}}
1307 \southeast
1308 \pgfpathlineto{\pgfpoint{\pgf@x}{\pgf@y}}
1309 \northeast
1310 \pgfpathlineto{\pgfpoint{\pgf@x}{\pgf@y}}
1311 \pgfpathclose
1312 %
1313 % FIXME : ceci devrait s'appliquer seulement au triangle intérieur -> un fgpath ou assimilé
1314 \pgfsetbeveljoin
1315 \northwest
1316 \pgfpathmoveto{\pgfpoint{\pgf@x}{\pgf@y}}
1317 \south
1318 \pgfpathlineto{\pgfpoint{\pgf@x}{\pgf@y}}
1319 \northeast
1320 \pgfpathlineto{\pgfpoint{\pgf@x}{\pgf@y}}
1321 }
1322 }
1323
1324
1325
1326
1327
1328
1329 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1330 % Shape [generic optics io]
1331 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1332 % keys :
1333 % - io body height : height of the body of the io body
1334 % - io body aspect ratio (alias io body width) : width/height of the body of the io body
1335 % - io aperture width : width of the output device (condenser, etc.) [in units of io body height]
1336 % - io aperture height : height of the output device (condenser, etc.) [in units of io body height]
1337 % - io aperture shift : vertical shift of the output device [in units of io body height]
1338 % - io orientation (ltr or rtl)
1339 \pgfkeys{/tikz/optics/.cd,
1340 io body height/.initial=0.75cm,
1341 io body aspect ratio/.initial=2,
1342 io aperture width/.initial=0.33,
1343 io aperture height/.initial=0.66,
1344 io aperture shift/.initial=0,
1345 }
1346 \pgfkeys{/tikz/optics/io body width/.style={/tikz/optics/io body aspect ratio=#1}}
1347 %
1348 \newif\if@tikz@optics@io@ltr
1349 \@tikz@optics@io@ltrtrue
1350 %
1351 \pgfkeys{/tikz/optics/io orientation/.is choice}
1352 \pgfkeys{/tikz/optics/io orientation/ltr/.code={\@tikz@optics@io@ltrtrue}}
1353 \pgfkeys{/tikz/optics/io orientation/rtl/.code={\@tikz@optics@io@ltrfalse}}
1354 %
1355 \pgfdeclareshape{generic optics io}
1356 {
1357 \savedanchor{\center}{
1358 \pgfpointorigin
1359 }
1360 \anchor{center}{\center}
1361
1362 \savedmacro\objectHeight{%
1363 \edef\objectHeight{\pgfkeysvalueof{/tikz/optics/io body height}}%
1364 }
1365
1366 \savedmacro\objectWidth{%
1367 \pgfmathparse{\pgfkeysvalueof{/tikz/optics/io body aspect ratio}}
1368 \ifpgfmathunitsdeclared%
1369 \pgfmathsetlengthmacro{\objectWidth}{\pgfkeysvalueof{/tikz/optics/io body aspect ratio}}%
1370 \else%
1371 \pgfmathsetlengthmacro{\objectWidth}{\pgfkeysvalueof{/tikz/optics/io body aspect ratio}*\pgfkeysvalueof{/tikz/optics/io body height}}%
1372 \fi%
1373 }
1374
1375 \savedmacro\outHeight{%
1376 \pgfmathparse{\pgfkeysvalueof{/tikz/optics/io aperture height}}
1377 \ifpgfmathunitsdeclared%
1378 \pgfmathsetlengthmacro{\outHeight}{\pgfkeysvalueof{/tikz/optics/io aperture height}}%
1379 \else%
1380 \pgfmathsetlengthmacro{\outHeight}{\pgfkeysvalueof{/tikz/optics/io aperture height}*\pgfkeysvalueof{/tikz/optics/io body height}}%
1381 \fi%
1382 }
1383
1384 \savedmacro\outWidth{%
1385 \pgfmathparse{\pgfkeysvalueof{/tikz/optics/io aperture width}}
1386 \ifpgfmathunitsdeclared%
1387 \pgfmathsetlengthmacro{\outWidth}{\pgfkeysvalueof{/tikz/optics/io aperture width}}%
1388 \else%
1389 \pgfmathsetlengthmacro{\outWidth}{\pgfkeysvalueof{/tikz/optics/io aperture width}*\pgfkeysvalueof{/tikz/optics/io body height}}%
1390 \fi%
1391 }
1392
1393 \savedmacro\outShift{%
1394 \pgfmathparse{\pgfkeysvalueof{/tikz/optics/io aperture shift}}
1395 \ifpgfmathunitsdeclared%
1396 \pgfmathsetlengthmacro{\outShift}{\pgfkeysvalueof{/tikz/optics/io aperture shift}}%
1397 \else%
1398 \pgfmathsetlengthmacro{\outShift}{\pgfkeysvalueof{/tikz/optics/io aperture shift}*\pgfkeysvalueof{/tikz/optics/io body height}}%
1399 \fi%
1400 }
1401
1402 \savedanchor{\bodynortheast}{
1403 \pgf@x=\objectWidth%
1404 \pgf@y=\objectHeight%
1405 \pgf@y=0.5\pgf@y%
1406 \pgf@x=0.5\pgf@x%
1407 }
1408 \anchor{body north east}{\bodynortheast}
1409
1410 \savedanchor{\bodysouthwest}{
1411 \pgf@x=\objectWidth%
1412 \pgf@y=\objectHeight%
1413 \pgf@y=-0.5\pgf@y%
1414 \pgf@x=-0.5\pgf@x%
1415 }
1416 \anchor{body south west}{\bodysouthwest}
1417
1418 \savedanchor{\outnortheast}{
1419 \if@tikz@optics@io@ltr
1420 % Left To Right (LTR)
1421 \pgf@x=\objectWidth%
1422 \pgf@x=0.5\pgf@x%
1423 \advance\pgf@x by\outWidth
1424 \else
1425 % Right To Left (RTL)
1426 \pgf@x=\objectWidth%
1427 \pgf@x=0.5\pgf@x%
1428 \pgf@x=-\pgf@x%
1429 \fi
1430 \pgf@y=0pt%
1431 \advance\pgf@y by\outHeight
1432 \pgf@y=0.5\pgf@y%
1433 \advance\pgf@y by\outShift
1434 }
1435 \anchor{aperture north east}{\outnortheast}
1436
1437 \savedanchor{\outsouthwest}{
1438 \if@tikz@optics@io@ltr
1439 % Left To Right (LTR)
1440 \pgf@x=\objectWidth%
1441 \pgf@x=0.5\pgf@x%
1442 \else
1443 % Right To Left (RTL)
1444 \pgf@x=\objectWidth%
1445 \pgf@x=0.5\pgf@x%
1446 \advance\pgf@x by\outWidth
1447 \pgf@x=-\pgf@x%
1448 \fi
1449 \pgf@y=0pt%
1450 \advance\pgf@y by\outHeight
1451 \pgf@y=-0.5\pgf@y%
1452 \advance\pgf@y by\outShift
1453 }
1454 \anchor{aperture south west}{\outsouthwest}
1455
1456 \savedanchor{\outcenter}{
1457 \if@tikz@optics@io@ltr
1458 % Left To Right (LTR)
1459 \pgf@x=\objectWidth%
1460 \advance\pgf@x by\outWidth
1461 \else
1462 % Right To Left (RTL)
1463 \pgf@x=\objectWidth%
1464 \advance\pgf@x by\outWidth
1465 \pgf@x=-\pgf@x%
1466 \fi
1467 \pgf@x=0.5\pgf@x%
1468 \pgf@y=0pt%
1469 \advance\pgf@y by\outShift
1470 }
1471 \anchor{aperture center}{\outcenter}
1472
1473
1474 \anchor{body center}{\center}
1475
1476 \anchor{text}{
1477 \pgfpointorigin
1478 \advance\pgf@x by -.5\wd\pgfnodeparttextbox%
1479 \advance\pgf@y by -.5\ht\pgfnodeparttextbox%
1480 \advance\pgf@y by +.5\dp\pgfnodeparttextbox%
1481 }
1482
1483 \anchor{body north}{
1484 \center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1485 \bodynortheast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1486 \pgf@x=\pgf@xa
1487 \pgf@y=\pgf@yb
1488 }
1489 % north = body north
1490 \anchor{north}{
1491 \center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1492 \bodynortheast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1493 \pgf@x=\pgf@xa
1494 \pgf@y=\pgf@yb
1495 }
1496
1497 \anchor{body south}{
1498 \center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1499 \bodysouthwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1500 \pgf@x=\pgf@xa
1501 \pgf@y=\pgf@yb
1502 }
1503 % south = body south
1504 \anchor{south}{
1505 \center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1506 \bodysouthwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1507 \pgf@x=\pgf@xa
1508 \pgf@y=\pgf@yb
1509 }
1510
1511 \anchor{body east}{
1512 \center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1513 \bodynortheast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1514 \pgf@x=\pgf@xb
1515 \pgf@y=\pgf@ya
1516 }
1517
1518 \anchor{body west}{
1519 \center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1520 \bodysouthwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1521 \pgf@x=\pgf@xb
1522 \pgf@y=\pgf@ya
1523 }
1524
1525 \anchor{body north west}{
1526 \bodynortheast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1527 \bodysouthwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1528 \pgf@x=\pgf@xb
1529 \pgf@y=\pgf@ya
1530 }
1531
1532 \anchor{body south east}{
1533 \bodynortheast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1534 \bodysouthwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1535 \pgf@x=\pgf@xa
1536 \pgf@y=\pgf@yb
1537 }
1538
1539
1540 \anchor{aperture north}{
1541 \outcenter \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1542 \outnortheast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1543 \pgf@x=\pgf@xa
1544 \pgf@y=\pgf@yb
1545 }
1546
1547 \anchor{aperture south}{
1548 \outcenter \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1549 \outsouthwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1550 \pgf@x=\pgf@xa
1551 \pgf@y=\pgf@yb
1552 }
1553
1554 \anchor{aperture east}{
1555 \outcenter \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1556 \outnortheast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1557 \pgf@x=\pgf@xb
1558 \pgf@y=\pgf@ya
1559 }
1560
1561 \anchor{aperture west}{
1562 \outcenter \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1563 \outsouthwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1564 \pgf@x=\pgf@xb
1565 \pgf@y=\pgf@ya
1566 }
1567
1568 \anchor{aperture north west}{
1569 \outnortheast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1570 \outsouthwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1571 \pgf@x=\pgf@xb
1572 \pgf@y=\pgf@ya
1573 }
1574
1575 \anchor{aperture south east}{
1576 \outnortheast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1577 \outsouthwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1578 \pgf@x=\pgf@xa
1579 \pgf@y=\pgf@yb
1580 }
1581
1582 \anchor{center}{\center}
1583
1584 \savedanchor{\realeast}{
1585 \pgfpointorigin
1586 \if@tikz@optics@io@ltr
1587 % Left To Right (LTR)
1588 %ltr : aperture east (<- out north east)
1589 \pgf@x=\objectWidth%
1590 \pgf@x=0.5\pgf@x%
1591 \advance\pgf@x by\outWidth
1592 %\pgf@y=0pt%
1593 \else
1594 % Right To Left (rtl)
1595 \pgf@x=\objectWidth%
1596 \pgf@x=0.5\pgf@x%
1597 \fi
1598 }
1599 \anchor{east}{\realeast}
1600
1601 \savedanchor{\realwest}{
1602 \pgfpointorigin
1603 \if@tikz@optics@io@ltr
1604 % Left To Right (LTR)
1605 \pgf@x=\objectWidth%
1606 \pgf@x=-0.5\pgf@x%
1607 \else
1608 % Right To Left (rtl)
1609 \pgf@x=\objectWidth%
1610 \pgf@x=0.5\pgf@x%
1611 \advance\pgf@x by\outWidth
1612 \pgf@x=-\pgf@x%
1613 \fi
1614 }
1615 \anchor{west}{\realwest}
1616
1617 % this is used only for the anchorborder
1618 \savedanchor{\anchorbordersouthwest}{
1619 \if@tikz@optics@io@ltr
1620 % Left To Right (LTR)
1621 \pgf@x=\objectWidth%
1622 \pgf@x=-0.5\pgf@x%
1623 \else
1624 % Right To Left (rtl)
1625 \pgf@x=\objectWidth%
1626 \pgf@x=0.5\pgf@x%
1627 \advance\pgf@x by\outWidth
1628 \pgf@x=-\pgf@x%
1629 \fi
1630 \pgf@y=\objectHeight%
1631 \pgf@y=-0.5\pgf@y%
1632 }
1633
1634 % this is used only for the anchorborder
1635 \savedanchor{\anchorbordernortheast}{
1636 \if@tikz@optics@io@ltr
1637 % Left To Right (LTR)
1638 \pgf@x=\objectWidth%
1639 \pgf@x=0.5\pgf@x%
1640 \advance\pgf@x by\outWidth
1641 \else
1642 % Right To Left (RTL)
1643 \pgf@x=\objectWidth%
1644 \pgf@x=0.5\pgf@x%
1645 %\pgf@x=-\pgf@x%
1646 \fi
1647 \pgf@y=\objectHeight%
1648 \pgf@y=0.5\pgf@y%
1649 }
1650
1651 % anchorborder
1652 % c'est celui de rectangle, mais un peu ajusté
1653 \anchorborder{%
1654 \pgf@xb=\pgf@x% xb/yb is target
1655 \pgf@yb=\pgf@y%
1656 \anchorbordersouthwest%
1657 \pgf@xa=\pgf@x% xa/ya is se
1658 \pgf@ya=\pgf@y%
1659 \anchorbordernortheast%
1660 \advance\pgf@x by-\pgf@xa%
1661 \advance\pgf@y by-\pgf@ya%
1662 \pgf@xc=.5\pgf@x% x/y is half width/height
1663 \pgf@yc=.5\pgf@y%
1664 \advance\pgf@xa by\pgf@xc% xa/ya becomes center
1665 \advance\pgf@ya by\pgf@yc%
1666 \edef\pgf@marshal{%
1667 \noexpand\pgfpointborderrectangle
1668 {\noexpand\pgfqpoint{\the\pgf@xb}{\the\pgf@yb}}
1669 {\noexpand\pgfqpoint{\the\pgf@xc}{\the\pgf@yc}}%
1670 }%
1671 \pgf@process{\pgf@marshal}%
1672 % \advance\pgf@x by\pgf@xa%
1673 % \advance\pgf@y by\pgf@ya%
1674 }
1675
1676 \backgroundpath
1677 {
1678 % corps
1679 \pgfpathrectanglecorners{\bodynortheast}{\bodysouthwest}
1680 % out
1681 \pgfpathrectanglecorners{\outnortheast}{\outsouthwest}
1682
1683 %\pgfusepath{draw}
1684 % il ne faut PAS mettre ça pour pouvoir utiliser des styles correctement après (genre double)
1685 }
1686 }
1687
1688
1689 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1690 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1691 % Sensors
1692 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1693 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1694
1695
1696 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1697 % Shape [sensor line]
1698 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1699 % Sensor line.
1700 %
1701 % This defines anchors center, north, south, east, west, north east
1702 % north west, south east, south west, as well as
1703 % pixel <i> <subanchor> with <subanchor> is any of the former.
1704 % ça va être horrible à faire
1705 %
1706 % keys :
1707 % - sensor line height
1708 % - sensor line aspect ratio (largeur en unités de la hauteur du capteur)
1709 % - sensor line pixel number
1710 % - sensor line pixel width (en unités de la largeur du capteur)
1711 % - sensor line inner ysep (en unités de la hauteur du capteur)
1712 \pgfkeys{/tikz/optics/.cd,
1713 sensor line height/.initial=2cm,
1714 sensor line aspect ratio/.initial=0.2,
1715 sensor line pixel number/.initial=5,
1716 sensor line pixel width/.initial=0.4,
1717 sensor line inner ysep/.initial=0.05, % entre le bord et les capteurs
1718 }
1719
1720 \pgfdeclareshape{sensor line}
1721 {
1722 \savedanchor{\center}{
1723 \pgfpointorigin
1724 }
1725 \anchor{center}{\center}
1726
1727 \savedmacro\objectHeight{%
1728 \edef\objectHeight{\pgfkeysvalueof{/tikz/optics/sensor line height}}%
1729 }
1730
1731 \savedmacro\objectWidth{%
1732 \pgfmathsetlengthmacro{\objectWidth}{\pgfkeysvalueof{/tikz/optics/sensor line aspect ratio}*\pgfkeysvalueof{/tikz/optics/sensor line height}}
1733 }
1734
1735 \savedmacro\pixelNumber{%
1736 \pgfmathtruncatemacro\pixelNumber{\pgfkeysvalueof{/tikz/optics/sensor line pixel number}}%
1737 }
1738
1739 \savedmacro\innerysep{%
1740 \pgfmathparse{\pgfkeysvalueof{/tikz/optics/sensor line inner ysep}}
1741 \ifpgfmathunitsdeclared%
1742 \pgfmathsetlengthmacro{\innerysep}{\pgfkeysvalueof{/tikz/optics/sensor line inner ysep}}%
1743 \else%
1744 \pgfmathsetlengthmacro{\innerysep}{\pgfkeysvalueof{/tikz/optics/sensor line inner ysep}*\pgfkeysvalueof{/tikz/optics/sensor line height}}%
1745 \fi%
1746 }
1747
1748 \savedmacro\pixelWidth{%
1749 \pgfmathparse{\pgfkeysvalueof{/tikz/optics/sensor line pixel width}}
1750 \ifpgfmathunitsdeclared%
1751 \pgfmathsetlengthmacro{\pixelWidth}{\pgfkeysvalueof{/tikz/optics/sensor line pixel width}}%
1752 \else%
1753 \pgfmathsetlengthmacro{\pixelWidth}{\pgfkeysvalueof{/tikz/optics/sensor line pixel width}*\objectWidth}%
1754 \fi%
1755 }
1756
1757 \savedmacro\pixelHeight{%
1758 \pgfmathparse{(\objectHeight-2*\innerysep)/\pixelNumber}
1759 \edef\pixelHeight{\pgfmathresult pt}%
1760 }
1761
1762 \savedanchor{\northeast}{
1763 \pgf@x=\objectWidth%
1764 \pgf@y=\objectHeight%
1765 \pgf@y=0.5\pgf@y%
1766 \pgf@x=0.5\pgf@x%
1767 }
1768 \anchor{north east}{\northeast}
1769
1770 \savedanchor{\southwest}{
1771 \pgf@x=\objectWidth%
1772 \pgf@y=\objectHeight%
1773 \pgf@y=-0.5\pgf@y%
1774 \pgf@x=-0.5\pgf@x%
1775 }
1776 \anchor{south west}{\southwest}
1777
1778 \anchor{north}{
1779 \center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1780 \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1781 \pgf@x=\pgf@xa
1782 \pgf@y=\pgf@yb
1783 }
1784
1785 \anchor{south}{
1786 \center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1787 \southwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1788 \pgf@x=\pgf@xa
1789 \pgf@y=\pgf@yb
1790 }
1791
1792 \anchor{east}{
1793 \center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1794 \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1795 \pgf@x=\pgf@xb
1796 \pgf@y=\pgf@ya
1797 }
1798
1799 \anchor{west}{
1800 \center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1801 \southwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1802 \pgf@x=\pgf@xb
1803 \pgf@y=\pgf@ya
1804 }
1805
1806 \anchor{north west}{
1807 \northeast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1808 \southwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1809 \pgf@x=\pgf@xb
1810 \pgf@y=\pgf@ya
1811 }
1812
1813 \anchor{south east}{
1814 \northeast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1815 \southwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1816 \pgf@x=\pgf@xa
1817 \pgf@y=\pgf@yb
1818 }
1819
1820 % ok, idée :
1821 % HAUT (north) du pixel n (allant de 1 à N)
1822 % \objectHeight/2 - \innerysep - (n-1) * \pixelHeight
1823 % BAS (south) du pixel n
1824 % \objectHeight/2 - \innerysep - n * \pixelHeight
1825 % west = le même que la boite, donc utiliser \southwest
1826 % east = west + \pixelWidth
1827
1828 % Le but de ce code est de définir des ancres
1829 % pixel <i> <pos>
1830 % pour <i> = 4, 2, ..., \pixelNumber
1831 % et <pos> = north, south, east, west, north west, south west, north east south east, center
1832 % Comme \pixelNumber est défini dynamiquement, il faut passer par cette horreur.
1833 % Le code est inspiré de pfglibraryshapes.geometric.code.tex (shape regular polygon).
1834 \expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@sensor line\endcsname{%
1835 \c@pgf@counta\pixelNumber\relax%
1836 \pgfmathloop%
1837 \ifnum\c@pgf@counta>0\relax%
1838 \pgfutil@ifundefined{pgf@anchor@sensor line@pixel\space\the\c@pgf@counta\space north west}{%
1839 %
1840 % ...(manually \xdef as \gdef is normally used by \anchor)...
1841 %
1842 %
1843 % pixel surface north
1844 \expandafter\xdef\csname pgf@anchor@sensor line@pixel\space\the\c@pgf@counta\space north\endcsname{%
1845 \noexpand\northeast \noexpand\pgf@xa=\noexpand\pgf@x \noexpand\pgf@ya=\noexpand\pgf@y
1846 \noexpand\southwest \noexpand\pgf@xb=\noexpand\pgf@x \noexpand\pgf@yb=\noexpand\pgf@y
1847 \noexpand\pgf@x=\noexpand\pixelWidth
1848 \noexpand\pgf@x=.5\noexpand\pgf@x
1849 \noexpand\advance\noexpand\pgf@x by\noexpand\pgf@xb
1850 \noexpand\pgf@y=\noexpand\pgf@ya
1851 \noexpand\newdimen\noexpand\temp@y
1852 \noexpand\pgfmathsetlength\noexpand\temp@y{(\the\c@pgf@counta-\noexpand\pixelNumber)*\noexpand\pixelHeight-\noexpand\innerysep}
1853 \noexpand\advance\noexpand\pgf@y by\noexpand\temp@y
1854 }%
1855 %
1856 %
1857 % pixel surface north east
1858 \expandafter\xdef\csname pgf@anchor@sensor line@pixel\space\the\c@pgf@counta\space north east\endcsname{%
1859 \noexpand\northeast \noexpand\pgf@xa=\noexpand\pgf@x \noexpand\pgf@ya=\noexpand\pgf@y
1860 \noexpand\southwest \noexpand\pgf@xb=\noexpand\pgf@x \noexpand\pgf@yb=\noexpand\pgf@y
1861 \noexpand\pgf@x=\noexpand\pixelWidth
1862 \noexpand\advance\noexpand\pgf@x by\noexpand\pgf@xb
1863 \noexpand\pgf@y=\noexpand\pgf@ya
1864 \noexpand\newdimen\noexpand\temp@y
1865 \noexpand\pgfmathsetlength\noexpand\temp@y{(\the\c@pgf@counta-\noexpand\pixelNumber)*\noexpand\pixelHeight-\noexpand\innerysep}
1866 \noexpand\advance\noexpand\pgf@y by\noexpand\temp@y
1867 }%
1868 %
1869 %
1870 % pixel surface north west
1871 \expandafter\xdef\csname pgf@anchor@sensor line@pixel\space\the\c@pgf@counta\space north west\endcsname{%
1872 \noexpand\northeast \noexpand\pgf@xa=\noexpand\pgf@x \noexpand\pgf@ya=\noexpand\pgf@y
1873 \noexpand\southwest \noexpand\pgf@xb=\noexpand\pgf@x \noexpand\pgf@yb=\noexpand\pgf@y
1874 \noexpand\pgf@x=\noexpand\pgf@xb
1875 \noexpand\pgf@y=\noexpand\pgf@ya
1876 \noexpand\newdimen\noexpand\temp@y
1877 \noexpand\pgfmathsetlength\noexpand\temp@y{(\the\c@pgf@counta-\noexpand\pixelNumber)*\noexpand\pixelHeight-\noexpand\innerysep}
1878 \noexpand\advance\noexpand\pgf@y by\noexpand\temp@y
1879 }%
1880 %
1881 %
1882 % pixel surface south
1883 \expandafter\xdef\csname pgf@anchor@sensor line@pixel\space\the\c@pgf@counta\space south\endcsname{%
1884 \noexpand\northeast \noexpand\pgf@xa=\noexpand\pgf@x \noexpand\pgf@ya=\noexpand\pgf@y
1885 \noexpand\southwest \noexpand\pgf@xb=\noexpand\pgf@x \noexpand\pgf@yb=\noexpand\pgf@y
1886 \noexpand\pgf@x=\noexpand\pixelWidth
1887 \noexpand\pgf@x=.5\noexpand\pgf@x
1888 \noexpand\advance\noexpand\pgf@x by\noexpand\pgf@xb
1889 \noexpand\pgf@y=\noexpand\pgf@ya
1890 \noexpand\newdimen\noexpand\temp@y
1891 \noexpand\pgfmathsetlength\noexpand\temp@y{(\the\c@pgf@counta-\noexpand\pixelNumber-1)*\noexpand\pixelHeight-\noexpand\innerysep}
1892 \noexpand\advance\noexpand\pgf@y by\noexpand\temp@y
1893 }%
1894 %
1895 %
1896 % pixel surface south east
1897 \expandafter\xdef\csname pgf@anchor@sensor line@pixel\space\the\c@pgf@counta\space south east\endcsname{%
1898 \noexpand\northeast \noexpand\pgf@xa=\noexpand\pgf@x \noexpand\pgf@ya=\noexpand\pgf@y
1899 \noexpand\southwest \noexpand\pgf@xb=\noexpand\pgf@x \noexpand\pgf@yb=\noexpand\pgf@y
1900 \noexpand\pgf@x=\noexpand\pixelWidth
1901 \noexpand\advance\noexpand\pgf@x by\noexpand\pgf@xb
1902 \noexpand\pgf@y=\noexpand\pgf@ya
1903 \noexpand\newdimen\noexpand\temp@y
1904 \noexpand\pgfmathsetlength\noexpand\temp@y{(\the\c@pgf@counta-\noexpand\pixelNumber-1)*\noexpand\pixelHeight-\noexpand\innerysep}
1905 \noexpand\advance\noexpand\pgf@y by\noexpand\temp@y
1906 }%
1907 %
1908 %
1909 % pixel surface south west
1910 \expandafter\xdef\csname pgf@anchor@sensor line@pixel\space\the\c@pgf@counta\space south west\endcsname{%
1911 \noexpand\northeast \noexpand\pgf@xa=\noexpand\pgf@x \noexpand\pgf@ya=\noexpand\pgf@y
1912 \noexpand\southwest \noexpand\pgf@xb=\noexpand\pgf@x \noexpand\pgf@yb=\noexpand\pgf@y
1913 \noexpand\pgf@x=\noexpand\pgf@xb
1914 \noexpand\pgf@y=\noexpand\pgf@ya
1915 \noexpand\newdimen\noexpand\temp@y
1916 \noexpand\pgfmathsetlength\noexpand\temp@y{(\the\c@pgf@counta-\noexpand\pixelNumber-1)*\noexpand\pixelHeight-\noexpand\innerysep}
1917 \noexpand\advance\noexpand\pgf@y by\noexpand\temp@y
1918 }%
1919 %
1920 %
1921 % pixel surface east
1922 \expandafter\xdef\csname pgf@anchor@sensor line@pixel\space\the\c@pgf@counta\space east\endcsname{%
1923 \noexpand\northeast \noexpand\pgf@xa=\noexpand\pgf@x \noexpand\pgf@ya=\noexpand\pgf@y
1924 \noexpand\southwest \noexpand\pgf@xb=\noexpand\pgf@x \noexpand\pgf@yb=\noexpand\pgf@y
1925 \noexpand\pgf@x=\noexpand\pixelWidth
1926 \noexpand\advance\noexpand\pgf@x by\noexpand\pgf@xb
1927 \noexpand\pgf@y=\noexpand\pgf@ya
1928 \noexpand\newdimen\noexpand\temp@y
1929 \noexpand\pgfmathsetlength\noexpand\temp@y{(\the\c@pgf@counta-\noexpand\pixelNumber-0.5)*\noexpand\pixelHeight-\noexpand\innerysep}
1930 \noexpand\advance\noexpand\pgf@y by\noexpand\temp@y
1931 }%
1932 %
1933 %
1934 % pixel surface center
1935 \expandafter\xdef\csname pgf@anchor@sensor line@pixel\space\the\c@pgf@counta\space center\endcsname{%
1936 \noexpand\northeast \noexpand\pgf@xa=\noexpand\pgf@x \noexpand\pgf@ya=\noexpand\pgf@y
1937 \noexpand\southwest \noexpand\pgf@xb=\noexpand\pgf@x \noexpand\pgf@yb=\noexpand\pgf@y
1938 \noexpand\pgf@x=\noexpand\pixelWidth
1939 \noexpand\pgf@x=.5\noexpand\pgf@x
1940 \noexpand\advance\noexpand\pgf@x by\noexpand\pgf@xb
1941 \noexpand\pgf@y=\noexpand\pgf@ya
1942 \noexpand\newdimen\noexpand\temp@y
1943 \noexpand\pgfmathsetlength\noexpand\temp@y{(\the\c@pgf@counta-\noexpand\pixelNumber-0.5)*\noexpand\pixelHeight-\noexpand\innerysep}
1944 \noexpand\advance\noexpand\pgf@y by\noexpand\temp@y
1945 }%
1946 %
1947 %
1948 % pixel surface west
1949 \expandafter\xdef\csname pgf@anchor@sensor line@pixel\space\the\c@pgf@counta\space west\endcsname{%
1950 \noexpand\northeast \noexpand\pgf@xa=\noexpand\pgf@x \noexpand\pgf@ya=\noexpand\pgf@y
1951 \noexpand\southwest \noexpand\pgf@xb=\noexpand\pgf@x \noexpand\pgf@yb=\noexpand\pgf@y
1952 \noexpand\pgf@x=\noexpand\pgf@xb
1953 \noexpand\pgf@y=\noexpand\pgf@ya
1954 \noexpand\newdimen\noexpand\temp@y
1955 \noexpand\pgfmathsetlength\noexpand\temp@y{(\the\c@pgf@counta-\noexpand\pixelNumber-0.5)*\noexpand\pixelHeight-\noexpand\innerysep}
1956 \noexpand\advance\noexpand\pgf@y by\noexpand\temp@y
1957 }%
1958 }{\c@pgf@counta0\relax}%
1959 \advance\c@pgf@counta-1\relax%
1960 \repeatpgfmathloop%
1961 }%
1962
1963 \inheritanchorborder[from=rectangle]
1964
1965 \backgroundpath
1966 {
1967 % rectangle contour
1968 \pgfpathrectanglecorners{\northeast}{\southwest}
1969
1970 % dessin des pixels
1971 \c@pgf@counta\pixelNumber\relax%
1972 \pgfmathloop%
1973 \ifnum\c@pgf@counta>0\relax%
1974 \newdimen\pixel@northeast@x
1975 \newdimen\pixel@northeast@y
1976 \newdimen\pixel@southwest@x
1977 \newdimen\pixel@southwest@y
1978 \northeast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1979 \southwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1980 % calcul pixel@northeast
1981 %% calcul x
1982 \pixel@northeast@x=\pgf@xb
1983 \advance\pixel@northeast@x by\pixelWidth
1984 %% calcul y
1985 \pixel@northeast@y=\pgf@ya
1986 \newdimen\temp@y
1987 \pgfmathsetlength\temp@y{(\the\c@pgf@counta-\pixelNumber)*\pixelHeight-\innerysep}
1988 \advance\pixel@northeast@y by\noexpand\temp@y
1989 % calcul pixel@southwest
1990 \pixel@southwest@x=\pgf@xb
1991 \pixel@southwest@y=\pgf@ya
1992 \newdimen\temp@y
1993 \pgfmathsetlength\temp@y{(\the\c@pgf@counta-\pixelNumber-1)*\pixelHeight-\innerysep}
1994 \advance\pixel@southwest@y by\temp@y
1995 % dessin
1996 \pgfpathrectanglecorners{\pgfpoint{\pixel@northeast@x}{\pixel@northeast@y}}{\pgfpoint{\pixel@southwest@x}{\pixel@southwest@y}}
1997 \advance\c@pgf@counta-1\relax%
1998 \repeatpgfmathloop%
1999 }
2000 }
2001
2002
2003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2005 % Styles defining optics elements in terms of the existing shapes.
2006 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2007 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2008
2009 % Style [screen]
2010 \pgfkeys{/tikz/optics/screen/.style={thin optics element, very thick}}
2011 % Style [diffraction grating]
2012 \pgfkeys{/tikz/optics/diffraction grating/.style={thin optics element, /tikz/optics/cheating dash={on 4pt off 2pt}}}
2013 % Style [grid]
2014 \pgfkeys{/tikz/optics/grid/.style={thin optics element, /tikz/optics/cheating dash={on 4pt off 2pt}, ultra thick}}
2015 % Style [semi-transparent mirror]
2016 \pgfkeys{/tikz/optics/semi-transparent mirror/.style={thin optics element, densely dotted, thick}}
2017 % Style [diaphragm]
2018 \pgfkeys{/tikz/optics/diaphragm/.style={slit,/tikz/optics/slit height=0.4}}
2019
2020
2021 % Style [generic lamp]
2022 \pgfkeys{/tikz/optics/generic lamp/.style={shape=generic optics io,optics,draw}}
2023 % Style [generic sensor]
2024 \pgfkeys{/tikz/optics/generic sensor/.style={shape=generic optics io,optics,io orientation=rtl,draw, io body height=1cm, io body aspect ratio=0.5, io aperture width=0.15}}
2025 % Style [halogen lamp]
2026 \pgfkeys{/tikz/optics/halogen lamp/.style={/tikz/optics/generic lamp, io body height=0.75cm, io body aspect ratio=2,io aperture width=0.33,io aperture height=0.66,io aperture shift=0}}
2027 % Style [spectral lamp]
2028 \pgfkeys{/tikz/optics/spectral lamp/.style={/tikz/optics/generic lamp, io body height=2.25cm, io body aspect ratio=2/3,io aperture width=0.11,io aperture height=0.22,io aperture shift=0.25,/tikz/optics/io multiline}}
2029 % Style [laser]
2030 \pgfkeys{/tikz/optics/laser/.style={/tikz/optics/generic lamp, io body height=0.5cm, io body aspect ratio=3,io aperture width=0.22,io aperture height=0.5,io aperture shift=0}}
2031 % Style [laser']
2032 \pgfkeys{/tikz/optics/laser'/.style={/tikz/optics/generic lamp, io body height=0.5cm, io body aspect ratio=3,io aperture width=0,io aperture height=0.5,io aperture shift=0}}
2033 % Style [beam splitter]
2034 \pgfkeys{/tikz/optics/beam splitter/.style={shape=polarizer, optics, draw, object height=1cm, object aspect ratio=1}}
2035
2036
2037
2038 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2039 % Helper style to draw correctly dashed paths.
2040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2041 % source : http://tex.stackexchange.com/questions/133271/can-tikz-dashed-lines-emulate-pstricks-dashed-lines
2042 % le but est d'avoir des dash symétriques par rapport au milieu et surtout avec un trait entier de chaque côté
2043 \tikzset{
2044 /tikz/optics/cheating dash/.code args={on #1 off #2}{
2045 % Use csname so catcode of @ doesn't have do be changed.
2046 \csname tikz@addoption\endcsname{%
2047 \pgfgetpath\currentpath%
2048 \pgfprocessround{\currentpath}{\currentpath}%
2049 \csname pgf@decorate@parsesoftpath\endcsname{\currentpath}{\currentpath}%
2050 \pgfmathparse{\csname pgf@decorate@totalpathlength\endcsname-#1}\let\rest=\pgfmathresult%
2051 \pgfmathparse{#1+#2}\let\onoff=\pgfmathresult%
2052 \pgfmathparse{max(floor(\rest/\onoff), 1)}\let\nfullonoff=\pgfmathresult%
2053 \pgfmathparse{max((\rest-\onoff*\nfullonoff)/\nfullonoff+#2, #2)}\let\offexpand=\pgfmathresult%
2054 \pgfsetdash{{#1}{\offexpand}}{0pt}}%
2055 }
2056 }
2057
2058
2059 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2060 % Helper style for multiline io elements.
2061 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2062 \pgfkeys{/tikz/optics/io multiline/.code={\newdimen\tmplen\pgfmathsetlength{\tmplen}{\pgfkeysvalueof{/tikz/optics/io body aspect ratio}*\pgfkeysvalueof{/tikz/optics/io body height}}\tikzset{text width=\the\tmplen,align=center}}}
2063
2064
2065 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2066 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2067 % Helper styles to mark interesing points
2068 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2069 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2070
2071
2072 % Style [mark point]
2073 % Describes how interesting points should be drawn (e.g. by [draw focal points], [draw mirror focus], [draw mirror center])
2074 \pgfkeys{/tikz/optics/mark point/.style={optics/mark a cross}}
2075
2076 % Style [draw focal points]
2077 % Should be applied to a [shape=lens] node to draw its focal points according to the style [mark point].
2078 \pgfkeys{/tikz/optics/draw focal points/.style={append after command={
2079 \pgfextra{
2080 \begin{pgfinterruptpath}
2081 \node[/tikz/optics/mark point,#1] at (\tikzlastnode.west focal point) {};
2082 \node[/tikz/optics/mark point,#1] at (\tikzlastnode.east focal point) {};
2083 \end{pgfinterruptpath}
2084 }
2085 }
2086 }}
2087
2088 % Style [draw mirror focus]
2089 % Should be applied to a [shape=spherical mirror] node to draw its focal point according to the style [mark point].
2090 \pgfkeys{/tikz/optics/draw mirror focus/.style={append after command={
2091 \pgfextra{
2092 \begin{pgfinterruptpath}
2093 \node[/tikz/optics/mark point,#1] at (\tikzlastnode.focus) {};
2094 \end{pgfinterruptpath}
2095 }
2096 }
2097 }}
2098
2099 % Style [draw mirror center]
2100 % Should be applied to a [shape=spherical mirror] node to draw its center according to the style [mark point].
2101 \pgfkeys{/tikz/optics/draw mirror center/.style={append after command={
2102 \pgfextra{
2103 \begin{pgfinterruptpath}
2104 \node[/tikz/optics/mark point,#1] at (\tikzlastnode.mirror center) {};
2105 \end{pgfinterruptpath}
2106 }
2107 }
2108 }}
2109
2110 % Style [mark a cross]
2111 % Draws a cross at the node
2112 \pgfkeys{/tikz/optics/mark a cross/.style={cross out,draw,inner sep=0pt,minimum width=2pt,minimum height=2pt}}
2113
2114 % idée : utiliser pgfextra pour les flèches, si on peut avoir les deux dernières nodes ?
2115
2116 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2117 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2118 % Helper styles to easily put things on paths.
2119 % It is often needed in optics to have e.g. arrows in the middle of a path.
2120 % It is often needed everywhere to be able to put a coordinate somewhere on
2121 % a path.
2122 % This is the aim of these helpers.
2123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2124 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2125
2126
2127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2128 % Style [put coordinate]
2129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2130 % Le style [put coordinate=<coord> at <pos>] crée une node[coordinate]
2131 % à l'abscisse curviligne <pos> sur le chemin auquel est appliqué le style.
2132 %
2133 % Exemple :
2134 % \draw[put coordinate=P at 0.3] (0,0) to[bend left] (2cm,0);
2135 % \draw[red] (P) -- (0,0);
2136 %
2137 \tikzset{
2138 put coordinate/.style args={#1 at #2}{decoration={markings, mark=at position #2 with {\node[coordinate] (#1) {};}},postaction={decorate}}
2139 }
2140
2141 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2142 % Style [put arrow]
2143 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2144 %
2145 % The aim of this horrible mess is that I want expansion to take place at the right time, so I can ask for something like
2146 % \draw[/tikz/optics/->-={at=0.25}, /tikz/optics/->-={at=0.75}] (0,0) -- (2cm,2cm) -- (4cm,0);
2147 % and have it work. Obviously, I want more complicated things (several arrows with different directions, colors, number of >, etc. on the same path).
2148 % With a naive implementation, this does not work and the last setting always wins.
2149 % A possible solution would be positional arguments, however keywords arguments are Better (tm).
2150 % Hence the need to take care of expansion order, so the specifications apply only to the currently drawn arrow tip.
2151 % The main idea behing this code is to use Magic (tm) so that Things Work (tm) and never touch it again.
2152 % However, it is obvious from a trivial application of Murphy Law that this will backfire sometime.
2153 % Indeed, a key with positional arguments are used internally (|ordered draw key|), which is called from the parsed arguments.
2154 \tikzset{/tikz/put arrow/.cd,
2155 pos/.initial=0.5,
2156 at/.style={pos=#1},
2157 pos var/.initial={},
2158 style/.initial={},
2159 style var/.initial={},
2160 postaction style/.initial={}, % more expansion magic needed for ->n- and friends (\arrow[thing=stuff] does not seem to work, probably because of the =)
2161 arrow macro/.initial={arrow},
2162 arrow macro var/.initial={},
2163 arrow type/.initial={>},
2164 arrow type var/.initial={},
2165 reversed/.style={arrow macro=arrowreversed},
2166 arrow/.style={arrow type=#1},
2167 arrow'/.style={arrow type=#1, reversed},
2168 every arrow/.style={},
2169 }
2170
2171 \tikzset{put arrow/.code={
2172 % parse arguments correctly
2173 \tikzset{/tikz/put arrow/.cd, #1}
2174 \tikzset{/tikz/put arrow/pos var/.expand once={\pgfkeysvalueof{/tikz/put arrow/pos}}}
2175 \tikzset{/tikz/put arrow/style var/.expanded={\pgfkeysvalueof{/tikz/put arrow/style}}}
2176 \tikzset{/tikz/put arrow/arrow macro var/.expand once={\pgfkeysvalueof{/tikz/put arrow/arrow macro}}}
2177 \tikzset{/tikz/put arrow/arrow type var/.expand once={\pgfkeysvalueof{/tikz/put arrow/arrow type}}}
2178 % call |ordered draw key| which does the real job
2179 \tikzset{/tikz/put arrow/ordered draw key/.expanded=%
2180 {\pgfkeysvalueof{/tikz/put arrow/pos var}}%
2181 {\pgfkeysvalueof{/tikz/put arrow/style var}}%
2182 {\pgfkeysvalueof{/tikz/put arrow/arrow macro var}}%
2183 {\pgfkeysvalueof{/tikz/put arrow/arrow type var}}%
2184 {\pgfkeysvalueof{/tikz/put arrow/postaction style}}%
2185 }
2186 % restore initial values
2187 \tikzset{/tikz/put arrow/pos=0.5}
2188 \tikzset{/tikz/put arrow/style={}}
2189 \tikzset{/tikz/put arrow/arrow macro={arrow}}
2190 \tikzset{/tikz/put arrow/arrow type={>}}
2191 }}
2192
2193 \tikzset{/tikz/put arrow/ordered draw key/.code n args={5}{
2194 \tikzset{postaction={#5,decorate, decoration={markings, mark=at position #1 with {\csname #3\endcsname[/tikz/put arrow/every arrow,#2]{#4}};}}}
2195 }}
2196
2197 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2198 % Styles to mark light rays
2199 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2200 \tikzset{/tikz/optics/multiple ray arrow/.cd,
2201 n/.initial=1,
2202 n var/.initial=1,
2203 set n/.code={\pgfsetarrowoptions{multiple ray arrow}{#1}},
2204 }
2205
2206
2207 \pgfkeys{
2208 /tikz/optics/.cd,
2209 use ray arrow >/.code 2 args={
2210 \pgfsetarrowoptions{ray arrow@length}{4pt}
2211 \pgfsetarrowoptions{ray arrow@angle}{50}
2212 \tikzset{/tikz/put arrow/postaction style/.expanded={/tikz/optics/multiple ray arrow/set n=#1}}
2213 \tikzset{/tikz/put arrow/.expanded={arrow={multiple ray arrow}, #2}}
2214 },
2215 use ray arrow </.code 2 args={
2216 \pgfsetarrowoptions{ray arrow@length}{4pt}
2217 \pgfsetarrowoptions{ray arrow@angle}{50}
2218 \tikzset{/tikz/put arrow/postaction style/.expanded={/tikz/optics/multiple ray arrow/set n=#1}}
2219 \tikzset{/tikz/put arrow/.expanded={arrow'={multiple ray arrow}, #2}}
2220 },
2221 ->n-/.code={
2222 \tikzset{/tikz/optics/multiple ray arrow/.cd, .collect unknowns,%
2223 #1,
2224 unknown options/.get = \arrowkeys}
2225 \tikzset{/tikz/optics/multiple ray arrow/n var/.expand once={\pgfkeysvalueof{/tikz/optics/multiple ray arrow/n}}}
2226 \tikzset{/tikz/optics/use ray arrow >={\pgfkeysvalueof{/tikz/optics/multiple ray arrow/n var}}{\arrowkeys}}
2227 },
2228 -<n-/.code={
2229 \tikzset{/tikz/optics/multiple ray arrow/.cd, .collect unknowns,%
2230 #1,
2231 unknown options/.get = \arrowkeys}
2232 \tikzset{/tikz/optics/multiple ray arrow/n var/.expand once={\pgfkeysvalueof{/tikz/optics/multiple ray arrow/n}}}
2233 \tikzset{/tikz/optics/use ray arrow <={\pgfkeysvalueof{/tikz/optics/multiple ray arrow/n var}}{\arrowkeys}}
2234 },
2235 %
2236 ->-/.style={/tikz/optics/->n-={n=1, #1}},
2237 -<-/.style={/tikz/optics/-<n-={n=1, #1}},
2238 ->>-/.style={/tikz/optics/->n-={n=2, #1}},
2239 -<<-/.style={/tikz/optics/-<n-={n=2, #1}},
2240 ->>>-/.style={/tikz/optics/->n-={n=3, #1}},
2241 -<<<-/.style={/tikz/optics/-<n-={n=3, #1}},
2242 ->>>>-/.style={/tikz/optics/->n-={n=4, #1}},
2243 -<<<<-/.style={/tikz/optics/-<n-={n=4, #1}},
2244 }
2245
2246
2247
2248
2249 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2250 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2251 % Styles [dim arrow] and [short dim arrow]
2252 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2253 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2254 \def\dimarrow@short@position{0}
2255 \newif\ifdimarrow@nearstart
2256 \dimarrow@nearstarttrue
2257 \tikzset{%
2258 /tikz/dim arrow/.code={\tikzset{draw,/tikz/dim arrow/draw dim arrow}\pgfkeys{/tikz/dim arrow/.cd,#1}},
2259 /tikz/dim arrow'/.code={\pgfkeysgetvalue{/tikz/dim arrow/raise}{\tmp@tdar}\tikzset{draw,/tikz/dim arrow/draw dim arrow,/tikz/dim arrow/raise=-\tmp@tdar}\pgfkeys{/tikz/dim arrow/.cd,#1}},
2260 /tikz/short dim arrow/.code={\tikzset{draw,/tikz/dim arrow/draw short dim arrow}\pgfkeys{/tikz/dim arrow/.cd,#1}},
2261 /tikz/short dim arrow'/.code={\pgfkeysgetvalue{/tikz/dim arrow/raise}{\tmp@tdar}\tikzset{draw,/tikz/dim arrow/draw short dim arrow,/tikz/dim arrow/raise=-\tmp@tdar}\pgfkeys{/tikz/dim arrow/.cd,#1}},
2262 /tikz/dim arrow/.cd,
2263 raise/.initial={0.5cm},
2264 no raise/.style={raise=0},
2265 label/.code={\pgfkeys{/tikz/dim arrow/label text=#1}},
2266 label'/.code={\pgfkeys{/tikz/dim arrow/label text=#1,/tikz/dim arrow/label style/.append style={swap},}},
2267 label text/.initial={},
2268 label style/.style={},
2269 label near start/.code={\def\dimarrow@short@position{0}}, % only short
2270 label near middle/.code={\def\dimarrow@short@position{2}}, % only short
2271 label near end/.code={\def\dimarrow@short@position{1}}, % only short
2272 arrow length/.initial={5mm}, % only for short
2273 draw short dim arrow/.style={to path={\pgfextra{%
2274 \let\tikz@mode@save=\tikz@mode%
2275 \let\tikz@options@save=\tikz@options%
2276 \newdimen\labelTotalRaise
2277 \pgfmathsetlength\labelTotalRaise{\pgfkeysvalueof{/tikz/dim arrow/raise}}
2278 \pgfinterruptpath
2279 \draw[>=technical,->|] \pgfextra{\let\tikz@mode=\tikz@mode@save\let\tikz@options=\tikz@options@save}
2280 let
2281 \p1=($(\tikztostart)!\pgfkeysvalueof{/tikz/dim arrow/raise}!90:(\tikztotarget)$),
2282 \p2=($(\tikztotarget)!\pgfkeysvalueof{/tikz/dim arrow/raise}!-90:(\tikztostart)$)
2283 in ($(\p1)!-\pgfkeysvalueof{/tikz/dim arrow/arrow length}!(\p2)$) -- ($(\p1)!0!(\p2)$);
2284 \draw[>=technical,->|] \pgfextra{\let\tikz@mode=\tikz@mode@save\let\tikz@options=\tikz@options@save}
2285 let
2286 \p1=($(\tikztostart)!\pgfkeysvalueof{/tikz/dim arrow/raise}!90:(\tikztotarget)$),
2287 \p2=($(\tikztotarget)!\pgfkeysvalueof{/tikz/dim arrow/raise}!-90:(\tikztostart)$)
2288 in ($(\p2)!-\pgfkeysvalueof{/tikz/dim arrow/arrow length}!(\p1)$) -- ($(\p2)!0!(\p1)$);
2289 \ifnum\dimarrow@short@position=0
2290 \path let
2291 \p1=($(\tikztostart)!\labelTotalRaise!90:(\tikztotarget)$),
2292 \p2=($(\tikztotarget)!\labelTotalRaise!-90:(\tikztostart)$)
2293 in let
2294 \p3=($(\p1)!-1*\pgfkeysvalueof{/tikz/dim arrow/arrow length}!(\p2)$),
2295 \p4=($(\p1)!-0*\pgfkeysvalueof{/tikz/dim arrow/arrow length}!(\p2)$)
2296 in
2297 (\p3) -- (\p4) node[pos=0.5,auto=left,/tikz/dim arrow/label style] {\pgfkeysvalueof{/tikz/dim arrow/label text}};
2298 \fi
2299 \ifnum\dimarrow@short@position=1
2300 \path let
2301 \p1=($(\tikztostart)!\labelTotalRaise!90:(\tikztotarget)$),
2302 \p2=($(\tikztotarget)!\labelTotalRaise!-90:(\tikztostart)$)
2303 in let
2304 \p3=($(\p2)!-1*\pgfkeysvalueof{/tikz/dim arrow/arrow length}!(\p1)$),
2305 \p4=($(\p2)!-0*\pgfkeysvalueof{/tikz/dim arrow/arrow length}!(\p1)$)
2306 in
2307 (\p4) -- (\p3) node[pos=0.5,auto=left,/tikz/dim arrow/label style] {\pgfkeysvalueof{/tikz/dim arrow/label text}};
2308 \fi
2309 \ifnum\dimarrow@short@position=2
2310 \path let
2311 \p1=($(\tikztostart)!\labelTotalRaise!90:(\tikztotarget)$),
2312 \p2=($(\tikztotarget)!\labelTotalRaise!-90:(\tikztostart)$)
2313 in
2314 (\p1) -- (\p2) node[pos=0.5,/tikz/dim arrow/label style] {\pgfkeysvalueof{/tikz/dim arrow/label text}};
2315 \fi
2316 \endpgfinterruptpath
2317 }(\tikztostart) (\tikztotarget) \tikztonodes
2318 }
2319 },
2320 draw dim arrow/.style={to path={\pgfextra{%
2321 \let\tikz@mode@save=\tikz@mode%
2322 \let\tikz@options@save=\tikz@options%
2323 \newdimen\labelTotalRaise
2324 \pgfmathsetlength\labelTotalRaise{\pgfkeysvalueof{/tikz/dim arrow/raise}}
2325 \pgfinterruptpath
2326 \draw[>=technical,|<->|] \pgfextra{\let\tikz@mode=\tikz@mode@save\let\tikz@options=\tikz@options@save}
2327 let
2328 \p1=($(\tikztostart)!\pgfkeysvalueof{/tikz/dim arrow/raise}!90:(\tikztotarget)$),
2329 \p2=($(\tikztotarget)!\pgfkeysvalueof{/tikz/dim arrow/raise}!-90:(\tikztostart)$)
2330 in (\p1) -- (\p2);
2331 \path let
2332 \p1=($(\tikztostart)!\labelTotalRaise!90:(\tikztotarget)$),
2333 \p2=($(\tikztotarget)!\labelTotalRaise!-90:(\tikztostart)$)
2334 in (\p1) -- (\p2) node[pos=0.5,auto=left,/tikz/dim arrow/label style] {\pgfkeysvalueof{/tikz/dim arrow/label text}};
2335 % rq : inner sep controle la distance chemin-node
2336 \endpgfinterruptpath
2337 }(\tikztostart) (\tikztotarget) \tikztonodes
2338 }
2339 },
2340 }
2341
2342 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2343 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2344 % Arrows
2345 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2346 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2347
2348 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2349 % Arrow lens arrow
2350 % used to draw lenses (perhaps not the best idea).
2351 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2352 \pgfsetarrowoptions{lens arrow@length}{6pt}
2353 \pgfsetarrowoptions{lens arrow@angle}{50}
2354 \pgfarrowsdeclare{lens arrow}{lens arrow}
2355 {
2356 \pgfarrowsleftextend{0pt}
2357 \pgfarrowsrightextend{0pt}
2358 }
2359 {
2360 \pgfsetroundcap
2361 \pgfsetmiterjoin
2362 \pgfmathsetlength{\pgfutil@tempdimb}{\pgfgetarrowoptions{lens arrow@length}*sin(\pgfgetarrowoptions{lens arrow@angle}/2)}
2363 \def\arrow@origin{\pgfpoint{0pt}{0pt}}
2364 \pgfutil@tempdima=\pgfgetarrowoptions{lens arrow@length}%
2365 \pgfmathsetmacro{\tmp@lens@angle}{90+\pgfgetarrowoptions{lens arrow@angle}}
2366 \pgfmathsetmacro{\tmp@lens@anglediv}{\pgfgetarrowoptions{lens arrow@angle}/2}
2367 \advance\pgfutil@tempdima by -1.5\pgflinewidth%
2368 \pgfmathsetlength{\pgfutil@tempdima}{\pgfutil@tempdima/cos(\pgfgetarrowoptions{lens arrow@angle}/2)}
2369 \pgfpathmoveto{\pgfpointadd{\arrow@origin}{\pgfqpointpolar{\tmp@lens@angle}{\pgfutil@tempdima}}}
2370 \pgfpathlineto{\arrow@origin}
2371 \pgfpathlineto{\pgfpointadd{\arrow@origin}{\pgfqpointpolar{-\tmp@lens@angle}{\pgfutil@tempdima}}}
2372 \pgfusepathqstroke
2373 }
2374 \pgfarrowsdeclarereversed{lens arrow reversed}{lens arrow reversed}{lens arrow}{lens arrow}
2375
2376
2377 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2378 % Ray arrow
2379 % It is useful to have an arrow which goes on the exact middle of a path.
2380 % This is used on ->-, etc.
2381 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2382 % flèche utilisée pour marquer les rayons lumineux (avec les styles ->-, etc.)
2383 \pgfsetarrowoptions{ray arrow@length}{4pt}
2384 \pgfsetarrowoptions{ray arrow@angle}{45}
2385
2386 \makeatletter
2387
2388 \pgfsetarrowoptions{multiple ray arrow}{0}
2389 \pgfarrowsdeclare{multiple ray arrow}{multiple ray arrow}
2390 {
2391 \pgfarrowsleftextend{0pt}
2392 \pgfarrowsrightextend{0pt}
2393 }
2394 {
2395 \pgfsetroundcap
2396 \pgfsetmiterjoin
2397 \pgfutil@tempdima=\pgfgetarrowoptions{ray arrow@length}%
2398 \pgfmathsetmacro{\tmp@ray@angle}{90+\pgfgetarrowoptions{ray arrow@angle}}
2399 \pgfmathsetmacro{\tmp@ray@anglediv}{\pgfgetarrowoptions{ray arrow@angle}/2}
2400 \advance\pgfutil@tempdima by -1.5\pgflinewidth%
2401 \pgfmathsetlength{\pgfutil@tempdima}{\pgfutil@tempdima/cos(\pgfgetarrowoptions{ray arrow@angle}/2)}
2402 %
2403 \foreach \i in {1,...,\pgfgetarrowoptions{multiple ray arrow}}
2404 {
2405 \pgfmathsetlength{\pgfutil@tempdimb}{(2*\i-\pgfgetarrowoptions{multiple ray arrow})*\pgfgetarrowoptions{ray arrow@length}*sin(\pgfgetarrowoptions{ray arrow@angle}/2)}
2406 %
2407 \def\arrow@origin{\pgfpoint{\pgfutil@tempdimb}{0pt}}
2408 %
2409 \pgfpathmoveto{\pgfpointadd{\arrow@origin}{\pgfqpointpolar{\tmp@ray@angle}{\pgfutil@tempdima}}}
2410 \pgfpathlineto{\arrow@origin}
2411 \pgfpathlineto{\pgfpointadd{\arrow@origin}{\pgfqpointpolar{-\tmp@ray@angle}{\pgfutil@tempdima}}}
2412 \pgfusepathqstroke
2413 }
2414 }
2415
2416
2417 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2418 % Arrow technical
2419 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2420 \makeatletter
2421 \pgfarrowsdeclare{technical}{technical}
2422 {%
2423 \pgfutil@tempdima=0.48pt%
2424 \pgfutil@tempdimb=\pgflinewidth%
2425 \ifdim\pgfinnerlinewidth>0pt%
2426 \pgfmathsetlength\pgfutil@tempdimb{.6\pgflinewidth-.4*\pgfinnerlinewidth}%
2427 \fi%
2428 \advance\pgfutil@tempdima by.3\pgfutil@tempdimb%
2429 \pgfarrowsleftextend{+-3\pgfutil@tempdima}%
2430 \pgfarrowsrightextend{+8\pgfutil@tempdima}%
2431 }
2432 {%
2433 \pgfutil@tempdima=0.48pt%
2434 \pgfutil@tempdimb=\pgflinewidth%
2435 \ifdim\pgfinnerlinewidth>0pt%
2436 \pgfmathsetlength\pgfutil@tempdimb{.6\pgflinewidth-.4*\pgfinnerlinewidth}%
2437 \fi%
2438 \advance\pgfutil@tempdima by.3\pgfutil@tempdimb%
2439 \pgfpathmoveto{\pgfqpoint{8\pgfutil@tempdima}{0pt}}%
2440 \pgfpathlineto{\pgfqpoint{-3\pgfutil@tempdima}{3\pgfutil@tempdima}}%
2441 \pgfpathlineto{\pgfpointorigin}%
2442 \pgfpathlineto{\pgfqpoint{-3\pgfutil@tempdima}{-3\pgfutil@tempdima}}%
2443 \pgfusepathqfill%
2444 }
2445
2446 \pgfarrowsdeclare{technical reversed}{technical reversed}
2447 {%
2448 \pgfutil@tempdima=0.48pt%
2449 \pgfutil@tempdimb=\pgflinewidth%
2450 \ifdim\pgfinnerlinewidth>0pt%
2451 \pgfmathsetlength\pgfutil@tempdimb{.6\pgflinewidth-.4*\pgfinnerlinewidth}%
2452 \fi%
2453 \advance\pgfutil@tempdima by.3\pgfutil@tempdimb%
2454 \pgfarrowsleftextend{-8\pgfutil@tempdima}
2455 \pgfarrowsrightextend{-8\pgfutil@tempdima}
2456 }
2457 {%
2458 \pgfutil@tempdima=0.48pt%
2459 \pgfutil@tempdimb=\pgflinewidth%
2460 \ifdim\pgfinnerlinewidth>0pt%
2461 \pgfmathsetlength\pgfutil@tempdimb{.6\pgflinewidth-.4*\pgfinnerlinewidth}%
2462 \fi%
2463 \advance\pgfutil@tempdima by.3\pgfutil@tempdimb%
2464 \pgfpathmoveto{\pgfqpoint{-8\pgfutil@tempdima}{0pt}}%
2465 \pgfpathlineto{\pgfqpoint{3\pgfutil@tempdima}{3\pgfutil@tempdima}}%
2466 \pgfpathlineto{\pgfpointorigin}%
2467 \pgfpathlineto{\pgfqpoint{3\pgfutil@tempdima}{-3\pgfutil@tempdima}}%
2468 \pgfusepathqfill%
2469 }
2470
2471
2472 % Changelog:
2473 % 2013-10-21 : ajout du style |distance arrow| et de la décoration |line| correspondante.
2474 % 2013-11-19 : suppression de |distance arrow| et ajout à la place de |dim arrow| et assimilés
2475 % 2013-11-22 : choix entre distances relatives et absolues (http://www.texample.net/tikz/examples/supersonic-nozzle/)
2476 % 2013-11-24 : styles de flèches |->-|, |-<-|, |->>-|, |-<<-| (et flèches pgf |ray arrow|, etc. correspondantes)
2477 % 2013-11-24 : flèches pgf |lens arrow| et |lens arrow reversed|
2478 % 2013-11-24 : |generic optics element| -> |thin optics element| et |thick optics element| ; conséquences. |beam splitter|
2479 % 2014-01-01 : ajout de |double amici prism|, |optics| -> |use optics| et |one arrow| -> |put arrow| ; |mark a *| supprimés
2480 % 2014-03-19 : anchorborder pour |generic optics io| (les labels devraient donc être placés correctement)
2481 % |io body aspect ratio| accepte désormais aussi des longueurs absolues, ajout d'un alias |io body width| pour |io body aspect ratio|
2482 % 2014-06-26 : modification du code des flèches |->-|, |->>-|, etc. et ajout de |->>>-|, |->>>>-|,|->n-=<nombre>| (idem dans l'autre sens)
2483 % 2014-07-08 : ajout de |arrow style| à |put arrow|
2484 % 2014-09-20 : ajout de |spherical mirror| et quelques modifications à |mirror| (ajustement de la décoration et de ses réglages par défaut)
2485 % 2014-09-22 : ajustements de |spherical mirror| (concave et convexe), et ajout des styles correspondants |convex mirror| et |concave mirror|
2486 % 2014-09-24 : ajustements de |spherical mirror| (ltr/rtl) ; correction des ancres de generic optics io (aperture north, aperture center, aperture south étaient incorrectes)
2487 % 2014-09-25 : corrections à |spherical mirror| (ltr/rtl vs concave/convex) ;
2488 % 2014-10-02 : ajout d'une fonction |from_radius| pour définir l'angle d'ouverture de |spherical mirror|, encore des corrections à |spherical mirror| (ltr/rtl vs concave/convex) ;
2489 % macro pour les messages d'erreur
2490 % 2014-10-03 : vérifications de cohérence des grandeurs pour |slit| et |double slit| ; messages d'erreur au besoin
2491 % 2014-12-07 : modifications substantielles à |put arrow| et |optics/->n-|, etc. pour pouvoir avoir plusieurs flèches sur le même chemin ; la compatibilité arrière est brisée.
2492 % 2014-12-11 : nettoyage
2493 % 2015-03-10 : ajout d'un alias |object width| pour |object aspect ratio|, qui accepte désormais aussi des longueurs absolues
2494 % 2015-06-13 : mise en cohérence des noms des points focaux pour le miroir et la lentille (désormais, "focus" et "focal point")
2495 % 2016-11-21 : appel aux biblothèques tikz |decorations| et |decorations.pathreplacing| qui sont nécessaires
2496 \makeatother