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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
|
\iffalse
The tikzoptics library
Copyright (C) 2013-2016 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.3}
\def\tikzopticsversiondate{2017-03-11}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 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}},
}
}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% We need some existing tikz libraries and tex packages.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usetikzlibrary{decorations,decorations.markings, decorations.pathreplacing}
\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}
}
\pgfdeclareshape{thick optics element}
{
\savedanchor{\center}{
\pgfpointorigin
}
\anchor{center}{\center}
\savedmacro\objectHeight{%
\edef\objectHeight{\pgfkeysvalueof{/tikz/optics/object height}}%
}
\savedmacro\objectWidth{%
\pgfmathparse{\pgfkeysvalueof{/tikz/optics/object aspect ratio}}
\ifpgfmathunitsdeclared%
\pgfmathsetlengthmacro{\objectWidth}{\pgfkeysvalueof{/tikz/optics/object aspect ratio}}%
\else%
\pgfmathsetlengthmacro{\objectWidth}{\pgfkeysvalueof{/tikz/optics/object aspect ratio}*\pgfkeysvalueof{/tikz/optics/object height}}%
\fi%
}
\savedanchor{\northeast}{
\pgf@x=\objectWidth%
\pgf@y=\objectHeight%
\pgf@y=0.5\pgf@y%
\pgf@x=0.5\pgf@x%
}
\anchor{north east}{\northeast}
\savedanchor{\southwest}{
\pgf@x=\objectWidth%
\pgf@y=\objectHeight%
\pgf@y=-0.5\pgf@y%
\pgf@x=-0.5\pgf@x%
}
\anchor{south west}{\southwest}
\anchor{north}{
\center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xa
\pgf@y=\pgf@yb
}
\anchor{south}{
\center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\southwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xa
\pgf@y=\pgf@yb
}
\anchor{east}{
\center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xb
\pgf@y=\pgf@ya
}
\anchor{west}{
\center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\southwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xb
\pgf@y=\pgf@ya
}
\anchor{north west}{
\northeast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\southwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xb
\pgf@y=\pgf@ya
}
\anchor{south east}{
\northeast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\southwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xa
\pgf@y=\pgf@yb
}
\inheritanchorborder[from=rectangle]
\backgroundpath
{
% rectangle
\pgfpathrectanglecorners{\northeast}{\southwest}
}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Shape [polarizer]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pgfdeclareshape{polarizer}
{
\savedanchor{\center}{
\pgfpointorigin
}
\anchor{center}{\center}
\savedmacro\objectHeight{%
\edef\objectHeight{\pgfkeysvalueof{/tikz/optics/object height}}%
}
\savedmacro\objectWidth{%
\pgfmathparse{\pgfkeysvalueof{/tikz/optics/object aspect ratio}}
\ifpgfmathunitsdeclared%
\pgfmathsetlengthmacro{\objectWidth}{\pgfkeysvalueof{/tikz/optics/object aspect ratio}}%
\else%
\pgfmathsetlengthmacro{\objectWidth}{\pgfkeysvalueof{/tikz/optics/object aspect ratio}*\pgfkeysvalueof{/tikz/optics/object height}}%
\fi%
}
\savedanchor{\northeast}{
\pgf@x=\objectWidth%
\pgf@y=\objectHeight%
\pgf@y=0.5\pgf@y%
\pgf@x=0.5\pgf@x%
}
\anchor{north east}{\northeast}
\savedanchor{\southwest}{
\pgf@x=\objectWidth%
\pgf@y=\objectHeight%
\pgf@y=-0.5\pgf@y%
\pgf@x=-0.5\pgf@x%
}
\anchor{south west}{\southwest}
\anchor{north}{
\center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xa
\pgf@y=\pgf@yb
}
\anchor{south}{
\center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\southwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xa
\pgf@y=\pgf@yb
}
\anchor{east}{
\center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xb
\pgf@y=\pgf@ya
}
\anchor{west}{
\center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\southwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xb
\pgf@y=\pgf@ya
}
\anchor{north west}{
\northeast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\southwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xb
\pgf@y=\pgf@ya
}
\anchor{south east}{
\northeast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\southwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xa
\pgf@y=\pgf@yb
}
\inheritanchorborder[from=rectangle]
\backgroundpath
{
% rectangle
\pgfpathrectanglecorners{\northeast}{\southwest}
% diagonale du polariseur
\northeast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\southwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Shape [double amici prism]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% keys :
% - prism height
% - prism apex angle
\pgfkeys{/tikz/optics/.cd,
prism height/.initial=1.5cm,
prism apex angle/.initial=60,
}
% Idea : we get
% apexAngle
% prismHeight
% demiPrismWidth = tan(apexAngle/2)*prismHeight
%
% so we compute
%
% C = (0,0)
% NE = (demiPrismWidth,0.5*prismHeight)
% SW = (-2*demiPrismWidth,-0.5*prismHeight)
% NW = (-demiPrismWidth,0.5*prismHeight)
% SE = (2*demiPrismWidth,-0.5*prismHeight)
%
% N = (0,0.5*prismHeight)
% S = (0,-0.5*prismHeight)
% E = (3*0.5*demiPrismWidth,0)
% W = (-3.0.5*demiPrismWidth,0)
\pgfdeclareshape{double amici prism}
{
\savedanchor{\center}{
\pgfpointorigin
}
\anchor{center}{\center}
\savedmacro\prismHeight{%
\edef\prismHeight{\pgfkeysvalueof{/tikz/optics/prism height}}%
}
\savedmacro\apexAngle{%
\pgfmathsetlengthmacro{\apexAngle}{\pgfkeysvalueof{/tikz/optics/prism apex angle}}
}
\savedmacro\demiPrismWidth{%
\pgfmathsetlengthmacro{\demiPrismWidth}{tan(0.5*\pgfkeysvalueof{/tikz/optics/prism apex angle})*\pgfkeysvalueof{/tikz/optics/prism height}}
}
\savedanchor{\northeast}{
\pgf@x=\demiPrismWidth%
\pgf@y=\prismHeight%
\pgf@y=0.5\pgf@y%
}
\anchor{north east}{\northeast}
\savedanchor{\southwest}{
\pgf@x=\demiPrismWidth%
\pgf@y=\prismHeight%
\pgf@x=-2\pgf@x%
\pgf@y=-0.5\pgf@y%
}
\anchor{south west}{\southwest}
\savedanchor{\northwest}{
\pgf@x=\demiPrismWidth%
\pgf@y=\prismHeight%
\pgf@x=-\pgf@x%
\pgf@y=0.5\pgf@y%
}
\anchor{north west}{\northwest}
\savedanchor{\southeast}{
\pgf@x=\demiPrismWidth%
\pgf@y=\prismHeight%
\pgf@x=2\pgf@x%
\pgf@y=-0.5\pgf@y%
}
\anchor{south east}{\southeast}
\anchor{north}{
\center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xa
\pgf@y=\pgf@yb
}
\savedanchor{\south}{
\pgfpointorigin
\pgf@y=\prismHeight%
\pgf@y=-0.5\pgf@y%
}
\anchor{south}{\south}
\anchor{east}{
\southeast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xa
\advance\pgf@x by\pgf@xb
\pgf@x=0.5\pgf@x
\pgf@y=\pgf@ya
\advance\pgf@y by\pgf@yb
\pgf@y=0.5\pgf@y
}
\anchor{west}{
\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xa
\advance\pgf@x by\pgf@xb
\pgf@x=0.5\pgf@x
\pgf@y=\pgf@ya
\advance\pgf@y by\pgf@yb
\pgf@y=0.5\pgf@y
}
\inheritanchorborder[from=rectangle]
\backgroundpath
{
\northwest
\pgfpathmoveto{\pgfpoint{\pgf@x}{\pgf@y}}
\southwest
\pgfpathlineto{\pgfpoint{\pgf@x}{\pgf@y}}
\southeast
\pgfpathlineto{\pgfpoint{\pgf@x}{\pgf@y}}
\northeast
\pgfpathlineto{\pgfpoint{\pgf@x}{\pgf@y}}
\pgfpathclose
%
% FIXME : ceci devrait s'appliquer seulement au triangle intérieur -> un fgpath ou assimilé
\pgfsetbeveljoin
\northwest
\pgfpathmoveto{\pgfpoint{\pgf@x}{\pgf@y}}
\south
\pgfpathlineto{\pgfpoint{\pgf@x}{\pgf@y}}
\northeast
\pgfpathlineto{\pgfpoint{\pgf@x}{\pgf@y}}
}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Shape [generic optics io]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% keys :
% - io body height : height of the body of the io body
% - io body aspect ratio (alias io body width) : width/height of the body of the io body
% - io aperture width : width of the output device (condenser, etc.) [in units of io body height]
% - io aperture height : height of the output device (condenser, etc.) [in units of io body height]
% - io aperture shift : vertical shift of the output device [in units of io body height]
% - io orientation (ltr or rtl)
\pgfkeys{/tikz/optics/.cd,
io body height/.initial=0.75cm,
io body aspect ratio/.initial=2,
io aperture width/.initial=0.33,
io aperture height/.initial=0.66,
io aperture shift/.initial=0,
}
\pgfkeys{/tikz/optics/io body width/.style={/tikz/optics/io body aspect ratio=#1}}
%
\newif\if@tikz@optics@io@ltr
\@tikz@optics@io@ltrtrue
%
\pgfkeys{/tikz/optics/io orientation/.is choice}
\pgfkeys{/tikz/optics/io orientation/ltr/.code={\@tikz@optics@io@ltrtrue}}
\pgfkeys{/tikz/optics/io orientation/rtl/.code={\@tikz@optics@io@ltrfalse}}
%
\pgfdeclareshape{generic optics io}
{
\savedanchor{\center}{
\pgfpointorigin
}
\anchor{center}{\center}
\savedmacro\objectHeight{%
\edef\objectHeight{\pgfkeysvalueof{/tikz/optics/io body height}}%
}
\savedmacro\objectWidth{%
\pgfmathparse{\pgfkeysvalueof{/tikz/optics/io body aspect ratio}}
\ifpgfmathunitsdeclared%
\pgfmathsetlengthmacro{\objectWidth}{\pgfkeysvalueof{/tikz/optics/io body aspect ratio}}%
\else%
\pgfmathsetlengthmacro{\objectWidth}{\pgfkeysvalueof{/tikz/optics/io body aspect ratio}*\pgfkeysvalueof{/tikz/optics/io body height}}%
\fi%
}
\savedmacro\outHeight{%
\pgfmathparse{\pgfkeysvalueof{/tikz/optics/io aperture height}}
\ifpgfmathunitsdeclared%
\pgfmathsetlengthmacro{\outHeight}{\pgfkeysvalueof{/tikz/optics/io aperture height}}%
\else%
\pgfmathsetlengthmacro{\outHeight}{\pgfkeysvalueof{/tikz/optics/io aperture height}*\pgfkeysvalueof{/tikz/optics/io body height}}%
\fi%
}
\savedmacro\outWidth{%
\pgfmathparse{\pgfkeysvalueof{/tikz/optics/io aperture width}}
\ifpgfmathunitsdeclared%
\pgfmathsetlengthmacro{\outWidth}{\pgfkeysvalueof{/tikz/optics/io aperture width}}%
\else%
\pgfmathsetlengthmacro{\outWidth}{\pgfkeysvalueof{/tikz/optics/io aperture width}*\pgfkeysvalueof{/tikz/optics/io body height}}%
\fi%
}
\savedmacro\outShift{%
\pgfmathparse{\pgfkeysvalueof{/tikz/optics/io aperture shift}}
\ifpgfmathunitsdeclared%
\pgfmathsetlengthmacro{\outShift}{\pgfkeysvalueof{/tikz/optics/io aperture shift}}%
\else%
\pgfmathsetlengthmacro{\outShift}{\pgfkeysvalueof{/tikz/optics/io aperture shift}*\pgfkeysvalueof{/tikz/optics/io body height}}%
\fi%
}
\savedanchor{\bodynortheast}{
\pgf@x=\objectWidth%
\pgf@y=\objectHeight%
\pgf@y=0.5\pgf@y%
\pgf@x=0.5\pgf@x%
}
\anchor{body north east}{\bodynortheast}
\savedanchor{\bodysouthwest}{
\pgf@x=\objectWidth%
\pgf@y=\objectHeight%
\pgf@y=-0.5\pgf@y%
\pgf@x=-0.5\pgf@x%
}
\anchor{body south west}{\bodysouthwest}
\savedanchor{\outnortheast}{
\if@tikz@optics@io@ltr
% Left To Right (LTR)
\pgf@x=\objectWidth%
\pgf@x=0.5\pgf@x%
\advance\pgf@x by\outWidth
\else
% Right To Left (RTL)
\pgf@x=\objectWidth%
\pgf@x=0.5\pgf@x%
\pgf@x=-\pgf@x%
\fi
\pgf@y=0pt%
\advance\pgf@y by\outHeight
\pgf@y=0.5\pgf@y%
\advance\pgf@y by\outShift
}
\anchor{aperture north east}{\outnortheast}
\savedanchor{\outsouthwest}{
\if@tikz@optics@io@ltr
% Left To Right (LTR)
\pgf@x=\objectWidth%
\pgf@x=0.5\pgf@x%
\else
% Right To Left (RTL)
\pgf@x=\objectWidth%
\pgf@x=0.5\pgf@x%
\advance\pgf@x by\outWidth
\pgf@x=-\pgf@x%
\fi
\pgf@y=0pt%
\advance\pgf@y by\outHeight
\pgf@y=-0.5\pgf@y%
\advance\pgf@y by\outShift
}
\anchor{aperture south west}{\outsouthwest}
\savedanchor{\outcenter}{
\if@tikz@optics@io@ltr
% Left To Right (LTR)
\pgf@x=\objectWidth%
\advance\pgf@x by\outWidth
\else
% Right To Left (RTL)
\pgf@x=\objectWidth%
\advance\pgf@x by\outWidth
\pgf@x=-\pgf@x%
\fi
\pgf@x=0.5\pgf@x%
\pgf@y=0pt%
\advance\pgf@y by\outShift
}
\anchor{aperture center}{\outcenter}
\anchor{body center}{\center}
\anchor{text}{
\pgfpointorigin
\advance\pgf@x by -.5\wd\pgfnodeparttextbox%
\advance\pgf@y by -.5\ht\pgfnodeparttextbox%
\advance\pgf@y by +.5\dp\pgfnodeparttextbox%
}
\anchor{body north}{
\center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\bodynortheast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xa
\pgf@y=\pgf@yb
}
% north = body north
\anchor{north}{
\center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\bodynortheast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xa
\pgf@y=\pgf@yb
}
\anchor{body south}{
\center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\bodysouthwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xa
\pgf@y=\pgf@yb
}
% south = body south
\anchor{south}{
\center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\bodysouthwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xa
\pgf@y=\pgf@yb
}
\anchor{body east}{
\center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\bodynortheast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xb
\pgf@y=\pgf@ya
}
\anchor{body west}{
\center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\bodysouthwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xb
\pgf@y=\pgf@ya
}
\anchor{body north west}{
\bodynortheast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\bodysouthwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xb
\pgf@y=\pgf@ya
}
\anchor{body south east}{
\bodynortheast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\bodysouthwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xa
\pgf@y=\pgf@yb
}
\anchor{aperture north}{
\outcenter \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\outnortheast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xa
\pgf@y=\pgf@yb
}
\anchor{aperture south}{
\outcenter \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\outsouthwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xa
\pgf@y=\pgf@yb
}
\anchor{aperture east}{
\outcenter \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\outnortheast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xb
\pgf@y=\pgf@ya
}
\anchor{aperture west}{
\outcenter \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\outsouthwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xb
\pgf@y=\pgf@ya
}
\anchor{aperture north west}{
\outnortheast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\outsouthwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xb
\pgf@y=\pgf@ya
}
\anchor{aperture south east}{
\outnortheast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\outsouthwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xa
\pgf@y=\pgf@yb
}
\anchor{center}{\center}
\savedanchor{\realeast}{
\pgfpointorigin
\if@tikz@optics@io@ltr
% Left To Right (LTR)
%ltr : aperture east (<- out north east)
\pgf@x=\objectWidth%
\pgf@x=0.5\pgf@x%
\advance\pgf@x by\outWidth
%\pgf@y=0pt%
\else
% Right To Left (rtl)
\pgf@x=\objectWidth%
\pgf@x=0.5\pgf@x%
\fi
}
\anchor{east}{\realeast}
\savedanchor{\realwest}{
\pgfpointorigin
\if@tikz@optics@io@ltr
% Left To Right (LTR)
\pgf@x=\objectWidth%
\pgf@x=-0.5\pgf@x%
\else
% Right To Left (rtl)
\pgf@x=\objectWidth%
\pgf@x=0.5\pgf@x%
\advance\pgf@x by\outWidth
\pgf@x=-\pgf@x%
\fi
}
\anchor{west}{\realwest}
% this is used only for the anchorborder
\savedanchor{\anchorbordersouthwest}{
\if@tikz@optics@io@ltr
% Left To Right (LTR)
\pgf@x=\objectWidth%
\pgf@x=-0.5\pgf@x%
\else
% Right To Left (rtl)
\pgf@x=\objectWidth%
\pgf@x=0.5\pgf@x%
\advance\pgf@x by\outWidth
\pgf@x=-\pgf@x%
\fi
\pgf@y=\objectHeight%
\pgf@y=-0.5\pgf@y%
}
% this is used only for the anchorborder
\savedanchor{\anchorbordernortheast}{
\if@tikz@optics@io@ltr
% Left To Right (LTR)
\pgf@x=\objectWidth%
\pgf@x=0.5\pgf@x%
\advance\pgf@x by\outWidth
\else
% Right To Left (RTL)
\pgf@x=\objectWidth%
\pgf@x=0.5\pgf@x%
%\pgf@x=-\pgf@x%
\fi
\pgf@y=\objectHeight%
\pgf@y=0.5\pgf@y%
}
% anchorborder
% c'est celui de rectangle, mais un peu ajusté
\anchorborder{%
\pgf@xb=\pgf@x% xb/yb is target
\pgf@yb=\pgf@y%
\anchorbordersouthwest%
\pgf@xa=\pgf@x% xa/ya is se
\pgf@ya=\pgf@y%
\anchorbordernortheast%
\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\pgfqpoint{\the\pgf@xb}{\the\pgf@yb}}
{\noexpand\pgfqpoint{\the\pgf@xc}{\the\pgf@yc}}%
}%
\pgf@process{\pgf@marshal}%
% \advance\pgf@x by\pgf@xa%
% \advance\pgf@y by\pgf@ya%
}
\backgroundpath
{
% corps
\pgfpathrectanglecorners{\bodynortheast}{\bodysouthwest}
% out
\pgfpathrectanglecorners{\outnortheast}{\outsouthwest}
%\pgfusepath{draw}
% il ne faut PAS mettre ça pour pouvoir utiliser des styles correctement après (genre double)
}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Sensors
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Shape [sensor line]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Sensor line.
%
% This defines anchors center, north, south, east, west, north east
% north west, south east, south west, as well as
% pixel <i> <subanchor> with <subanchor> is any of the former.
% ça va être horrible à faire
%
% keys :
% - sensor line height
% - sensor line aspect ratio (largeur en unités de la hauteur du capteur)
% - sensor line pixel number
% - sensor line pixel width (en unités de la largeur du capteur)
% - sensor line inner ysep (en unités de la hauteur du capteur)
\pgfkeys{/tikz/optics/.cd,
sensor line height/.initial=2cm,
sensor line aspect ratio/.initial=0.2,
sensor line pixel number/.initial=5,
sensor line pixel width/.initial=0.4,
sensor line inner ysep/.initial=0.05, % entre le bord et les capteurs
}
\pgfdeclareshape{sensor line}
{
\savedanchor{\center}{
\pgfpointorigin
}
\anchor{center}{\center}
\savedmacro\objectHeight{%
\edef\objectHeight{\pgfkeysvalueof{/tikz/optics/sensor line height}}%
}
\savedmacro\objectWidth{%
\pgfmathsetlengthmacro{\objectWidth}{\pgfkeysvalueof{/tikz/optics/sensor line aspect ratio}*\pgfkeysvalueof{/tikz/optics/sensor line height}}
}
\savedmacro\pixelNumber{%
\pgfmathtruncatemacro\pixelNumber{\pgfkeysvalueof{/tikz/optics/sensor line pixel number}}%
}
\savedmacro\innerysep{%
\pgfmathparse{\pgfkeysvalueof{/tikz/optics/sensor line inner ysep}}
\ifpgfmathunitsdeclared%
\pgfmathsetlengthmacro{\innerysep}{\pgfkeysvalueof{/tikz/optics/sensor line inner ysep}}%
\else%
\pgfmathsetlengthmacro{\innerysep}{\pgfkeysvalueof{/tikz/optics/sensor line inner ysep}*\pgfkeysvalueof{/tikz/optics/sensor line height}}%
\fi%
}
\savedmacro\pixelWidth{%
\pgfmathparse{\pgfkeysvalueof{/tikz/optics/sensor line pixel width}}
\ifpgfmathunitsdeclared%
\pgfmathsetlengthmacro{\pixelWidth}{\pgfkeysvalueof{/tikz/optics/sensor line pixel width}}%
\else%
\pgfmathsetlengthmacro{\pixelWidth}{\pgfkeysvalueof{/tikz/optics/sensor line pixel width}*\objectWidth}%
\fi%
}
\savedmacro\pixelHeight{%
\pgfmathparse{(\objectHeight-2*\innerysep)/\pixelNumber}
\edef\pixelHeight{\pgfmathresult pt}%
}
\savedanchor{\northeast}{
\pgf@x=\objectWidth%
\pgf@y=\objectHeight%
\pgf@y=0.5\pgf@y%
\pgf@x=0.5\pgf@x%
}
\anchor{north east}{\northeast}
\savedanchor{\southwest}{
\pgf@x=\objectWidth%
\pgf@y=\objectHeight%
\pgf@y=-0.5\pgf@y%
\pgf@x=-0.5\pgf@x%
}
\anchor{south west}{\southwest}
\anchor{north}{
\center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xa
\pgf@y=\pgf@yb
}
\anchor{south}{
\center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\southwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xa
\pgf@y=\pgf@yb
}
\anchor{east}{
\center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xb
\pgf@y=\pgf@ya
}
\anchor{west}{
\center \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\southwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xb
\pgf@y=\pgf@ya
}
\anchor{north west}{
\northeast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\southwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xb
\pgf@y=\pgf@ya
}
\anchor{south east}{
\northeast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\southwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@x=\pgf@xa
\pgf@y=\pgf@yb
}
% ok, idée :
% HAUT (north) du pixel n (allant de 1 à N)
% \objectHeight/2 - \innerysep - (n-1) * \pixelHeight
% BAS (south) du pixel n
% \objectHeight/2 - \innerysep - n * \pixelHeight
% west = le même que la boite, donc utiliser \southwest
% east = west + \pixelWidth
% Le but de ce code est de définir des ancres
% pixel <i> <pos>
% pour <i> = 4, 2, ..., \pixelNumber
% et <pos> = north, south, east, west, north west, south west, north east south east, center
% Comme \pixelNumber est défini dynamiquement, il faut passer par cette horreur.
% Le code est inspiré de pfglibraryshapes.geometric.code.tex (shape regular polygon).
\expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@sensor line\endcsname{%
\c@pgf@counta\pixelNumber\relax%
\pgfmathloop%
\ifnum\c@pgf@counta>0\relax%
\pgfutil@ifundefined{pgf@anchor@sensor line@pixel\space\the\c@pgf@counta\space north west}{%
%
% ...(manually \xdef as \gdef is normally used by \anchor)...
%
%
% pixel surface north
\expandafter\xdef\csname pgf@anchor@sensor line@pixel\space\the\c@pgf@counta\space north\endcsname{%
\noexpand\northeast \noexpand\pgf@xa=\noexpand\pgf@x \noexpand\pgf@ya=\noexpand\pgf@y
\noexpand\southwest \noexpand\pgf@xb=\noexpand\pgf@x \noexpand\pgf@yb=\noexpand\pgf@y
\noexpand\pgf@x=\noexpand\pixelWidth
\noexpand\pgf@x=.5\noexpand\pgf@x
\noexpand\advance\noexpand\pgf@x by\noexpand\pgf@xb
\noexpand\pgf@y=\noexpand\pgf@ya
\noexpand\newdimen\noexpand\temp@y
\noexpand\pgfmathsetlength\noexpand\temp@y{(\the\c@pgf@counta-\noexpand\pixelNumber)*\noexpand\pixelHeight-\noexpand\innerysep}
\noexpand\advance\noexpand\pgf@y by\noexpand\temp@y
}%
%
%
% pixel surface north east
\expandafter\xdef\csname pgf@anchor@sensor line@pixel\space\the\c@pgf@counta\space north east\endcsname{%
\noexpand\northeast \noexpand\pgf@xa=\noexpand\pgf@x \noexpand\pgf@ya=\noexpand\pgf@y
\noexpand\southwest \noexpand\pgf@xb=\noexpand\pgf@x \noexpand\pgf@yb=\noexpand\pgf@y
\noexpand\pgf@x=\noexpand\pixelWidth
\noexpand\advance\noexpand\pgf@x by\noexpand\pgf@xb
\noexpand\pgf@y=\noexpand\pgf@ya
\noexpand\newdimen\noexpand\temp@y
\noexpand\pgfmathsetlength\noexpand\temp@y{(\the\c@pgf@counta-\noexpand\pixelNumber)*\noexpand\pixelHeight-\noexpand\innerysep}
\noexpand\advance\noexpand\pgf@y by\noexpand\temp@y
}%
%
%
% pixel surface north west
\expandafter\xdef\csname pgf@anchor@sensor line@pixel\space\the\c@pgf@counta\space north west\endcsname{%
\noexpand\northeast \noexpand\pgf@xa=\noexpand\pgf@x \noexpand\pgf@ya=\noexpand\pgf@y
\noexpand\southwest \noexpand\pgf@xb=\noexpand\pgf@x \noexpand\pgf@yb=\noexpand\pgf@y
\noexpand\pgf@x=\noexpand\pgf@xb
\noexpand\pgf@y=\noexpand\pgf@ya
\noexpand\newdimen\noexpand\temp@y
\noexpand\pgfmathsetlength\noexpand\temp@y{(\the\c@pgf@counta-\noexpand\pixelNumber)*\noexpand\pixelHeight-\noexpand\innerysep}
\noexpand\advance\noexpand\pgf@y by\noexpand\temp@y
}%
%
%
% pixel surface south
\expandafter\xdef\csname pgf@anchor@sensor line@pixel\space\the\c@pgf@counta\space south\endcsname{%
\noexpand\northeast \noexpand\pgf@xa=\noexpand\pgf@x \noexpand\pgf@ya=\noexpand\pgf@y
\noexpand\southwest \noexpand\pgf@xb=\noexpand\pgf@x \noexpand\pgf@yb=\noexpand\pgf@y
\noexpand\pgf@x=\noexpand\pixelWidth
\noexpand\pgf@x=.5\noexpand\pgf@x
\noexpand\advance\noexpand\pgf@x by\noexpand\pgf@xb
\noexpand\pgf@y=\noexpand\pgf@ya
\noexpand\newdimen\noexpand\temp@y
\noexpand\pgfmathsetlength\noexpand\temp@y{(\the\c@pgf@counta-\noexpand\pixelNumber-1)*\noexpand\pixelHeight-\noexpand\innerysep}
\noexpand\advance\noexpand\pgf@y by\noexpand\temp@y
}%
%
%
% pixel surface south east
\expandafter\xdef\csname pgf@anchor@sensor line@pixel\space\the\c@pgf@counta\space south east\endcsname{%
\noexpand\northeast \noexpand\pgf@xa=\noexpand\pgf@x \noexpand\pgf@ya=\noexpand\pgf@y
\noexpand\southwest \noexpand\pgf@xb=\noexpand\pgf@x \noexpand\pgf@yb=\noexpand\pgf@y
\noexpand\pgf@x=\noexpand\pixelWidth
\noexpand\advance\noexpand\pgf@x by\noexpand\pgf@xb
\noexpand\pgf@y=\noexpand\pgf@ya
\noexpand\newdimen\noexpand\temp@y
\noexpand\pgfmathsetlength\noexpand\temp@y{(\the\c@pgf@counta-\noexpand\pixelNumber-1)*\noexpand\pixelHeight-\noexpand\innerysep}
\noexpand\advance\noexpand\pgf@y by\noexpand\temp@y
}%
%
%
% pixel surface south west
\expandafter\xdef\csname pgf@anchor@sensor line@pixel\space\the\c@pgf@counta\space south west\endcsname{%
\noexpand\northeast \noexpand\pgf@xa=\noexpand\pgf@x \noexpand\pgf@ya=\noexpand\pgf@y
\noexpand\southwest \noexpand\pgf@xb=\noexpand\pgf@x \noexpand\pgf@yb=\noexpand\pgf@y
\noexpand\pgf@x=\noexpand\pgf@xb
\noexpand\pgf@y=\noexpand\pgf@ya
\noexpand\newdimen\noexpand\temp@y
\noexpand\pgfmathsetlength\noexpand\temp@y{(\the\c@pgf@counta-\noexpand\pixelNumber-1)*\noexpand\pixelHeight-\noexpand\innerysep}
\noexpand\advance\noexpand\pgf@y by\noexpand\temp@y
}%
%
%
% pixel surface east
\expandafter\xdef\csname pgf@anchor@sensor line@pixel\space\the\c@pgf@counta\space east\endcsname{%
\noexpand\northeast \noexpand\pgf@xa=\noexpand\pgf@x \noexpand\pgf@ya=\noexpand\pgf@y
\noexpand\southwest \noexpand\pgf@xb=\noexpand\pgf@x \noexpand\pgf@yb=\noexpand\pgf@y
\noexpand\pgf@x=\noexpand\pixelWidth
\noexpand\advance\noexpand\pgf@x by\noexpand\pgf@xb
\noexpand\pgf@y=\noexpand\pgf@ya
\noexpand\newdimen\noexpand\temp@y
\noexpand\pgfmathsetlength\noexpand\temp@y{(\the\c@pgf@counta-\noexpand\pixelNumber-0.5)*\noexpand\pixelHeight-\noexpand\innerysep}
\noexpand\advance\noexpand\pgf@y by\noexpand\temp@y
}%
%
%
% pixel surface center
\expandafter\xdef\csname pgf@anchor@sensor line@pixel\space\the\c@pgf@counta\space center\endcsname{%
\noexpand\northeast \noexpand\pgf@xa=\noexpand\pgf@x \noexpand\pgf@ya=\noexpand\pgf@y
\noexpand\southwest \noexpand\pgf@xb=\noexpand\pgf@x \noexpand\pgf@yb=\noexpand\pgf@y
\noexpand\pgf@x=\noexpand\pixelWidth
\noexpand\pgf@x=.5\noexpand\pgf@x
\noexpand\advance\noexpand\pgf@x by\noexpand\pgf@xb
\noexpand\pgf@y=\noexpand\pgf@ya
\noexpand\newdimen\noexpand\temp@y
\noexpand\pgfmathsetlength\noexpand\temp@y{(\the\c@pgf@counta-\noexpand\pixelNumber-0.5)*\noexpand\pixelHeight-\noexpand\innerysep}
\noexpand\advance\noexpand\pgf@y by\noexpand\temp@y
}%
%
%
% pixel surface west
\expandafter\xdef\csname pgf@anchor@sensor line@pixel\space\the\c@pgf@counta\space west\endcsname{%
\noexpand\northeast \noexpand\pgf@xa=\noexpand\pgf@x \noexpand\pgf@ya=\noexpand\pgf@y
\noexpand\southwest \noexpand\pgf@xb=\noexpand\pgf@x \noexpand\pgf@yb=\noexpand\pgf@y
\noexpand\pgf@x=\noexpand\pgf@xb
\noexpand\pgf@y=\noexpand\pgf@ya
\noexpand\newdimen\noexpand\temp@y
\noexpand\pgfmathsetlength\noexpand\temp@y{(\the\c@pgf@counta-\noexpand\pixelNumber-0.5)*\noexpand\pixelHeight-\noexpand\innerysep}
\noexpand\advance\noexpand\pgf@y by\noexpand\temp@y
}%
}{\c@pgf@counta0\relax}%
\advance\c@pgf@counta-1\relax%
\repeatpgfmathloop%
}%
\inheritanchorborder[from=rectangle]
\backgroundpath
{
% rectangle contour
\pgfpathrectanglecorners{\northeast}{\southwest}
% dessin des pixels
\c@pgf@counta\pixelNumber\relax%
\pgfmathloop%
\ifnum\c@pgf@counta>0\relax%
\newdimen\pixel@northeast@x
\newdimen\pixel@northeast@y
\newdimen\pixel@southwest@x
\newdimen\pixel@southwest@y
\northeast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\southwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
% calcul pixel@northeast
%% calcul x
\pixel@northeast@x=\pgf@xb
\advance\pixel@northeast@x by\pixelWidth
%% calcul y
\pixel@northeast@y=\pgf@ya
\newdimen\temp@y
\pgfmathsetlength\temp@y{(\the\c@pgf@counta-\pixelNumber)*\pixelHeight-\innerysep}
\advance\pixel@northeast@y by\noexpand\temp@y
% calcul pixel@southwest
\pixel@southwest@x=\pgf@xb
\pixel@southwest@y=\pgf@ya
\newdimen\temp@y
\pgfmathsetlength\temp@y{(\the\c@pgf@counta-\pixelNumber-1)*\pixelHeight-\innerysep}
\advance\pixel@southwest@y by\temp@y
% dessin
\pgfpathrectanglecorners{\pgfpoint{\pixel@northeast@x}{\pixel@northeast@y}}{\pgfpoint{\pixel@southwest@x}{\pixel@southwest@y}}
\advance\c@pgf@counta-1\relax%
\repeatpgfmathloop%
}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Styles defining optics elements in terms of the existing shapes.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Style [screen]
\pgfkeys{/tikz/optics/screen/.style={thin optics element, very thick}}
% Style [diffraction grating]
\pgfkeys{/tikz/optics/diffraction grating/.style={thin optics element, /tikz/optics/cheating dash={on 4pt off 2pt}}}
% Style [grid]
\pgfkeys{/tikz/optics/grid/.style={thin optics element, /tikz/optics/cheating dash={on 4pt off 2pt}, ultra thick}}
% Style [semi-transparent mirror]
\pgfkeys{/tikz/optics/semi-transparent mirror/.style={thin optics element, densely dotted, thick}}
% Style [diaphragm]
\pgfkeys{/tikz/optics/diaphragm/.style={slit,/tikz/optics/slit height=0.4}}
% Style [generic lamp]
\pgfkeys{/tikz/optics/generic lamp/.style={shape=generic optics io,optics,draw}}
% Style [generic sensor]
\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}}
% Style [halogen lamp]
\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}}
% Style [spectral lamp]
\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}}
% Style [laser]
\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}}
% Style [laser']
\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}}
% Style [beam splitter]
\pgfkeys{/tikz/optics/beam splitter/.style={shape=polarizer, optics, draw, object height=1cm, object aspect ratio=1}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Helper style to draw correctly dashed paths.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% source : http://tex.stackexchange.com/questions/133271/can-tikz-dashed-lines-emulate-pstricks-dashed-lines
% le but est d'avoir des dash symétriques par rapport au milieu et surtout avec un trait entier de chaque côté
\tikzset{
/tikz/optics/cheating dash/.code args={on #1 off #2}{
% Use csname so catcode of @ doesn't have do be changed.
\csname tikz@addoption\endcsname{%
\pgfgetpath\currentpath%
\pgfprocessround{\currentpath}{\currentpath}%
\csname pgf@decorate@parsesoftpath\endcsname{\currentpath}{\currentpath}%
\pgfmathparse{\csname pgf@decorate@totalpathlength\endcsname-#1}\let\rest=\pgfmathresult%
\pgfmathparse{#1+#2}\let\onoff=\pgfmathresult%
\pgfmathparse{max(floor(\rest/\onoff), 1)}\let\nfullonoff=\pgfmathresult%
\pgfmathparse{max((\rest-\onoff*\nfullonoff)/\nfullonoff+#2, #2)}\let\offexpand=\pgfmathresult%
\pgfsetdash{{#1}{\offexpand}}{0pt}}%
}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Helper style for multiline io elements.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\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}}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Helper styles to mark interesing points
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Style [mark point]
% Describes how interesting points should be drawn (e.g. by [draw focal points], [draw mirror focus], [draw mirror center])
\pgfkeys{/tikz/optics/mark point/.style={optics/mark a cross}}
% Style [draw focal points]
% Should be applied to a [shape=lens] node to draw its focal points according to the style [mark point].
\pgfkeys{/tikz/optics/draw focal points/.style={append after command={
\pgfextra{
\begin{pgfinterruptpath}
\node[/tikz/optics/mark point,#1] at (\tikzlastnode.west focal point) {};
\node[/tikz/optics/mark point,#1] at (\tikzlastnode.east focal point) {};
\end{pgfinterruptpath}
}
}
}}
% Style [draw mirror focus]
% Should be applied to a [shape=spherical mirror] node to draw its focal point according to the style [mark point].
\pgfkeys{/tikz/optics/draw mirror focus/.style={append after command={
\pgfextra{
\begin{pgfinterruptpath}
\node[/tikz/optics/mark point,#1] at (\tikzlastnode.focus) {};
\end{pgfinterruptpath}
}
}
}}
% Style [draw mirror center]
% Should be applied to a [shape=spherical mirror] node to draw its center according to the style [mark point].
\pgfkeys{/tikz/optics/draw mirror center/.style={append after command={
\pgfextra{
\begin{pgfinterruptpath}
\node[/tikz/optics/mark point,#1] at (\tikzlastnode.mirror center) {};
\end{pgfinterruptpath}
}
}
}}
% Style [mark a cross]
% Draws a cross at the node
\pgfkeys{/tikz/optics/mark a cross/.style={cross out,draw,inner sep=0pt,minimum width=2pt,minimum height=2pt}}
% idée : utiliser pgfextra pour les flèches, si on peut avoir les deux dernières nodes ?
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Helper styles to easily put things on paths.
% It is often needed in optics to have e.g. arrows in the middle of a path.
% It is often needed everywhere to be able to put a coordinate somewhere on
% a path.
% This is the aim of these helpers.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Style [put coordinate]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Le style [put coordinate=<coord> at <pos>] crée une node[coordinate]
% à l'abscisse curviligne <pos> sur le chemin auquel est appliqué le style.
%
% Exemple :
% \draw[put coordinate=P at 0.3] (0,0) to[bend left] (2cm,0);
% \draw[red] (P) -- (0,0);
%
\tikzset{
put coordinate/.style args={#1 at #2}{decoration={markings, mark=at position #2 with {\node[coordinate] (#1) {};}},postaction={decorate}}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Style [put arrow]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% 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
% \draw[/tikz/optics/->-={at=0.25}, /tikz/optics/->-={at=0.75}] (0,0) -- (2cm,2cm) -- (4cm,0);
% and have it work. Obviously, I want more complicated things (several arrows with different directions, colors, number of >, etc. on the same path).
% With a naive implementation, this does not work and the last setting always wins.
% A possible solution would be positional arguments, however keywords arguments are Better (tm).
% Hence the need to take care of expansion order, so the specifications apply only to the currently drawn arrow tip.
% The main idea behing this code is to use Magic (tm) so that Things Work (tm) and never touch it again.
% However, it is obvious from a trivial application of Murphy Law that this will backfire sometime.
% Indeed, a key with positional arguments are used internally (|ordered draw key|), which is called from the parsed arguments.
\tikzset{/tikz/put arrow/.cd,
pos/.initial=0.5,
at/.style={pos=#1},
pos var/.initial={},
style/.initial={},
style var/.initial={},
postaction style/.initial={}, % more expansion magic needed for ->n- and friends (\arrow[thing=stuff] does not seem to work, probably because of the =)
arrow macro/.initial={arrow},
arrow macro var/.initial={},
arrow type/.initial={>},
arrow type var/.initial={},
reversed/.style={arrow macro=arrowreversed},
arrow/.style={arrow type=#1},
arrow'/.style={arrow type=#1, reversed},
every arrow/.style={},
}
\tikzset{put arrow/.code={
% parse arguments correctly
\tikzset{/tikz/put arrow/.cd, #1}
\tikzset{/tikz/put arrow/pos var/.expand once={\pgfkeysvalueof{/tikz/put arrow/pos}}}
\tikzset{/tikz/put arrow/style var/.expanded={\pgfkeysvalueof{/tikz/put arrow/style}}}
\tikzset{/tikz/put arrow/arrow macro var/.expand once={\pgfkeysvalueof{/tikz/put arrow/arrow macro}}}
\tikzset{/tikz/put arrow/arrow type var/.expand once={\pgfkeysvalueof{/tikz/put arrow/arrow type}}}
% call |ordered draw key| which does the real job
\tikzset{/tikz/put arrow/ordered draw key/.expanded=%
{\pgfkeysvalueof{/tikz/put arrow/pos var}}%
{\pgfkeysvalueof{/tikz/put arrow/style var}}%
{\pgfkeysvalueof{/tikz/put arrow/arrow macro var}}%
{\pgfkeysvalueof{/tikz/put arrow/arrow type var}}%
{\pgfkeysvalueof{/tikz/put arrow/postaction style}}%
}
% restore initial values
\tikzset{/tikz/put arrow/pos=0.5}
\tikzset{/tikz/put arrow/style={}}
\tikzset{/tikz/put arrow/arrow macro={arrow}}
\tikzset{/tikz/put arrow/arrow type={>}}
}}
\tikzset{/tikz/put arrow/ordered draw key/.code n args={5}{
\tikzset{postaction={#5,decorate, decoration={markings, mark=at position #1 with {\csname #3\endcsname[/tikz/put arrow/every arrow,#2]{#4}};}}}
}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Styles to mark light rays
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\tikzset{/tikz/optics/multiple ray arrow/.cd,
n/.initial=1,
n var/.initial=1,
set n/.code={\pgfsetarrowoptions{multiple ray arrow}{#1}},
}
\pgfkeys{
/tikz/optics/.cd,
use ray arrow >/.code 2 args={
\pgfsetarrowoptions{ray arrow@length}{4pt}
\pgfsetarrowoptions{ray arrow@angle}{50}
\tikzset{/tikz/put arrow/postaction style/.expanded={/tikz/optics/multiple ray arrow/set n=#1}}
\tikzset{/tikz/put arrow/.expanded={arrow={multiple ray arrow}, #2}}
},
use ray arrow </.code 2 args={
\pgfsetarrowoptions{ray arrow@length}{4pt}
\pgfsetarrowoptions{ray arrow@angle}{50}
\tikzset{/tikz/put arrow/postaction style/.expanded={/tikz/optics/multiple ray arrow/set n=#1}}
\tikzset{/tikz/put arrow/.expanded={arrow'={multiple ray arrow}, #2}}
},
->n-/.code={
\tikzset{/tikz/optics/multiple ray arrow/.cd, .collect unknowns,%
#1,
unknown options/.get = \arrowkeys}
\tikzset{/tikz/optics/multiple ray arrow/n var/.expand once={\pgfkeysvalueof{/tikz/optics/multiple ray arrow/n}}}
\tikzset{/tikz/optics/use ray arrow >={\pgfkeysvalueof{/tikz/optics/multiple ray arrow/n var}}{\arrowkeys}}
},
-<n-/.code={
\tikzset{/tikz/optics/multiple ray arrow/.cd, .collect unknowns,%
#1,
unknown options/.get = \arrowkeys}
\tikzset{/tikz/optics/multiple ray arrow/n var/.expand once={\pgfkeysvalueof{/tikz/optics/multiple ray arrow/n}}}
\tikzset{/tikz/optics/use ray arrow <={\pgfkeysvalueof{/tikz/optics/multiple ray arrow/n var}}{\arrowkeys}}
},
%
->-/.style={/tikz/optics/->n-={n=1, #1}},
-<-/.style={/tikz/optics/-<n-={n=1, #1}},
->>-/.style={/tikz/optics/->n-={n=2, #1}},
-<<-/.style={/tikz/optics/-<n-={n=2, #1}},
->>>-/.style={/tikz/optics/->n-={n=3, #1}},
-<<<-/.style={/tikz/optics/-<n-={n=3, #1}},
->>>>-/.style={/tikz/optics/->n-={n=4, #1}},
-<<<<-/.style={/tikz/optics/-<n-={n=4, #1}},
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Styles [dim arrow] and [short dim arrow]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\dimarrow@short@position{0}
\newif\ifdimarrow@nearstart
\dimarrow@nearstarttrue
\tikzset{%
/tikz/dim arrow/.code={\tikzset{draw,/tikz/dim arrow/draw dim arrow}\pgfkeys{/tikz/dim arrow/.cd,#1}},
/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}},
/tikz/short dim arrow/.code={\tikzset{draw,/tikz/dim arrow/draw short dim arrow}\pgfkeys{/tikz/dim arrow/.cd,#1}},
/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}},
/tikz/dim arrow/.cd,
raise/.initial={0.5cm},
no raise/.style={raise=0},
label/.code={\pgfkeys{/tikz/dim arrow/label text=#1}},
label'/.code={\pgfkeys{/tikz/dim arrow/label text=#1,/tikz/dim arrow/label style/.append style={swap},}},
label text/.initial={},
label style/.style={},
label near start/.code={\def\dimarrow@short@position{0}}, % only short
label near middle/.code={\def\dimarrow@short@position{2}}, % only short
label near end/.code={\def\dimarrow@short@position{1}}, % only short
arrow length/.initial={5mm}, % only for short
draw short dim arrow/.style={to path={\pgfextra{%
\let\tikz@mode@save=\tikz@mode%
\let\tikz@options@save=\tikz@options%
\newdimen\labelTotalRaise
\pgfmathsetlength\labelTotalRaise{\pgfkeysvalueof{/tikz/dim arrow/raise}}
\pgfinterruptpath
\draw[>=technical,->|] \pgfextra{\let\tikz@mode=\tikz@mode@save\let\tikz@options=\tikz@options@save}
let
\p1=($(\tikztostart)!\pgfkeysvalueof{/tikz/dim arrow/raise}!90:(\tikztotarget)$),
\p2=($(\tikztotarget)!\pgfkeysvalueof{/tikz/dim arrow/raise}!-90:(\tikztostart)$)
in ($(\p1)!-\pgfkeysvalueof{/tikz/dim arrow/arrow length}!(\p2)$) -- ($(\p1)!0!(\p2)$);
\draw[>=technical,->|] \pgfextra{\let\tikz@mode=\tikz@mode@save\let\tikz@options=\tikz@options@save}
let
\p1=($(\tikztostart)!\pgfkeysvalueof{/tikz/dim arrow/raise}!90:(\tikztotarget)$),
\p2=($(\tikztotarget)!\pgfkeysvalueof{/tikz/dim arrow/raise}!-90:(\tikztostart)$)
in ($(\p2)!-\pgfkeysvalueof{/tikz/dim arrow/arrow length}!(\p1)$) -- ($(\p2)!0!(\p1)$);
\ifnum\dimarrow@short@position=0
\path let
\p1=($(\tikztostart)!\labelTotalRaise!90:(\tikztotarget)$),
\p2=($(\tikztotarget)!\labelTotalRaise!-90:(\tikztostart)$)
in let
\p3=($(\p1)!-1*\pgfkeysvalueof{/tikz/dim arrow/arrow length}!(\p2)$),
\p4=($(\p1)!-0*\pgfkeysvalueof{/tikz/dim arrow/arrow length}!(\p2)$)
in
(\p3) -- (\p4) node[pos=0.5,auto=left,/tikz/dim arrow/label style] {\pgfkeysvalueof{/tikz/dim arrow/label text}};
\fi
\ifnum\dimarrow@short@position=1
\path let
\p1=($(\tikztostart)!\labelTotalRaise!90:(\tikztotarget)$),
\p2=($(\tikztotarget)!\labelTotalRaise!-90:(\tikztostart)$)
in let
\p3=($(\p2)!-1*\pgfkeysvalueof{/tikz/dim arrow/arrow length}!(\p1)$),
\p4=($(\p2)!-0*\pgfkeysvalueof{/tikz/dim arrow/arrow length}!(\p1)$)
in
(\p4) -- (\p3) node[pos=0.5,auto=left,/tikz/dim arrow/label style] {\pgfkeysvalueof{/tikz/dim arrow/label text}};
\fi
\ifnum\dimarrow@short@position=2
\path let
\p1=($(\tikztostart)!\labelTotalRaise!90:(\tikztotarget)$),
\p2=($(\tikztotarget)!\labelTotalRaise!-90:(\tikztostart)$)
in
(\p1) -- (\p2) node[pos=0.5,/tikz/dim arrow/label style] {\pgfkeysvalueof{/tikz/dim arrow/label text}};
\fi
\endpgfinterruptpath
}(\tikztostart) (\tikztotarget) \tikztonodes
}
},
draw dim arrow/.style={to path={\pgfextra{%
\let\tikz@mode@save=\tikz@mode%
\let\tikz@options@save=\tikz@options%
\newdimen\labelTotalRaise
\pgfmathsetlength\labelTotalRaise{\pgfkeysvalueof{/tikz/dim arrow/raise}}
\pgfinterruptpath
\draw[>=technical,|<->|] \pgfextra{\let\tikz@mode=\tikz@mode@save\let\tikz@options=\tikz@options@save}
let
\p1=($(\tikztostart)!\pgfkeysvalueof{/tikz/dim arrow/raise}!90:(\tikztotarget)$),
\p2=($(\tikztotarget)!\pgfkeysvalueof{/tikz/dim arrow/raise}!-90:(\tikztostart)$)
in (\p1) -- (\p2);
\path let
\p1=($(\tikztostart)!\labelTotalRaise!90:(\tikztotarget)$),
\p2=($(\tikztotarget)!\labelTotalRaise!-90:(\tikztostart)$)
in (\p1) -- (\p2) node[pos=0.5,auto=left,/tikz/dim arrow/label style] {\pgfkeysvalueof{/tikz/dim arrow/label text}};
% rq : inner sep controle la distance chemin-node
\endpgfinterruptpath
}(\tikztostart) (\tikztotarget) \tikztonodes
}
},
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Arrows
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Arrow lens arrow
% used to draw lenses (perhaps not the best idea).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pgfsetarrowoptions{lens arrow@length}{6pt}
\pgfsetarrowoptions{lens arrow@angle}{50}
\pgfarrowsdeclare{lens arrow}{lens arrow}
{
\pgfarrowsleftextend{0pt}
\pgfarrowsrightextend{0pt}
}
{
\pgfsetroundcap
\pgfsetmiterjoin
\pgfmathsetlength{\pgfutil@tempdimb}{\pgfgetarrowoptions{lens arrow@length}*sin(\pgfgetarrowoptions{lens arrow@angle}/2)}
\def\arrow@origin{\pgfpoint{0pt}{0pt}}
\pgfutil@tempdima=\pgfgetarrowoptions{lens arrow@length}%
\pgfmathsetmacro{\tmp@lens@angle}{90+\pgfgetarrowoptions{lens arrow@angle}}
\pgfmathsetmacro{\tmp@lens@anglediv}{\pgfgetarrowoptions{lens arrow@angle}/2}
\advance\pgfutil@tempdima by -1.5\pgflinewidth%
\pgfmathsetlength{\pgfutil@tempdima}{\pgfutil@tempdima/cos(\pgfgetarrowoptions{lens arrow@angle}/2)}
\pgfpathmoveto{\pgfpointadd{\arrow@origin}{\pgfqpointpolar{\tmp@lens@angle}{\pgfutil@tempdima}}}
\pgfpathlineto{\arrow@origin}
\pgfpathlineto{\pgfpointadd{\arrow@origin}{\pgfqpointpolar{-\tmp@lens@angle}{\pgfutil@tempdima}}}
\pgfusepathqstroke
}
\pgfarrowsdeclarereversed{lens arrow reversed}{lens arrow reversed}{lens arrow}{lens arrow}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ray arrow
% It is useful to have an arrow which goes on the exact middle of a path.
% This is used on ->-, etc.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% flèche utilisée pour marquer les rayons lumineux (avec les styles ->-, etc.)
\pgfsetarrowoptions{ray arrow@length}{4pt}
\pgfsetarrowoptions{ray arrow@angle}{45}
\makeatletter
\pgfsetarrowoptions{multiple ray arrow}{0}
\pgfarrowsdeclare{multiple ray arrow}{multiple ray arrow}
{
\pgfarrowsleftextend{0pt}
\pgfarrowsrightextend{0pt}
}
{
\pgfsetroundcap
\pgfsetmiterjoin
\pgfutil@tempdima=\pgfgetarrowoptions{ray arrow@length}%
\pgfmathsetmacro{\tmp@ray@angle}{90+\pgfgetarrowoptions{ray arrow@angle}}
\pgfmathsetmacro{\tmp@ray@anglediv}{\pgfgetarrowoptions{ray arrow@angle}/2}
\advance\pgfutil@tempdima by -1.5\pgflinewidth%
\pgfmathsetlength{\pgfutil@tempdima}{\pgfutil@tempdima/cos(\pgfgetarrowoptions{ray arrow@angle}/2)}
%
\foreach \i in {1,...,\pgfgetarrowoptions{multiple ray arrow}}
{
\pgfmathsetlength{\pgfutil@tempdimb}{(2*\i-\pgfgetarrowoptions{multiple ray arrow})*\pgfgetarrowoptions{ray arrow@length}*sin(\pgfgetarrowoptions{ray arrow@angle}/2)}
%
\def\arrow@origin{\pgfpoint{\pgfutil@tempdimb}{0pt}}
%
\pgfpathmoveto{\pgfpointadd{\arrow@origin}{\pgfqpointpolar{\tmp@ray@angle}{\pgfutil@tempdima}}}
\pgfpathlineto{\arrow@origin}
\pgfpathlineto{\pgfpointadd{\arrow@origin}{\pgfqpointpolar{-\tmp@ray@angle}{\pgfutil@tempdima}}}
\pgfusepathqstroke
}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Arrow technical
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\pgfarrowsdeclare{technical}{technical}
{%
\pgfutil@tempdima=0.48pt%
\pgfutil@tempdimb=\pgflinewidth%
\ifdim\pgfinnerlinewidth>0pt%
\pgfmathsetlength\pgfutil@tempdimb{.6\pgflinewidth-.4*\pgfinnerlinewidth}%
\fi%
\advance\pgfutil@tempdima by.3\pgfutil@tempdimb%
\pgfarrowsleftextend{+-3\pgfutil@tempdima}%
\pgfarrowsrightextend{+8\pgfutil@tempdima}%
}
{%
\pgfutil@tempdima=0.48pt%
\pgfutil@tempdimb=\pgflinewidth%
\ifdim\pgfinnerlinewidth>0pt%
\pgfmathsetlength\pgfutil@tempdimb{.6\pgflinewidth-.4*\pgfinnerlinewidth}%
\fi%
\advance\pgfutil@tempdima by.3\pgfutil@tempdimb%
\pgfpathmoveto{\pgfqpoint{8\pgfutil@tempdima}{0pt}}%
\pgfpathlineto{\pgfqpoint{-3\pgfutil@tempdima}{3\pgfutil@tempdima}}%
\pgfpathlineto{\pgfpointorigin}%
\pgfpathlineto{\pgfqpoint{-3\pgfutil@tempdima}{-3\pgfutil@tempdima}}%
\pgfusepathqfill%
}
\pgfarrowsdeclare{technical reversed}{technical reversed}
{%
\pgfutil@tempdima=0.48pt%
\pgfutil@tempdimb=\pgflinewidth%
\ifdim\pgfinnerlinewidth>0pt%
\pgfmathsetlength\pgfutil@tempdimb{.6\pgflinewidth-.4*\pgfinnerlinewidth}%
\fi%
\advance\pgfutil@tempdima by.3\pgfutil@tempdimb%
\pgfarrowsleftextend{-8\pgfutil@tempdima}
\pgfarrowsrightextend{-8\pgfutil@tempdima}
}
{%
\pgfutil@tempdima=0.48pt%
\pgfutil@tempdimb=\pgflinewidth%
\ifdim\pgfinnerlinewidth>0pt%
\pgfmathsetlength\pgfutil@tempdimb{.6\pgflinewidth-.4*\pgfinnerlinewidth}%
\fi%
\advance\pgfutil@tempdima by.3\pgfutil@tempdimb%
\pgfpathmoveto{\pgfqpoint{-8\pgfutil@tempdima}{0pt}}%
\pgfpathlineto{\pgfqpoint{3\pgfutil@tempdima}{3\pgfutil@tempdima}}%
\pgfpathlineto{\pgfpointorigin}%
\pgfpathlineto{\pgfqpoint{3\pgfutil@tempdima}{-3\pgfutil@tempdima}}%
\pgfusepathqfill%
}
% Changelog:
% 2013-10-21 : ajout du style |distance arrow| et de la décoration |line| correspondante.
% 2013-11-19 : suppression de |distance arrow| et ajout à la place de |dim arrow| et assimilés
% 2013-11-22 : choix entre distances relatives et absolues (http://www.texample.net/tikz/examples/supersonic-nozzle/)
% 2013-11-24 : styles de flèches |->-|, |-<-|, |->>-|, |-<<-| (et flèches pgf |ray arrow|, etc. correspondantes)
% 2013-11-24 : flèches pgf |lens arrow| et |lens arrow reversed|
% 2013-11-24 : |generic optics element| -> |thin optics element| et |thick optics element| ; conséquences. |beam splitter|
% 2014-01-01 : ajout de |double amici prism|, |optics| -> |use optics| et |one arrow| -> |put arrow| ; |mark a *| supprimés
% 2014-03-19 : anchorborder pour |generic optics io| (les labels devraient donc être placés correctement)
% |io body aspect ratio| accepte désormais aussi des longueurs absolues, ajout d'un alias |io body width| pour |io body aspect ratio|
% 2014-06-26 : modification du code des flèches |->-|, |->>-|, etc. et ajout de |->>>-|, |->>>>-|,|->n-=<nombre>| (idem dans l'autre sens)
% 2014-07-08 : ajout de |arrow style| à |put arrow|
% 2014-09-20 : ajout de |spherical mirror| et quelques modifications à |mirror| (ajustement de la décoration et de ses réglages par défaut)
% 2014-09-22 : ajustements de |spherical mirror| (concave et convexe), et ajout des styles correspondants |convex mirror| et |concave mirror|
% 2014-09-24 : ajustements de |spherical mirror| (ltr/rtl) ; correction des ancres de generic optics io (aperture north, aperture center, aperture south étaient incorrectes)
% 2014-09-25 : corrections à |spherical mirror| (ltr/rtl vs concave/convex) ;
% 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) ;
% macro pour les messages d'erreur
% 2014-10-03 : vérifications de cohérence des grandeurs pour |slit| et |double slit| ; messages d'erreur au besoin
% 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.
% 2014-12-11 : nettoyage
% 2015-03-10 : ajout d'un alias |object width| pour |object aspect ratio|, qui accepte désormais aussi des longueurs absolues
% 2015-06-13 : mise en cohérence des noms des points focaux pour le miroir et la lentille (désormais, "focus" et "focal point")
% 2016-11-21 : appel aux biblothèques tikz |decorations| et |decorations.pathreplacing| qui sont nécessaires
\makeatother
|