-
Notifications
You must be signed in to change notification settings - Fork 5
/
tikzlibraryoptics.code.tex
2597 lines (2326 loc) · 89.9 KB
/
tikzlibraryoptics.code.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\iffalse
The tikzoptics library
Copyright (C) 2013-2019 by
Michel Fruchart <michel.fruchart@ens-lyon.org>
This work may be distributed and/or modified under the conditions of
the LaTeX Project Public License (LPPL), version 1.3c, which can be
found at the address:
https://www.latex-project.org/lppl/lppl-1-3c/
Alternatively, it may be distributed and/or modified under the conditions of
the GNU General Public License (GNU GPL), version 2, which can be found
at the address:
https://www.gnu.org/licenses/gpl-2.0.en.html
or any later version published by the Free Software Foundation.
\fi
\makeatletter
\def\tikzopticsversion{0.2.5-alpha}
\def\tikzopticsversiondate{2020-01-25}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% errors from this library
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\opticserror#1{\pgfutil@packageerror{tikz/optics}{#1}{}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% handler |collect unknowns|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% from http://tex.stackexchange.com/questions/81821/filtering-options-with-pgfkeys/81985#81985
% used by /tikz/optics/->n-
%
\pgfkeys{
/handlers/.collect unknowns/.style = {
unknown options/.initial = {},
.unknown/.code = {%
\letcs\reserved{pgfk@\pgfkeyscurrentpath/unknown options}%
\csedef{pgfk@\pgfkeyscurrentpath/unknown options}{%
\ifx\reserved\empty\else\expandonce\reserved,\fi
\expandonce\pgfkeyscurrentname
\ifx\pgfkeysnovalue##1\else=\expandonce\pgfkeyscurrentvalue\fi
}%
}
}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% defining |optics| family
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pgfkeys{
/tikz/.cd,
optics/.is family,
optics/.search also={/tikz},
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [use optics]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pgfkeys{
/tikz/use optics/.append code={
\pgfkeys{
/tikz/.cd,
% shapes
% 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
lens/.prefix style={shape=lens,optics,draw},
slit/.prefix style={shape=slit,optics,draw},
double slit/.prefix style={shape=double slit,optics,draw},
thin optics element/.prefix style={shape=thin optics element,optics,draw},
polarizer/.prefix style={shape=polarizer,optics,draw,object aspect ratio=0.1},
generic optics io/.prefix style={shape=generic optics io,optics,draw},
sensor/.prefix style={shape=sensor,optics,object aspect ratio=1,draw},
sensor line/.prefix style={shape=sensor line,optics,draw},
mirror/.prefix style={shape=mirror,optics,draw},
spherical mirror/.prefix style={shape=spherical mirror,optics,draw},
thick optics element/.prefix style={shape=thick optics element,optics,draw,object aspect ratio=0.1},
heat filter/.prefix style={shape=thick optics element,optics,draw, object aspect ratio=0.05},
double amici prism/.prefix style={shape=double amici prism,optics,draw, prism height=1cm, prism apex angle=60},
% styles
screen/.prefix style={optics,/tikz/optics/screen},
diffraction grating/.style={optics,/tikz/optics/diffraction grating},
grid/.style={optics, /tikz/optics/grid},
semi-transparent mirror/.style={optics, /tikz/optics/semi-transparent mirror},
diaphragm/.style={optics, /tikz/optics/diaphragm},
beam splitter/.prefix style={optics,/tikz/optics/beam splitter},
generic lamp/.prefix style={optics,/tikz/optics/generic lamp},
generic sensor/.prefix style={optics,/tikz/optics/generic sensor},
halogen lamp/.prefix style={optics,/tikz/optics/halogen lamp},
spectral lamp/.prefix style={optics,/tikz/optics/spectral lamp},
laser/.prefix style={optics,/tikz/optics/laser},
laser'/.prefix style={optics,/tikz/optics/laser'},
concave mirror/.prefix style={optics, /tikz/optics/concave mirror},
convex mirror/.prefix style={optics, /tikz/optics/convex mirror},
% arrows (styles)
->-/.prefix style={optics,/tikz/optics/->-={##1}},
-<-/.prefix style={optics,/tikz/optics/-<-={##1}},
->>-/.prefix style={optics,/tikz/optics/->>-={##1}},
-<<-/.prefix style={optics,/tikz/optics/-<<-={##1}},
->>>-/.prefix style={optics,/tikz/optics/->>>-={##1}},
-<<<-/.prefix style={optics,/tikz/optics/-<<<-={##1}},
->>>>-/.prefix style={optics,/tikz/optics/->>>>-={##1}},
-<<<<-/.prefix style={optics,/tikz/optics/-<<<<-={##1}},
->n-/.prefix style={optics,/tikz/optics/->n-={##1}},
-<n-/.prefix style={optics,/tikz/optics/-<n-={##1}},
pics/optics eye/.forward to=/tikz/optics@pics/optics eye,
}
}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% We need some existing tikz libraries and tex packages.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usetikzlibrary{decorations,decorations.markings, decorations.pathreplacing}
\usetikzlibrary{shapes.misc}
\usepackage{etoolbox}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Key |object height|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pgfkeys{/tikz/optics/.cd,
object height/.initial=2cm,
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Shape [thin optics element]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pgfdeclareshape{thin optics element}
{
\savedanchor{\center}{
\pgfpointorigin
}
\anchor{center}{\center}
\savedmacro\objectHeight{%
\edef\objectHeight{\pgfkeysvalueof{/tikz/optics/object height}}%
}
\savedanchor{\north}{
\pgf@x=0cm%
\pgf@y=\objectHeight%
\pgf@y=0.5\pgf@y%
}
\anchor{north}{\north}
\savedanchor{\south}{
\pgf@x=0cm%
\pgf@y=\objectHeight%
\pgf@y=-0.5\pgf@y%
}
\anchor{south}{\south}
\anchor{east}{\center}
\anchor{west}{\center}
\anchorborder{%
\pgf@xb=\pgf@x% xb/yb is target
\pgf@yb=\pgf@y%
\south%
\pgf@xa=\pgf@x% xa/ya is se
\pgf@ya=\pgf@y%
\north%
\advance\pgf@x by-\pgf@xa%
\advance\pgf@y by-\pgf@ya%
\pgf@xc=.5\pgf@x% x/y is half width/height
\pgf@yc=.5\pgf@y%
\advance\pgf@xa by\pgf@xc% xa/ya becomes center
\advance\pgf@ya by\pgf@yc%
\edef\pgf@marshal{%
\noexpand\pgfpointborderrectangle
{\noexpand\pgfpoint{\the\pgf@xb}{\the\pgf@yb}}
{\noexpand\pgfpoint{\the\pgf@xc}{\the\pgf@yc}}%
}%
\pgf@process{\pgf@marshal}%
\advance\pgf@x by\pgf@xa%
\advance\pgf@y by\pgf@ya%
}
\backgroundpath
{
\north \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\south \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Shape [lens]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newif\iftikz@optics@lens@converging
\tikz@optics@lens@convergingtrue
% keys
% - focal lens is used to define anchors |east focus| and |west focus|
% - lens height is used to define anchors |lens north| and |lens south|
% - lens type (converging or diverging)
\pgfkeys{/tikz/optics/.cd,
focal length/.initial=1cm,
lens height/.initial=0.8,
lens type/.is choice,
lens type/converging/.code={\tikz@optics@lens@convergingtrue},
lens type/diverging/.code={\tikz@optics@lens@convergingfalse}
}
\pgfdeclareshape{lens}
{
\savedanchor{\center}{
\pgfpointorigin
}
\anchor{center}{\center}
\savedmacro\focalLength{%
\edef\focalLength{\pgfkeysvalueof{/tikz/optics/focal length}}%
}
\savedmacro\objectHeight{%
\edef\objectHeight{\pgfkeysvalueof{/tikz/optics/object height}}%
}
\savedmacro\lensHeight{%
\pgfmathparse{\pgfkeysvalueof{/tikz/optics/lens height}}%
\ifpgfmathunitsdeclared%
\pgfmathsetlengthmacro{\lensHeight}{\pgfkeysvalueof{/tikz/optics/lens height}}%
\else%
\pgfmathsetlengthmacro{\lensHeight}{\pgfkeysvalueof{/tikz/optics/lens height}*\pgfkeysvalueof{/tikz/optics/object height}}%
\fi%
}
\savedanchor{\lensnorth}{
\pgfpointorigin
\pgf@y=\lensHeight%
\pgf@y=0.5\pgf@y%
}
\anchor{lens north}{\lensnorth}
\savedanchor{\lenssouth}{
\pgfpointorigin
\pgf@y=\lensHeight%
\pgf@y=-0.5\pgf@y%
}
\anchor{lens south}{\lenssouth}
\savedanchor{\north}{
\pgf@x=0cm%
\pgf@y=\objectHeight%
\pgf@y=0.5\pgf@y%
}
\anchor{north}{\north}
\savedanchor{\south}{
\pgf@x=0cm%
\pgf@y=\objectHeight%
\pgf@y=-0.5\pgf@y%
}
\anchor{south}{\south}
\savedanchor{\eastfocal}{
\pgf@x=\focalLength%
\pgf@y=0cm%
}
\anchor{east focal point}{\eastfocal}
\anchor{east focus}{\eastfocal}
\savedanchor{\westfocal}{
\pgf@x=-\focalLength%
\pgf@y=0cm%
}
\anchor{west focal point}{\westfocal}
\anchor{west focus}{\westfocal}
\anchor{east}{\center}
\anchor{west}{\center}
\inheritanchorborder[from=thin optics element]
\backgroundpath
{
\north \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\south \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
\iftikz@optics@lens@converging
\pgfsetarrowsstart{lens arrow}
\pgfsetarrowsend{lens arrow}
\else
\pgfsetarrowsstart{lens arrow reversed}
\pgfsetarrowsend{lens arrow reversed}
\fi
}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Shape [slit]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% keys : slit height
\pgfkeys{/tikz/optics/.cd,
slit height/.initial=0.1
}
\pgfdeclareshape{slit}
{
\savedanchor{\center}{
\pgfpointorigin
}
\anchor{center}{\center}
\anchor{slit center}{\center}
% TODO par cohérence ?
\savedmacro\objectHeight{%
\edef\objectHeight{\pgfkeysvalueof{/tikz/optics/object height}}%
}
\savedmacro\slitHeight{%
\pgfmathparse{\pgfkeysvalueof{/tikz/optics/slit height}}%
\ifpgfmathunitsdeclared%
\pgfmathsetlengthmacro{\slitHeight}{\pgfkeysvalueof{/tikz/optics/slit height}}%
\else%
\pgfmathsetlengthmacro{\slitHeight}{\pgfkeysvalueof{/tikz/optics/slit height}*\pgfkeysvalueof{/tikz/optics/object height}}%
\fi%
}
\savedanchor{\north}{
\pgf@x=0cm%
\pgf@y=\objectHeight%
\pgf@y=0.5\pgf@y%
}
\anchor{north}{\north}
\savedanchor{\south}{
\pgf@x=0cm%
\pgf@y=\objectHeight%
\pgf@y=-0.5\pgf@y%
}
\anchor{south}{\south}
\savedanchor{\slitnorth}{
\pgf@x=0cm%
\pgf@y=\slitHeight%
\pgf@y=0.5\pgf@y%
}
\anchor{slit north}{\slitnorth}
\savedanchor{\slitsouth}{
\pgf@x=0cm%
\pgf@y=\slitHeight%
\pgf@y=-0.5\pgf@y%
}
\anchor{slit south}{\slitsouth}
\anchor{east}{\center}
\anchor{west}{\center}
\inheritanchorborder[from=thin optics element]
\backgroundpath
{
% erreurs possibles dans la spécification du dessin
\pgfmathparse{notless(\slitHeight, \objectHeight)}
\ifnum\pgfmathresult=1
\opticserror{<slit height> should be strictly lower than <object height> (in slit)}
\fi
\north \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\slitnorth \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
\south \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\slitsouth \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Shape [double slit]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% keys :
% - slit height : (relative) height of the holes (each)
% - slit separation : (relative) distance between the centers of the holes
\pgfkeys{/tikz/optics/.cd,
object height/.initial=2cm,
slit height/.initial=0.075,
slit separation/.initial=0.2
}
\pgfdeclareshape{double slit}
{
\savedanchor{\center}{
\pgfpointorigin
}
\anchor{center}{\center}
\savedmacro\objectHeight{%
\edef\objectHeight{\pgfkeysvalueof{/tikz/optics/object height}}%
}
\savedmacro\slitHeight{%
\pgfmathparse{\pgfkeysvalueof{/tikz/optics/slit height}}%
\ifpgfmathunitsdeclared%
\pgfmathsetlengthmacro{\slitHeight}{\pgfkeysvalueof{/tikz/optics/slit height}}%
\else%
\pgfmathsetlengthmacro{\slitHeight}{\pgfkeysvalueof{/tikz/optics/slit height}*\pgfkeysvalueof{/tikz/optics/object height}}%
\fi%
}
\savedmacro\slitSeparation{%
\pgfmathparse{\pgfkeysvalueof{/tikz/optics/slit separation}}%
\ifpgfmathunitsdeclared%
\pgfmathsetlengthmacro{\slitSeparation}{\pgfkeysvalueof{/tikz/optics/slit separation}}%
\else%
\pgfmathsetlengthmacro{\slitSeparation}{\pgfkeysvalueof{/tikz/optics/slit separation}*\pgfkeysvalueof{/tikz/optics/object height}}%
\fi%
}
\savedmacro\macro@slitOneCenter{
\def\macro@slitOneCenter{
\pgfpointorigin
\pgf@ya=\slitSeparation
\pgf@ya=0.5\pgf@ya
\advance \pgf@y by \pgf@ya
}
}
\savedmacro\macro@slitTwoCenter{
\def\macro@slitTwoCenter{
\pgfpointorigin
\pgf@ya=\slitSeparation
\pgf@ya=-0.5\pgf@ya
\advance \pgf@y by \pgf@ya
}
}
\savedanchor{\north}{
\pgf@x=0cm%
\pgf@y=\objectHeight%
\pgf@y=0.5\pgf@y%
}
\anchor{north}{\north}
\savedanchor{\south}{
\pgf@x=0cm%
\pgf@y=\objectHeight%
\pgf@y=-0.5\pgf@y%
}
\anchor{south}{\south}
% slit 1
\savedanchor{\slitOneCenter}{
\macro@slitOneCenter
}
\anchor{slit 1 center}{\slitOneCenter}
\savedanchor{\slitOneNorth}{
\macro@slitOneCenter
\pgf@ya = \slitHeight
\pgf@ya = 0.5\pgf@ya
\advance \pgf@y by \pgf@ya
}
\anchor{slit 1 north}{\slitOneNorth}
\savedanchor{\slitOneSouth}{
\macro@slitOneCenter
\pgf@ya = \slitHeight
\pgf@ya = -0.5\pgf@ya
\advance \pgf@y by \pgf@ya
}
\anchor{slit 1 south}{\slitOneSouth}
% slit 2
\savedanchor{\slitTwoCenter}{
\macro@slitTwoCenter
}
\anchor{slit 2 center}{\slitTwoCenter}
\savedanchor{\slitTwoNorth}{
\macro@slitTwoCenter
\pgf@ya = \slitHeight
\pgf@ya = 0.5\pgf@ya
\advance \pgf@y by \pgf@ya
}
\anchor{slit 2 north}{\slitTwoNorth}
\savedanchor{\slitTwoSouth}{
\macro@slitTwoCenter
\pgf@ya = \slitHeight
\pgf@ya = -0.5\pgf@ya
\advance \pgf@y by \pgf@ya
}
\anchor{slit 2 south}{\slitTwoSouth}
\anchor{east}{\center}
\anchor{west}{\center}
\inheritanchorborder[from=thin optics element]
\backgroundpath
{
% erreurs possibles dans les spécifications du dessin
\pgfmathparse{notgreater(\slitSeparation, \slitHeight)}
\ifnum\pgfmathresult=1
\opticserror{<slit separation> should be strictly lower than <slit height> (in double slit)}
\fi
\pgfmathparse{notless(\slitSeparation+\slitHeight, \objectHeight)}
\ifnum\pgfmathresult=1
\opticserror{<slit height> plus <slit separation> should be strictly lower than <object height> (in double slit)}
\fi
\north \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\slitOneNorth \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
\slitOneSouth \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\slitTwoNorth \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
\slitTwoSouth \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\south \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Shape [mirror]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% keys
% - mirror decoration separation
% - mirror decoration amplitude
\pgfkeys{/tikz/optics/.cd,
object height/.initial=2cm,
mirror decoration separation/.initial=0.15cm,
mirror decoration amplitude/.initial=0.125cm,
}
\pgfdeclareshape{mirror}
{
\savedanchor{\center}{
\pgfpointorigin
}
\anchor{center}{\center}
\savedmacro\objectHeight{%
\edef\objectHeight{\pgfkeysvalueof{/tikz/optics/object height}}%
}
\savedanchor{\north}{
\pgf@x=0cm%
\pgf@y=\objectHeight%
\pgf@y=0.5\pgf@y%
}
\anchor{north}{\north}
\savedanchor{\south}{
\pgf@x=0cm%
\pgf@y=\objectHeight%
\pgf@y=-0.5\pgf@y%
}
\anchor{south}{\south}
\anchor{east}{\center}
\anchor{west}{\center}
% bof
\inheritanchorborder[from=thin optics element]
\backgroundpath
{
\north \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\south \pgf@xb=\pgf@x \pgf@yb=\pgf@y
% We use a border decoration to make a mirror (hachures).
% First set the decoration parameters :
% - decoration angle
% 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)
\def\pgfdecorationsegmentangle{45-180}%
% - decoration step length
\pgfmathparse{\pgfkeysvalueof{/tikz/optics/mirror decoration separation}}
\ifpgfmathunitsdeclared%
\pgfmathsetlengthmacro{\pgfdecorationsegmentlength}{\pgfkeysvalueof{/tikz/optics/mirror decoration separation}}%
\else%
\pgfmathsetlengthmacro{\pgfdecorationsegmentlength}{\pgfkeysvalueof{/tikz/optics/mirror decoration separation}*\pgfkeysvalueof{/tikz/optics/object height}}%
\fi%
% magouillons pour que \pgfdecorationsegmentlength soit un multiple de la longueur ...
\pgfmathsetmacro\initialstep{\pgfdecorationsegmentlength}
\pgfmathsetmacro\totallength{\pgfkeysvalueof{/tikz/optics/object height}}
\pgfmathsetmacro\newstep{\totallength/floor(\totallength/\initialstep)}
\pgfmathsetlengthmacro{\pgfdecorationsegmentlength}{\newstep}
% fin magouille
% - decoration amplitude
% on multiplie par -1 pour que ça aille dans le bon sens (pour éviter des problèmes louches)
\pgfmathparse{\pgfkeysvalueof{/tikz/optics/mirror decoration amplitude}}
\ifpgfmathunitsdeclared%
\pgfmathsetlengthmacro{\pgfdecorationsegmentamplitude}{-1*\pgfkeysvalueof{/tikz/optics/mirror decoration amplitude}}%
\else%
\pgfmathsetlengthmacro{\pgfdecorationsegmentamplitude}{-1*\pgfkeysvalueof{/tikz/optics/mirror decoration amplitude}*\pgfkeysvalueof{/tikz/optics/object height}}%
\fi%
% Use decoration.
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
\pgfdecoratecurrentpath{border} %
% dessin du miroir (trait)
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Shape [spherical mirror]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% keys :
% - spherical mirror angle : the aperture angle of the mirror
% - spherical mirror type (concave or convex)
% - spherical mirror orientation (ltr or rtl)
% The properties of the decoration are controled by the same parameters as in [mirror].
% Height is controled by |object height|, as usual.
\pgfkeys{/tikz/optics/spherical mirror angle/.initial=150}
\newif\iftikz@optics@sphericalmirror@concave
\tikz@optics@sphericalmirror@concavetrue
\pgfkeys{/tikz/optics/.cd,
spherical mirror type/.is choice,
spherical mirror type/concave/.code={\tikz@optics@sphericalmirror@concavetrue},
spherical mirror type/convex/.code={\tikz@optics@sphericalmirror@concavefalse}
}
\newif\iftikz@optics@sphericalmirror@ltr
\tikz@optics@sphericalmirror@ltrtrue
\pgfkeys{/tikz/optics/.cd,
spherical mirror orientation/.is choice,
spherical mirror orientation/ltr/.code={\tikz@optics@sphericalmirror@ltrtrue},
spherical mirror orientation/rtl/.code={\tikz@optics@sphericalmirror@ltrfalse}
}
% shortcuts (styles) : [concave mirror] and [convex mirror]
\pgfkeys{/tikz/optics/.cd,
concave mirror/.style={optics, spherical mirror, /tikz/optics/spherical mirror type=concave},
convex mirror/.style={optics, spherical mirror, /tikz/optics/spherical mirror type=convex},
}
\pgfdeclareshape{spherical mirror}{%
\savedmacro\installsphericalmirrorparameters{%
%
% Define a \centerpoint
%
\pgfextract@process\centerpoint{%
\pgfpointorigin
}%
%
% Define height
%
\pgfmathsetlengthmacro\height{\pgfkeysvalueof{/tikz/optics/object height}}%
%
% Function to define angle from radius
% use e.g. [spherical mirror angle=from_radius(2cm)] instead of e.g. [spherical mirror angle=90]
% This can seem somewhat ridiculous as we will undo this when calculating \radius, however it helps providing a simpler API.
% This function has to be defined before parsing \pgfkeysvalueof{/tikz/optics/spherical mirror angle}.
%
\pgfmathdeclarefunction{from_radius}{1}{
\begingroup
\pgfmathparse{notless(2*#1,\height)}
\ifnum\pgfmathresult=0
\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.}
\fi
\newdimen\angle
\pgfmathsetlength\angle{2*asin(\height/(2*#1))}
\pgf@x=\angle
\pgfmathreturn\pgf@x
\endgroup
}
%
% Define angle
%
\pgfmathsetmacro\angle{\pgfkeysvalueof{/tikz/optics/spherical mirror angle}}
%
% Compute radius from height and angle
%
\pgfmathsetlengthmacro\radius{\height/(2*sin(\angle/2))}
%
% Half of the sector angle is more useful.
%
\pgfmathmod{\angle}{360}%
\ifdim\pgfmathresult pt<0pt\relax%
\pgfmathadd@{\pgfmathresult}{360}%
\fi%
\let\angle\pgfmathresult%
\pgfmathdivide@{\pgfmathresult}{2}%
\let\halfangle\pgfmathresult%
%
% Get the start and end angles of the arc.
%
\iftikz@optics@sphericalmirror@concave
\iftikz@optics@sphericalmirror@ltr
\pgfmathsetmacro\startangle{-\halfangle}
\pgfmathsetmacro\endangle{+\halfangle}
\else
\pgfmathsetmacro\startangle{180-\halfangle}
\pgfmathsetmacro\endangle{180+\halfangle}
\fi
\else
\iftikz@optics@sphericalmirror@ltr
\pgfmathsetmacro\startangle{180-\halfangle}
\pgfmathsetmacro\endangle{180+\halfangle}
\else
\pgfmathsetmacro\startangle{-\halfangle}
\pgfmathsetmacro\endangle{+\halfangle}
\fi
\fi
%
% Calculate R cos(angle/2) and R sin(angle/2)
%
\pgfmathabs@{\halfangle}%
\pgfmathcos@{\pgfmathresult}%
\let\coshalfangle\pgfmathresult%
\pgfmathabs@{\halfangle}%
\pgfmathsin@{\pgfmathresult}%
\let\sinhalfangle\pgfmathresult%
\pgfmathsetlength\pgf@xa{\radius*\coshalfangle}
\edef\rcoshalfangle{\the\pgf@xa}%
\pgfmathsetlength\pgf@xa{\radius*\sinhalfangle}
\edef\rsinhalfangle{\the\pgf@xa}%
%
% Calculate the arc coordinates
%
\pgfextract@process\arcstart{%
\pgfqpointpolar{\startangle}{\radius}%
\pgf@xa\pgf@x%
\pgf@ya\pgf@y%
\centerpoint%
\advance\pgf@x\pgf@xa%
\advance\pgf@y\pgf@ya%
}%
\pgfextract@process\arcend{%
\pgfqpointpolar{\endangle}{\radius}%
\pgf@xa\pgf@x%
\pgf@ya\pgf@y%
\centerpoint%
\advance\pgf@x\pgf@xa%
\advance\pgf@y\pgf@ya%
}%
\def\convexrtlsetx#1#2{
\iftikz@optics@sphericalmirror@concave%
\iftikz@optics@sphericalmirror@ltr%
\advance\pgf@x by #1
\else% % => rtl
\advance\pgf@x by #2
\fi%
\else% % => convex
\iftikz@optics@sphericalmirror@ltr%
\advance\pgf@x by #2
\else% % => rtl
\advance\pgf@x by #1
\fi%
\fi%
}
\def\convexrtlinvert{%
\iftikz@optics@sphericalmirror@concave%
\iftikz@optics@sphericalmirror@ltr%
%nothing
\else% % => rtl
\pgf@x=-\pgf@x%
\fi%
\else% % => convex
\iftikz@optics@sphericalmirror@ltr%
\pgf@x=-\pgf@x%
\else% % => rtl
%nothing
\fi%
\fi%
}%
%
% Save everything.
% "NB \addtosavedmacro is currently experimental. May get changed." d'après le code où je l'ai piqué
%
\addtosavedmacro{\radius}%
%
\addtosavedmacro{\rcoshalfangle}%
\addtosavedmacro{\rsinhalfangle}%
%
\addtosavedmacro{\endangle}%
\addtosavedmacro{\startangle}%
%
\addtosavedmacro{\centerpoint}%
\addtosavedmacro{\arcstart}%
\addtosavedmacro{\arcend}%
\addtosavedmacro{\convexrtlinvert}%
%
}%
%
% Define anchors
%
\savedanchor\mirrorcenterpoint{%
\pgfpointorigin
}%
\savedanchor\centerpoint{%
\pgfpointorigin%
\advance\pgf@x by \radius%
\advance\pgf@x by \rcoshalfangle%
\iftikz@optics@sphericalmirror@concave%
\iftikz@optics@sphericalmirror@ltr%
%nothing
\else% % => rtl
\pgf@x=-\pgf@x%
\fi%
\else% % => convex
\iftikz@optics@sphericalmirror@ltr%
\pgf@x=-\pgf@x%
\else% % => rtl
%nothing
\fi%
\fi%
\divide\pgf@x by 2%
}%
\savedanchor\focalpoint{%
\pgfpointorigin%
\pgf@xa=\radius%
\advance\pgf@x by .5\pgf@xa%
\iftikz@optics@sphericalmirror@concave%
\iftikz@optics@sphericalmirror@ltr%
%nothing
\else% % => rtl
\pgf@x=-\pgf@x%
\fi%
\else% % => convex
\iftikz@optics@sphericalmirror@ltr%
\pgf@x=-\pgf@x%
\else% % => rtl
%nothing
\fi%
\fi%
}%
\savedanchor\north{%
\pgfpointorigin
\pgf@xa=0pt
\advance\pgf@xa by \rcoshalfangle
\advance\pgf@xa by \radius
\divide\pgf@xa by 2
\advance\pgf@x by \pgf@xa
\advance\pgf@y by \rsinhalfangle
\convexrtlinvert
}%
\savedanchor\arccenter{%
\centerpoint
\advance\pgf@x by \radius
\convexrtlinvert
}
\savedanchor\south{%
\pgfpointorigin
\pgf@xa=0pt
\advance\pgf@xa by \rcoshalfangle
\advance\pgf@xa by \radius
\divide\pgf@xa by 2
\advance\pgf@x by \pgf@xa
\advance\pgf@y by -\rsinhalfangle
\convexrtlinvert
}
\savedanchor\east{%
\pgfpointorigin
\convexrtlsetx{\radius}{\rcoshalfangle}
\convexrtlinvert
}
\savedanchor\west{%
\pgfpointorigin
\convexrtlsetx{\rcoshalfangle}{\radius}
\convexrtlinvert
}
\savedanchor\northwest{%
\pgfpointorigin
\convexrtlsetx{\rcoshalfangle}{\radius}
\advance\pgf@y by \rsinhalfangle
\convexrtlinvert
}
\savedanchor\southwest{%
\pgfpointorigin
\convexrtlsetx{\rcoshalfangle}{\radius}
\advance\pgf@y by -\rsinhalfangle
\convexrtlinvert
}
\savedanchor\northeast{%
\pgfpointorigin
\convexrtlsetx{\radius}{\rcoshalfangle}
\advance\pgf@y by \rsinhalfangle
\convexrtlinvert
}
\savedanchor\southeast{%
\pgfpointorigin
\convexrtlsetx{\radius}{\rcoshalfangle}
\advance\pgf@y by -\rsinhalfangle
\convexrtlinvert
}
\anchor{arc start}{%
\installsphericalmirrorparameters%
\arcstart%
}
\anchor{arc end}{%
\installsphericalmirrorparameters%
\arcend%
}
\anchor{focal point}{%
\installsphericalmirrorparameters%
\focalpoint
}
\anchor{focus}{%
\installsphericalmirrorparameters%
\focalpoint
}
\anchor{mirror center}{\mirrorcenterpoint}
\anchor{center}{\centerpoint}
\anchor{arc center}{\arccenter}
\anchor{north}{\north}%
\anchor{south}{\south}%
\anchor{east}{\east}%
\anchor{west}{\west}%
\anchor{north west}{\northwest}%
\anchor{south west}{\southwest}%
\anchor{north east}{\northeast}%
\anchor{south east}{\southeast}%
%
% Draw backgroundpath
%
\backgroundpath{%
\installsphericalmirrorparameters%
% We use a border decoration to make a mirror.
% First set the decoration parameters :
% - decoration angle
\iftikz@optics@sphericalmirror@concave
\def\pgfdecorationsegmentangle{45}%
\else
\def\pgfdecorationsegmentangle{-90-45}%
\fi
% - decoration step length
\pgfmathparse{\pgfkeysvalueof{/tikz/optics/mirror decoration separation}}
\ifpgfmathunitsdeclared%
\pgfmathsetlengthmacro{\pgfdecorationsegmentlength}{\pgfkeysvalueof{/tikz/optics/mirror decoration separation}}%
\else%
\pgfmathsetlengthmacro{\pgfdecorationsegmentlength}{\pgfkeysvalueof{/tikz/optics/mirror decoration separation}*\pgfkeysvalueof{/tikz/optics/object height}}%
\fi%
% magouillons pour que \pgfdecorationsegmentlength soit un multiple de la longueur ...
\pgfmathsetmacro\initialstep{\pgfdecorationsegmentlength}
\pgfmathsetmacro\totallength{(2*pi/360)*\angle*\radius}
\pgfmathsetmacro\newstep{\totallength/floor(\totallength/\initialstep)}
\pgfmathsetlengthmacro{\pgfdecorationsegmentlength}{\newstep}
% fin magouille
% - decoration amplitude
% on multiplie par -1 pour que ça aille dans le bon sens sans devoir modifier l'angle (pour éviter des problèmes louches)
\pgfmathparse{\pgfkeysvalueof{/tikz/optics/mirror decoration amplitude}}
\ifpgfmathunitsdeclared%
\pgfmathsetlengthmacro{\pgfdecorationsegmentamplitude}{-1*\pgfkeysvalueof{/tikz/optics/mirror decoration amplitude}}%
\else%
\pgfmathsetlengthmacro{\pgfdecorationsegmentamplitude}{-1*\pgfkeysvalueof{/tikz/optics/mirror decoration amplitude}*\pgfkeysvalueof{/tikz/optics/object height}}%
\fi%
% Now use decoration.
% Draw decoration of path : an arc of radius \radius from \arcstart to \arcend
\pgfpathmoveto{\arcstart}%
\pgfpatharc{\startangle}{\endangle}{\radius}%
\pgfdecoratecurrentpath{border} %
% Now draw the path.
\pgfpathmoveto{\arcstart}%
\pgfpatharc{\startangle}{\endangle}{\radius}%
}
%
% Anchor border
% This is needed for anchors .<angle> (like mirror.0, mirror.90, etc.) to work.
%
\anchorborder{%
% Save x and y
\edef\externalx{\the\pgf@x}%
\edef\externaly{\the\pgf@y}%
\installsphericalmirrorparameters%
% Use circular border
\pgfpointborderellipse{ \pgfpoint{\externalx}{\externaly} }{ \pgfpoint{\radius}{\radius} }%
}%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Shape [thick optics element]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% keys :
% - object aspect ratio (alias : object width)
% ar = largeur/hauteur => largeur = ar * hauteur
\pgfkeys{/tikz/optics/.cd,
object aspect ratio/.initial=0.2,
object width/.style={/tikz/optics/object aspect ratio=#1}