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
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
|
\input texinfo @c -*-texinfo-*-
@c %**start of header
@setfilename sketch.info
@include version.texi
@settitle Sketch
@c an index for sketch commands
@defcodeindex sx
@defcodeindex op
@syncodeindex op sx
@c %**end of header
@copying
Copyright @copyright{} 2005, 2006, 2007, 2008 Eugene K. Ressler.
This manual is for @code{sketch}, version @value{VERSION},
@value{UPDATED}, a program that converts descriptions of simple
three-dimensional scenes into static drawings. This version generates
@code{PSTricks} or @code{PGF/TikZ} code suitable for use with the
@TeX{} document processing system.
@code{Sketch} is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
Sketch is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with @code{sketch}; see the file COPYING.txt. If not, see
@verb{|http://www.gnu.org/copyleft|}.
@end copying
@dircategory TeX
@direntry
* Sketch: (sketch). Simple 3D sketching for TeX
@end direntry
@titlepage
@title Sketch
@subtitle Simple 3D sketching
@subtitle Version @value{VERSION}, @value{UPDATED}
@author Gene Ressler
@page
@vskip 0pt plus 1fill
@insertcopying
@end titlepage
@c TOC
@contents
@ifnottex
@node Top, About sketch, (dir), (dir)
@top Sketch
@insertcopying
@end ifnottex
@menu
* About sketch:: Why sketch exists and what it does.
* Introduction by example:: Most features shown as working code.
* Input language:: Syntax and semantics of @code{sketch} commands.
* Building a drawing:: How to use @code{sketch} productively.
* Command line:: Options and their usage.
* Installing sketch:: Building and installing from sources.
* Index of syntax::
* Index::
@detailmenu
--- The Detailed Node Listing ---
About sketch
* Reporting bugs:: Let use know what's wrong!
* Contributions:: How you can help@dots{}.
Introduction by example
* Hello world:: Simplest possible @code{sketch} program.
* Drawing options:: Controlling object appearance.
* Drawing a solid:: Drawing an object with 3d appearance.
* Special objects:: Laying @TeX{} over, in, or under drawings.
* Object transforms:: Rotate, translate, scale, and others.
* Repeated objects:: Making transformed copies.
* Swept objects:: Sweeping objects in space to make new shapes.
Swept objects
* Point sweeps:: Swept points make lines and polygons.
* Polyline sweeps:: Swept lines make surfaces.
* Nested sweeps:: Swept sweeps are useful!
* Polygon sweeps:: Swept polygons make solids...
* Polyline sweeps with closure:: and so do closed polyline sweeps.
* Affine arithmetic:: Sketch useful math expression.
* More to learn:: Check out the Mobius strip!
Input language
* Language basics:: Case, space, comments, include files.
* Drawables:: Things that can be drawn.
* Definitions:: Giving things names.
* Global environment:: Affect the entire drawing.
Basics
* Identifiers:: Names for things.
* Key and reserved words:: Names you shouldn't use.
* Literals:: Constants and constructors.
* Arithmetic:: Rules for expressions.
* Options:: Modifying object appearance.
Literals
* Scalar literals:: Just the numbers.
* Point and vector literals:: 3d quantities.
* Transform literals:: Matrix form.
Arithmetic expressions
* Two-operand (binary) forms:: A op B
* Unary forms:: op A (and others)
Options
* PSTricks options:: Options inherited from @code{PSTricks}.
* TikZ/PGF options:: Options inherited from @code{TikZ/PGF}.
* Dots in TikZ/PGF:: Sketch uses @code{TikZ/PGF} circles for dots.
* TikZ/PGF user-defined styles:: Support for @code{TikZ/PGF} named, user-defined styles.
* Transparency:: See-through polygons.
* Internal options:: Options used by @code{sketch}.
Point lists
* Drawables:: Things that are drawn.
* Definitions:: Things with names.
Drawables
* Dots:: Draw dots.
* Lines:: Draw polylines.
* Curves:: Draw curves.
* Polygons:: Draw polygons.
* Specials:: Embed raw @LaTeX{} and @code{PSTricks}.
* Sweeps:: Draw sweeps of dots and polylines.
* Blocks:: Group other drawables.
* Repeats:: Draw transformed copies of objects.
* Puts:: Draw one object transformed.
Sweeps
* Swept points:: Swept points make lines or polygons.
* Swept lines:: Swept lines make open or closed surfaces.
* Swept polygons:: Swept polygons make closed surfaces.
* Swept blocks:: Swept block @equiv{} block of sweeps.
* Sweep face splitting:: Fixing warped faces with triangles.
Definitions
* Forms of definitions:: Different defs for different purposes.
* Forms of references:: How references denote types.
Global environment
* Global options:: Attributes of the entire drawing.
* Camera:: A final camera transformation of the scene.
* Picture box:: Setting the bounding box and 2d clipping.
* Frame:: Adding a box around the drawing.
* Language:: Setting the output language.
Building a drawing
* Overview:: Building a substantial drawing.
* A technical drawing:: An example with fine placement.
* A hierarchical model:: An example with sweeps and puts.
* Caveats:: Where trouble can occur.
Caveats
* Limits on error detection:: What sketch doesn't do.
* Clipping:: No clipping at present.
* Hidden surface removal:: Imperfections to fix.
Hidden surface removal and polygon splitting
* Statistics:: Performance numbers on depth sort.
* Bugs and anomalies:: Imperfections in this implementation.
@end detailmenu
@end menu
@node About sketch, Introduction by example, Top, Top
@comment node-name, next, previous, up
@chapter About sketch
@menu
* Reporting bugs:: Let use know what's wrong!
* Contributions:: How you can help@dots{}.
@end menu
@code{Sketch} is a small, simple system for producing line drawings of
two- or three-dimensional objects and scenes. It began as a way to
make illustrations for a textbook after we could find no suitable
tool for this purpose. Existing scene processors emphasized GUIs
and/or photo-realism, both un-useful to us. We wanted to produce
finely wrought, mathematically-based illustrations with no extraneous
detail.
@code{Sketch} accepts a tiny scene description language and generates
@code{PSTricks} or @code{TikZ/PGF} code for @LaTeX{}. The
@code{sketch} language is similar to @code{PSTricks}, making it easy
to learn for current @code{PSTricks} users. See
@cindex PSTricks
@verb{|www.pstricks.de|} for information on @code{PSTricks}.
@code{TikZ/PGF} are also very similar except for details of syntax.
See
@cindex TikZ/PGF
@verb{|http://sourceforge.net/projects/pgf|}. One can easily lay raw
@code{PSTricks} or @code{TikZ/PGF} output over, in, or under
@code{sketch} drawings, providing the full power of @LaTeX{} text and
mathematics formatting in a three-dimensional setting.
@node Reporting bugs, Contributions, About sketch, About sketch
@comment node-name, next, previous, up
@section Reporting bugs and recommending improvements.
Send bug reports and suggestions to @verb{|sketch@frontiernet.net|}.
We will try to respond, but can't promise. In any event, don't be
offended if a reply is not forthcoming. We're just busy and will get
to your suggestion eventually.
For bugs, attach a @code{sketch} input file that causes the bad
behavior. Embed comments that explain what to look for in
the behavior of @code{sketch} or its output.
A recommendation for improvement from one unknown person counts as one
vote. We use overall vote tallies to decide what to do next as
resources permit. We reserve the right to a assign any number of votes
to suggestions from people who have been helpful and supportive in the
past.
@node Contributions, , Reporting bugs, About sketch
@comment node-name, next, previous, up
@section Contributions
If you intend to implement an enhancement of your own, that's
terrific! Consider collaborating with us first to see if we're
already working on your idea or if we can use your work in the
official release.
@center @image{ex000}
@anchor{Solid coil example}
@node Introduction by example, Input language, About sketch, Top
@comment node-name, next, previous, up
@chapter Introduction by example
The @code{sketch} input language will seem familiar to users of the
@code{PSTricks} package for @LaTeX{}. The following program draws a
triangular polygon pierced by a line.
@verbatim
polygon(0,0,1)(1,0,0)(0,1,0)
line(-1,-1,-1)(2,2,2)
@end verbatim
@noindent
The coordinate system
@cindex coordinate system, right-handed
@cindex right-hand coordinate system
is a standard right-handed Cartesian one.
@center @image{ex010}
@menu
* Hello world:: Simplest possible @code{sketch} program.
* Drawing options:: Controlling object appearance.
* Drawing a solid:: Drawing an object with 3d appearance.
* Special objects:: Laying @TeX{} over, in, or under drawings.
* Object transforms:: Rotate, translate, scale, and others.
* Repeated objects:: Making transformed copies.
* Swept objects:: Sweeping objects in space to make new shapes.
@end menu
@node Hello world, Drawing options, Introduction by example, Introduction by example
@comment node-name, next, previous, up
@section Hello world
The @code{sketch} program above is nearly the simplest one possible,
the equivalent of a ``hello world''
@cindex hello world
@cindex program, hello world
program you might find at the start of a programming language text.
If it is saved in the file @file{simple.sk}, then the command
@cindex command line, @code{sketch}
@cindex running @code{sketch}
@verbatim
sketch simple.sk -o simple.tex
@end verbatim
@noindent
creates a file @file{simple.tex} containing @code{PSTricks} commands to
draw these objects on paper. The contents of @file{simple.tex}
look like this.
@verbatim
\begin{pspicture}(-1,-1)(2,2)
\pstVerb{1 setlinejoin}
\psline(-1,-1)(.333,.333)
\pspolygon[fillstyle=solid,fillcolor=white](0,0)(1,0)(0,1)
\psline(.333,.333)(2,2)
\end{pspicture}
@end verbatim
@noindent
The hidden surface algorithm
@cindex hidden surface algorithm
of @code{sketch} has split
@cindex splitting, line and surface
the line into
two pieces and ordered the three resulting objects so that the correct
portion of the line is hidden.
If you've noticed that the projection we are using seems equivalent to
erasing the @math{z}-coordinate of the three-dimensional input points,
pat yourself on the back. You are correct. This is called a
@dfn{parallel projection}.
@cindex parallel projection
@cindex projection, parallel
The @math{z}-coordinate axis is pointing straight out of the paper at
us, while the @math{x}- and @math{y}-axes point to the right and up as
usual.
The resulting picture file can be included in a @LaTeX{} document with
@verb{|\input{simple}|}. Alternately, adding the command line option
@option{-T}@footnote{Or for European users of A4 size paper,
@option{-Te}.}
@cindex command line option
@cindex option, command line
causes the @code{pspicture} to be wrapped in a short
but complete document, ready to run though @LaTeX{}.
@cindex document template
@cindex template, document
In a finished, typeset document, the picture looks like this. (The
axes have been added in light gray.)
@center @image{ex020}
@noindent
It is important to know that only the ``outside''
@cindex outside of a polygon
@cindex polygon, outside of
of a polygon is
normally drawn. The @dfn{outside} is where the vertices given in the
@code{polygon}
@sxindex polygon
command appear in @emph{counter-clockwise}
@cindex counter-clockwise polygon vertex order
@cindex polygon vertex order
@cindex order, polygon vertex
order. Thus, if the command above had been
@verbatim
polygon(0,1,0)(1,0,0)(0,0,1)
@end verbatim
@noindent
the polygon would not appear in the picture at all. It would have
been @dfn{culled}
@cindex culling
from the scene. This culling behavior may seem
strange, but stay tuned.
@node Drawing options, Drawing a solid, Hello world, Introduction by example
@comment node-name, next, previous, up
@section Options
Many @code{PSTricks} and @code{TikZ/PGF} options
@cindex option
work just fine in @code{sketch}. If generating @code{PSTricks}, the code
@sxindex line
@verbatim
polygon[fillcolor=lightgray,linewidth=3pt](0,0,1)(1,0,0)(0,1,0)
line[linestyle=dotted](-1,-1,-1)(2,2,2)
@end verbatim
@noindent
produces
@center @image{ex030}
To produce @code{TikZ/PGF}, the corresponding code is
@verbatim
polygon[fill=lightgray,line width=3pt](0,0,1)(1,0,0)(0,1,0)
line[style=dotted](-1,-1,-1)(2,2,2)
global { language tikz }
@end verbatim
@noindent
The final @code{global}
@cindex options, global
@cindex global options
instructs @code{sketch} to produce @code{TikZ/PGF} code as output
rather than the default, @code{PSTricks}. Note that @code{polygon}
fill color and @code{line} style options both conform to @code{TikZ}
syntax rules. The remaining examples of this manual are in PSTricks
style.
@node Drawing a solid, Special objects, Drawing options, Introduction by example
@comment node-name, next, previous, up
@section Drawing a solid
Let's try something more exciting. @code{Sketch} has no notion of a
solid,
@cindex solid
but polygonal @dfn{faces}
@cindex faces
can be used to represent the
boundary of a solid. To the previous example, let's add three more
triangular polygons to make the faces of an irregular tetrahedron.
@cindex tetrahedron
@sxindex def
@sxindex polygon
@verbatim
% vertices of the tetrahedron
def p1 (0,0,1) def p2 (1,0,0)
def p3 (0,1,0) def p4 (-.3,-.5,-.8)
% faces of the tetrahedron.
polygon(p1)(p2)(p3) % original front polygon
polygon(p1)(p4)(p2) % bottom
polygon(p1)(p3)(p4) % left
polygon(p3)(p2)(p4) % rear
% line to pierce the tetrahedron
line[linecolor=red](-1,-1,-1)(2,2,2)
@end verbatim
@noindent
This example uses @dfn{definitions},
@cindex definition
which begin with
@code{def}.
@sxindex def
These @dfn{define} or give names to points,
@cindex definition, point
@cindex point definition
which are then available
as @dfn{references}
@cindex reference, point
by enclosing the names in parentheses,
e.g.@ @verb{|(foo)|}.
@sxindex (foo)@r{, point reference}
The parentheses denote that the names refer to points; they are
required. There can be no
@cindex white space
white space between them and the name.
As you can see, comments
@cindex comments
start with @verb{|%|} as in @TeX{} and extend
to the end of the line (though @verb{|#|} will work as well). White
space,
@cindex white space
including spaces, tabs and blank lines, has no effect in the @code{sketch}
language.
@center @image{ex040}
@noindent
If we look inside the @TeX{} file produced by @code{sketch}, there
will be only three polygons. The fourth has been
@cindex culling
culled because it is
a ``back face''
@cindex back face
of the tetrahedron, invisible to our view. It is
unnecessary, and so it is removed.
In some drawings, polygons act as zero-thickness solid surfaces with
both sides visible rather than as the faces of solid objects, where
back faces can be culled. For zero-thickness solids, culling
@cindex culling
is a
problem. One solution is to use a pair of @code{sketch} polygons for
each zero-thickness face, identical except with opposite vertex
orders. This is unwieldy and expensive. A better way is to
set the @code{sketch} internal option @code{cull} to @code{false} in
the usual @code{PSTricks} manner.
@opindex cull
@verbatim
polygon[cull=false](p1)(p2)(p3)
@end verbatim
@noindent
The following shows the same helix
@cindex helix
shape drawn first with
@verb{|cull=true|} (the default) and then @verb{|cull=false|}.
@center @image{ex045} @anchor{Helix with cull set false then true}
@noindent
We'll soon see how to produce these helixes with a few lines
of @code{sketch} language code.
It may be tempting to turn culling off gratuitously so that vertex order
can be ignored. This is not a good idea because output file size and
@TeX{} and Postscript processing time both depend on the number of
output polygons. Culling usually improves performance by a factor of
two. On the other hand, globally setting @code{cull=false} is
reasonable while debugging. See @ref{Global options} and
@ref{Limits on error detection}.
@node Special objects, Object transforms, Drawing a solid, Introduction by example
@comment node-name, next, previous, up
@section Special objects
We can add labels
@cindex labels
to a drawing by using @verb{|special|}
@sxindex special
@cindex special object
objects, which provide a way to embed raw @LaTeX{} and @code{PSTricks}
code. Adding this to the tetrahedron does the trick.
@verbatim
special |\footnotesize
\uput{2pt}[ur]#1{$P1$}
\uput[r]#2{$P2$}
\uput[u]#3{$P3$}
\uput[d]#4{$P4$}|
(p1)(p2)(p3)(p4)
@end verbatim
@noindent
Here is the result.
@center @image{ex042}
There are several details to note here. First, the quoting convention
@cindex quoting, special
for the raw code is similar to the @LaTeX{} @verb{|\verb|} command. The
first non-white space character following @verb{|special|} is
understood to be the quote character,
in this case @samp{|}. The raw
text continues until this character recurs.
Second, the argument references
@cindex argument, special
@verb{|#1|}, @verb{|#2|}, @verb{|#3|},
and @verb{|#4|} refer to points in the list that follow. This is
similar to @TeX{} macro syntax. The transformed and two-dimensional
projections of these three-dimensional points are substituted
@cindex substitution, special
@cindex special argument substitution
in the final output. An argument reference of the form @verb{|#1-2|}
is replaced with the angle in degrees of the two-dimensional vector
that connects the projections of the two respective argument points,
here @verb{|#1|} and @verb{|#2|}. The substituted angle is enclosed
in curly braces @code{@{ @}}
By default, @code{special} objects are printed last, overlaying all
other objects in the scene. If you specify the internal option
@cindex internal option
@cindex option, internal
@code{lay=in}, the hidden surface algorithm
@opindex lay
@cindex hidden surface algorithm
considers the entire special object to be the first point
(@verb{|#1|}) in the argument list. If that point is behind (of
smaller @math{z}-component than) any drawable, then the entire special
object is drawn before that drawable, so the drawable obscures parts of
the special object that overlaps it. In our example, @verb{|p1|} is
the front-most point in the scene (has the largest
@math{z}-component), so adding @code{lay=in} has no effect.
With option @code{lay=under}, a special is drawn @emph{before}, hence
appears @emph{under} any of the objects handled by the hidden surface
algorithm. This is how the light gray axes were added to the ``hello
world'' example @ref{Hello world}.
@verb{|Special|} objects are powerful, with many possible uses.
@node Object transforms, Repeated objects, Special objects, Introduction by example
@comment node-name, next, previous, up
@section Transforms
@cindex transform
Now let's add a second copy of the pierced tetrahedron. We'll rotate
the copy 90 degrees about the @math{x}-axis with the origin as
@dfn{center of rotation}
@cindex center of rotation
@cindex rotation, center of
so we can see the back,
then translate it to the right---in the positive
@math{x}-direction---so it doesn't collide with the original. To help
us see what's going on, make the back side gray.
@sxindex def
@sxindex put
@sxindex line
@sxindex polygon
@opindex linecolor
@opindex fillcolor
@sxindex rotate
@sxindex translate
@sxindex then
@verbatim
def pierced_tetrahedron {
def p1 (0,0,1) def p2 (1,0,0)
def p3 (0,1,0) def p4 (-.3,-.5,-.8)
polygon(p1)(p2)(p3) % original
polygon(p1)(p4)(p2) % bottom
polygon(p1)(p3)(p4) % left
polygon[fillcolor=lightgray](p3)(p2)(p4) % rear
line[linecolor=red](-1,-1,-1)(2,2,2)
}
{pierced_tetrahedron} % tetrahedron in original position
put { rotate(90, (0,0,0), [1,0,0]) % copy in new position
then translate([2.5,0,0]) } {pierced_tetrahedron}
@end verbatim
@noindent
Here the entire code of the previous example has been wrapped in a
definition by forming a @dfn{block}
@cindex block
@sxindex @{ @}@r{, block drawable}
with braces (a single item would not need them). The point
definitions nested inside the braces are @dfn{lexically scoped}.
@cindex lexical scope
@cindex scope, identifier
Their meaning extends only to the end of the block. The outer
@verb{|def|} is called a @dfn{drawable}
@cindex drawable
definition
@cindex definition, drawable
@cindex drawable definition
because it describes something that can be drawn.
A drawable definition by itself causes nothing to happen until its
name is referenced. Drawable references must be enclosed in curly
braces, e.g.@ @verb{|{foo}|}, with no intervening
@cindex white space
white space. In the code
above, the first reference
@cindex reference, drawable
@verb{|{pierced_tetrahedron}|}
@sxindex @{foo@}@r{, drawable reference}
is a plain
one. Its effect is merely to duplicate the earlier drawing. Almost
any series of @code{sketch} commands @verb{|stuff|} may be replaced
with @verb{|def foo { stuff } {foo}|} without changing its meaning.
The @verb{|put|} command supplies a second reference, this time with
a @dfn{transform} applied first. The @verb{|rotate|}
@sxindex rotate
@cindex rotation
transform turns the tetrahedron 90 degrees about the origin. The
axis of rotation
@cindex axis, rotation
is the vector @math{[1,0,0]}. By the @dfn{right
hand rule},
@cindex right hand rule
this causes the top of the tetrahedron to rotate toward
the viewer and the bottom away. The rule receives its name from the
following definition:
@quotation
@anchor{Right hand rule}
@strong{Right hand rule.} If the right hand is wrapped around any
axis with the thumb pointing in the axis direction, then the fingers
curl in the direction of positive rotation about that axis.
@end quotation
The @verb{|translate|}
@sxindex translate
@cindex translation transform
@cindex transform, translation
transform moves the pyramid laterally to
the right by adding the vector
@cindex vector
@math{[2.5,0,0]} to each vertex
coordinate. The result is shown here.
@center @image{ex050}
@node Repeated objects, Swept objects, Object transforms, Introduction by example
@comment node-name, next, previous, up
@section Repeated objects
To draw seven instances of the tetrahedron, each differing from the
last by the same transform, replace the last two commands of the
previous example with
@sxindex repeat
@sxindex rotate
@sxindex translate
@verbatim
repeat { 7, rotate(15, (0,0,0), [1,0,0]) % copy in new position
then translate([2,0,0]) } {pierced_tetrahedron}
@end verbatim
@noindent
And the result@enddots{}
@center @image{ex060}
@node Swept objects, , Repeated objects, Introduction by example
@comment node-name, next, previous, up
@section Swept objects
@cindex swept object
@cindex sweep
Many familiar shapes can be generated by sweeping simpler ones through
space and considering the resulting path, surface, or volume.
@code{Sketch} implements this idea in the @verb{|sweep|} command.
@sxindex sweep
@sxindex rotate
@verbatim
def n_segs 8
sweep { n_segs, rotate(180 / n_segs, (0,0,0), [0,0,1]) } (1,0,0)
@end verbatim
@noindent
This code sweeps the point @math{(1,0,0)}
@cindex point sweep
@cindex swept point
eight times by rotating it
@math{180/8 = 22.5} degrees each time and connecting the resulting
points with line segments. The @verb{|def|} used here is a
@dfn{scalar} definition.
@cindex definition, scalar
@cindex scalar definition
References to
@cindex reference, scalar
scalars have no enclosing brackets at all.
@menu
* Point sweeps:: Swept points make lines and polygons.
* Polyline sweeps:: Swept lines make surfaces.
* Nested sweeps:: Swept sweeps are useful!
* Polygon sweeps:: Swept polygons make solids...
* Polyline sweeps with closure:: and so do closed polyline sweeps.
* Affine arithmetic:: Sketch useful math expression.
* More to learn:: Check out the Mobius strip!
@end menu
@node Point sweeps, Polyline sweeps, Swept objects, Swept objects
@comment node-name, next, previous, up
@subsection Point sweeps
Sweeping a point makes a one-dimensional path, which is a polyline.
Since we have swept with a rotation, the result is a circular arc.
Here is what it looks like.
@center @image{ex070}
This is the first example we have seen of @code{sketch} arithmetic.
The expression @verb{|180 / n_segs|} causes the eight rotations to add
to 180. If you're paying attention, you'll have already noted that
there are @emph{nine} points, producing eight line segments.
You can cause the swept point to generate a single polygon rather than
a polyline by using the @dfn{closure tag} @verb{|<>|}
@sxindex <>@r{, closure tag}
@cindex closure tag, @code{<>}
after the number
of swept objects. Code and result follow
@sxindex def
@sxindex rotate
@sxindex sweep
@verbatim
def n_segs 8
sweep { n_segs<>, rotate(180 / n_segs, (0,0,0), [0,0,1]) } (1,0,0)
@end verbatim
@center @image{ex080}
@node Polyline sweeps, Nested sweeps, Point sweeps, Swept objects
@comment node-name, next, previous, up
@subsection Polyline sweeps
Sweeping a polyline produces a
@cindex line sweep
@cindex swept line
@cindex surface
surface composed of many faces.
@cindex faces
The unbroken helix in the
example @ref{Helix with cull set false then true} is produced by this
code (plus a surrounding @verb{|put|} rotation to make an interesting
view; this has been omitted).
@sxindex def
@sxindex sweep
@sxindex rotate
@sxindex translate
@opindex cull
@opindex linewidth
@verbatim
def K [0,0,1]
sweep[cull=false] {
60,
rotate(10, (0,0,0), [K]) then translate(1/6 * [K])
} line[linewidth=2pt](-1,0)(1,0)
@end verbatim
@noindent
Again, 60 segments of the helix
@cindex helix
are produced by connecting 61
instances of the swept line. Options
@cindex options, sweep
applied to the sweep, here
@verb{|cull=false|}, are treated as options for the generated polygon
or polyline. Options of the swept line itself, here
@verb{|linewidth=2pt|}, are ignored, though with a warning. This
@verb{|def|} is a @dfn{vector} definition,
@cindex definition, vector
@cindex vector definition
which must be referenced
with square brackets, e.g.@ @verb{|[foo]|}.
@cindex reference, vector
@sxindex [foo]@r{, vector reference}
@node Nested sweeps, Polygon sweeps, Polyline sweeps, Swept objects
@comment node-name, next, previous, up
@subsection Nested sweeps
When the center point of rotation is omitted,
@cindex center of rotation
@cindex rotation, center of
the origin is assumed.
When a point has only two coordinates, they are taken as
@math{x}@tie{}and @math{y},@tie{}with @math{z=0} assumed. A toroid
@cindex toroid
is therefore obtained with this code.
@sxindex def
@sxindex sweep
@sxindex rotate
@verbatim
def n_toroid_segs 20 def n_circle_segs 16
def r_minor 1 def r_major 1.5
sweep { n_toroid_segs, rotate(360 / n_toroid_segs, [0,1,0]) }
sweep { n_circle_segs, rotate(360 / n_circle_segs, (r_major,0,0)) }
(r_major + r_minor, 0)
@end verbatim
@indent
For intuition, the idea of the code is to sketch a circle to the right
of the origin in the @math{xy}-plane, then rotate that circle ``out of
the plane'' about the @math{y}-axis to make the final figure. This
produces the following. (A view rotation and some axes have been
added.)
@center @image{ex090}
This example also shows that the swept object may itself be another
@code{sweep}.
@sxindex sweep
@cindex nesting, swept object
In fact, it may be @emph{any} @code{sketch} expression that results in
a list of one or more points or, alternately, a list of one or more
polylines and polygons. The latter kind of list can be created with a
@verb{|{ }|}-enclosed block, perhaps following a
@sxindex put
@verb{|put|} or
@sxindex repeat
@verb{|repeat|}.
@sxindex @{ @}@r{, block drawable}
@node Polygon sweeps, Polyline sweeps with closure, Nested sweeps, Swept objects
@comment node-name, next, previous, up
@subsection Polygon sweeps
Sweeping a polygon
@cindex polygon sweep
@cindex swept polygon
creates a closed surface with polygons at the ends,
which are just copies of the original, appropriately
positioned. @xref{Solid coil example}.
@cindex options, swept object
Options on the swept polygon,
if they exist, are applied to the ends. Otherwise the sweep options
@cindex options, sweep
are used throughout.
@node Polyline sweeps with closure, Affine arithmetic, Polygon sweeps, Swept objects
@comment node-name, next, previous, up
@subsection Polyline sweeps with closure
A polyline sweep with a closure tag
@sxindex <>@r{, closure tag}
@cindex closure tag, @code{<>}
creates another kind of closed
surface. First, the polyline segments are connected by faces, just as
without the closure tag. Then, each set of end points is joined to
make a polygon, one for each end. A code for several views of a
cylindrical prism follows.
@sxindex def
@sxindex repeat
@sxindex rotate
@sxindex then
@sxindex translate
@sxindex sweep
@sxindex line
@opindex fillcolor
@verbatim
def n_cyl_segs 20 def n_views 5 def I [1,0,0]
def endopts [fillcolor=lightgray]
repeat { n_views, rotate(180/n_views, [I]) then translate([I] * 2.1) }
sweep[endopts]{ n_cyl_segs<>, rotate(360/n_cyl_segs, [0,1,0]) }
line[fillcolor=white](1,-1)(1,1)
@end verbatim
@noindent
It produces this drawing.
@center @image{ex110}
@noindent
The options of the swept line, if any, are applied to the faces
produced by sweeping the line, but not the end polygons. Otherwise,
the sweep options are applied throughout.
@cindex options, swept object
The @verb{|def|} in this example is an @dfn{option} definition.
@cindex definition, options
@cindex options definition
References to options must be enclosed in square brackets, e.g.@tie{}
@verb{|[foo]|}.
@cindex reference, options
@sxindex [foo]@r{, options reference}
Happily, the syntax of @code{sketch} is such that
options references can never be confused with vector references. While
not apparent in this example, options references are useful when
defining many objects with a similar appearance.
@node Affine arithmetic, More to learn, Polyline sweeps with closure, Swept objects
@comment node-name, next, previous, up
@subsection Affine arithmetic
The arithmetic @verb{|[I] * 2.1|} above hints at a larger truth.
@code{Sketch} operators work on scalars, vectors, points, and
transforms according to the general rules of @dfn{affine algebra}.
@cindex affine arithmetic
This can be helpful for setting up diagrams with computed geometry.
For example, if you have triangle vertices @verb{|(p1)|} through
@verb{|(p3)|} and need to draw a unit normal vector pointing out of
the center of the triangle, this code does the trick.
@sxindex def
@sxindex polygon
@sxindex line
@opindex arrows
@verbatim
def p1 (1,0,0) def p2 (0,0.5,0) def p3 (-0.5,-1,2)
def O (0,0,0)
def N unit( ((p3) - (p2)) * ((p1) - (p2)) )
def n1 ((p1)-(O) + (p2)-(O) + (p3)-(O)) / 3 + (O)
def n2 (n1)+[N]
polygon(p1)(p2)(p3)
line[arrows=*->](n1)(n2)
@end verbatim
@noindent
The first line computes the cross product of two edge vectors of the
triangle and scales it to unit length. The second computes the
average of the vertices. Note that subtraction and addition of the
origin effectively convert vectors to points and @emph{vice versa}.
The line command draws the normal at the correct spot.
@center @image{ex100}
Two caveats regarding this example remain. First, the only way to use
@code{PSTricks}-style arrows is with @verb{|arrows=|}.
@opindex arrows
The alternative syntax for @code{PSTricks} arrows is not allowed in
@verb{|sketch|}. Second, you might like to eliminate the third
@verb{|def|} and write instead the following.
@verbatim
line[arrows=*->](n1) (n1)+[N]
@end verbatim
@noindent
This is not allowed. The point lists in drawables may consist only of
explicit points or point references. You may, however, use arithmetic
to calculate point components. The following works, though it's
a little cumbersome.
@verbatim
line[arrows=*->](n1)((n1)'x+(N)'x, (n1)'y+(N)'y, (n1)'z+(N)'z)
@end verbatim
@noindent
Obviously, the @dfn{tick operator}
@cindex tick operator (@code{'})
@sxindex 'x@r{,} 'y@r{, and }'z
@samp{'x} extracts components of points and
vectors.
@node More to learn, , Affine arithmetic, Swept objects
@comment node-name, next, previous, up
@subsection More to learn
This is not the end of the story on sweeps! We invite the reader into
the main body of this documentation @ref{Sweeps} to learn more.
@center @image{ex120}
@noindent
Who knows where you'll finish?
@node Input language, Building a drawing, Introduction by example, Top
@comment node-name, next, previous, up
@chapter Input language
This chapter describes the @code{sketch} input language in detail.
@menu
* Language basics:: Case, space, comments, include files.
* Drawables:: Things that can be drawn.
* Definitions:: Giving things names.
* Global environment:: Affect the entire drawing.
@end menu
@node Language basics, Drawables, Input language, Input language
@comment node-name, next, previous, up
@section Basics
@code{Sketch} input is plain ASCII text, usually stored in an input
file.
@cindex input file
@cindex file, input
It describes a @dfn{scene},
so the sketch language is a @dfn{scene description
language}.
@cindex scene description language
@cindex language, scene description
@code{Sketch} input is also @dfn{declarative}.
@cindex declarative language
@cindex language, declarative
It merely
declares what the scene ought to look like when drawing is complete
and says very little about how @code{sketch} should do its work.
@code{Sketch} commands are not executed sequentially as in the usual
programming language. They merely contribute to that declaration.
A few syntactic details are important. Case is significant in the
@code{sketch} language. With a few exceptions, white space is not.
This includes line breaks.
@cindex white space
Comments begin with @code{%} or @code{#} and extend to the end of the
line. You can disable a chunk of syntactically correct @code{sketch}
code by enclosing it in a @code{def}.
@cindex comments
There is a simple ``include file'' mechanism.
@cindex include file
@cindex file, include
The command
@sxindex input
@verbatim
input{otherfile.sk}
@end verbatim
@noindent
causes the contents of @file{otherfile.sk} to be inserted as though
they were part of the current file.
@menu
* Identifiers:: Names for things.
* Key and reserved words:: Names you shouldn't use.
* Literals:: Constants and constructors.
* Arithmetic:: Rules for expressions.
* Options:: Modifying object appearance.
@end menu
@node Identifiers, Key and reserved words, Language basics, Language basics
@comment node-name, next, previous, up
@subsection Identifiers
Identifiers in @code{sketch} are references to earlier-defined
options, scalars, points, vectors, transforms, drawables, and tags.
@cindex identifiers
Definitions are explained in @ref{Definitions}.
An identifier consists of a leading letter followed by letters,
numbers and underscores. The last character may @emph{not} be an
underscore. Keywords cannot be used as identifiers, and reserved
words ought to be avoided. @xref{Key and reserved words}.
@node Key and reserved words, Literals, Identifiers, Language basics
@comment node-name, next, previous, up
@subsection Key and reserved words
@cindex keywords
The keywords of @code{sketch} are @code{picturebox} @code{curve}
@code{def} @code{dots} @code{frame} @code{global} @code{input}
@code{line} @code{polygon} @code{put} @code{repeat} @code{set}
@code{sweep} and @code{then}. The @code{sketch} parser will note a
syntax error if any of these are used in place of a proper identifier.
In addition, there are reserved words
@cindex reserved words
that can currently be defined by the user, but with the risk that
future versions of @code{sketch} will reject those definitions. The
reserved words are @code{atan2} @code{cos} @code{inverse}
@code{perspective} @code{project} @code{rotate} @code{scale}
@code{sin} @code{special} @code{sqrt} @code{translate} @code{unit} and
@code{view}.
@node Literals, Arithmetic, Key and reserved words, Language basics
@comment node-name, next, previous, up
@subsection Literals
Literals in @code{sketch} include scalars, points, vectors, and
transforms. Literals, along with defined object references,
are used in arithmetic expressions. @xref{Arithmetic}.
@menu
* Scalar literals:: Just the numbers.
* Point and vector literals:: 3d quantities.
* Transform literals:: Matrix form.
@end menu
@node Scalar literals, Point and vector literals, Literals, Literals
@comment node-name, next, previous, up
@subsubsection Scalar literals
@cindex scalar literal
@cindex literal, scalar
Scalar literals are positive floating point numbers with syntax
according to C conventions. The following are some examples.
@example
0 1004 .001 8.3143 3. 1.60E-19 6.02e+23
@end example
@noindent
Scalar literals may not contain embedded spaces.
@node Point and vector literals, Transform literals, Scalar literals, Literals
@comment node-name, next, previous, up
@subsubsection Point and vector literals
@cindex point literal
@cindex literal, point
@cindex vector literal
@cindex literal, vector
Points and vector literals have these forms respectively.
@example
(@i{X},@i{Y},@i{Z}) [@i{X},@i{Y},@i{Z}]
@end example
@noindent
Each of the components is itself a scalar expression. The
@math{z}-components are optional and default to zero.
@node Transform literals, , Point and vector literals, Literals
@comment node-name, next, previous, up
@subsubsection Transform literals
@cindex transform literal
@cindex literal, transform
Most transform literals are formed by @dfn{constructors}.
@cindex constructor
These are summarized in the following table.
@multitable {@code{[[@math{a_{11}},@math{a_{12}},@math{a_{13}},@math{a_{14}}],}}{point,vector,vector}{Long column meant to wrap but does it? Maybe.}
@headitem Constructor @tab Param types @tab Description
@item @code{rotate(A,P,X)}
@sxindex rotate
@cindex rotation transform
@cindex transform, rotation
@tab scalar,point,vector
@tab Rotate @code{A} degrees about point @code{P} with axis @code{X}
according to the right hand rule. @xref{Right hand rule}.
@code{P} and @code{X} are both optional and default to the origin and
the @math{z}-axis respectively.
@item @code{translate(X)}
@sxindex translate
@cindex translation transform
@cindex transform, translation
@tab vector
@tab Translate by @code{X}.
@item @code{scale(S)}
@sxindex scale
@cindex scale transform
@cindex transform, scale
@tab scalar
@tab Scale uniformly by factor @code{S}.
@item @code{scale(V)}
@sxindex scale
@cindex scale transform
@cindex transform, scale
@tab vector
@tab Scale along each axis by components of @code{V}.
@item @code{project()}
@sxindex project
@cindex parallel projection
@cindex projection, parallel
@tab ---
@tab Same as @code{scale([1,1,0])}.
@item @code{project(S)}
@sxindex project
@cindex perspective projection
@cindex projection, perspective
@tab scalar
@tab Perspective projection with view center at origin and projection
plane @math{z=-@code{S}}.
@item @code{perspective(S)}
@sxindex perspective
@cindex perspective projection
@cindex projection, perspective
@tab scalar
@tab Perspective @emph{transform} identical to @code{project(S)}
except that the @math{z}-coordinate of the transformed result is
@dfn{pseudodepth}, usable by the hidden surface algorithm.
@cindex hidden surface algorithm
@item @code{view(E,D,U)}
@sxindex view
@cindex view transform
@cindex transform, view
@tab point,vector,vector
@tab View transform similar to that of @code{OpenGL}'s. The
@emph{eye point} @code{E} is translated to the origin while a rotation
is also applied that makes the @emph{view direction vector} @code{D}
and the @emph{view ``up'' vector} @code{U} point in the negative
@math{z}- and the @math{y}-directions respectively. If @code{U} is
omitted, it defaults to @math{[0,1,0]}. When @code{U} is omitted,
@code{D} may be also; it defaults to @code{(0,0,0)-(E)}, a vector
pointing from the eye toward the origin.
@item @code{view(E,L,U)}
@sxindex view
@cindex view transform
@cindex transform, view
@tab point,point,vector
@tab An alternate form of @code{view(E,D,U)} above where
the view direction parameter @code{D} is replaced with a
``look at'' point @code{L}, i.e., a point where the viewer is focusing
her attention. This form of view is equivalent to
@code{view(E, (L)-(E), U)}, where @code{(L)-(E)} is a direction
vector. @code{U} is optional and defaults to @math{[0,1,0]}.
@item
@code{[[@math{a_{11}},@math{a_{12}},@math{a_{13}},@math{a_{14}}]}@*
@code{@w{ }[@math{a_{21}},@math{a_{22}},@math{a_{23}},@math{a_{24}}]}@*
@code{@w{ }[@math{a_{31}},@math{a_{32}},@math{a_{33}},@math{a_{34}}]}@*
@code{@w{ }[@math{a_{41}},@math{a_{42}},@math{a_{43}},@math{a_{44}}]]}@*
@sxindex [[ ][ ][ ][ ]]@r{, transform literal}
@tab 16 scalars
@tab Direct transform matrix definition. Each
of the @math{a_{ij}} is a scalar expression. If you don't know what
this is about, you don't need it.
@end multitable
@noindent
The @code{project}
@sxindex project
constructor is not generally useful because it
defeats hidden surface removal by collapsing the scene onto a single
plane. It is a special purpose transform for drawing pictures of
scenes where three-dimensional objects are being projected onto
planes. See, for example, @ref{Overview}.
@node Arithmetic, Options, Literals, Language basics
@subsection Arithmetic expressions
Arithmetic expressions over @code{sketch} literals and
defined identifiers are summarized in the following tables.
@menu
* Two-operand (binary) forms:: A op B
* Unary forms:: op A (and others)
@end menu
@node Two-operand (binary) forms, Unary forms, Arithmetic, Arithmetic
@comment node-name, next, previous, up
@subsubsection Two-operand (binary) forms and precedence
Most two-operand binary
@cindex binary form
@cindex two-operand form
forms have meanings dependent on the types of
their arguments. An exhaustive summary of the possibilities is given
in the following table.
@multitable {transform}{@code{then}}{transform}{transform}{a long description that really ought to wrap but does it I do not know}
@headitem Left @tab Op @tab Right @tab Result @tab Description
@item scalar @tab @code{+} @tab scalar
@sxindex +@r{, plus operator}
@tab scalar @tab Scalar sum.
@item vector @tab @code{+} @tab vector
@tab vector @tab Vector sum.
@item point @tab @code{+} @tab vector
@tab point @tab Point-vector affine sum.
@item vector @tab @code{+} @tab point
@tab " @tab "
@item scalar @tab @code{-} @tab scalar
@sxindex -@r{, minus operator}
@tab scalar @tab Scalar difference.
@item vector @tab @code{-} @tab vector
@tab vector @tab Vector difference.
@item point @tab @code{-} @tab point
@tab vector @tab Point-point affine difference.
@item point @tab @code{-} @tab vector
@tab point @tab Point-vector affine difference.
@item scalar @tab @code{*} or
@code{.} @tab scalar
@sxindex *@r{, multiplication operator}
@sxindex .@r{, dot operator}
@tab scalar @tab Scalar product.
@item scalar @tab @code{*} or
@code{.} @tab vector
@tab vector @tab Scalar-vector product.
@item vector @tab @code{*} or
@code{.} @tab scalar
@tab " @tab "
@item vector @tab @code{*} @tab vector
@tab vector @tab Vector cross-product.
@item vector @tab @code{.} @tab vector
@tab scalar @tab Vector dot product.
@item scalar @tab @code{^} @tab scalar
@sxindex ^@r{, exponentiation operator}
@tab scalar @tab Raise scalar to scalar power.
@item transform @tab @code{^} @tab integer
@tab transform @tab Raise transform or integer power.
@cindex transform
@item transform @tab @code{*} or
@code{.} @tab point
@tab point @tab Affine point transform (right-to-left).
@item transform @tab @code{*} or
@code{.} @tab vector
@tab vector @tab Affine vector transform (right-to-left).
@item transform @tab @code{*} or
@code{.} @tab transform
@tab transform @tab Transform composition (right-to-left).
@item point @tab @code{then} @tab transform
@sxindex then
@tab point @tab Affine point transform (left-to-right).
@item vector @tab @code{then} @tab transform
@tab vector @tab Affine vector transform (left-to-right).
@item transform @tab @code{then} @tab transform
@tab transform @tab Transform composition (left-to-right).
@item scalar @tab @code{/} @tab scalar
@sxindex /@r{, division operator}
@tab scalar @tab Scalar division.
@item vector @tab @code{/} @tab scalar
@tab vector @tab Vector component-wise division by scalar.
@item point @tab @code{'} @tab @code{x}, @code{y}, or @code{z}
@cindex tick operator (@code{'})
@sxindex 'x@r{,} 'y@r{, and }'z
@tab scalar @tab Point component extraction.
@item vector @tab @code{'} @tab @code{x}, @code{y}, or @code{z}
@tab scalar @tab Vector component extraction.
@end multitable
@sp 1
@noindent
Operator precedence
@cindex precedence, operator
@cindex operator precedence
is shown in this table.
@multitable {@code{then}} {highest (most tightly binding)}
@headitem Op @tab Precedence
@item @code{'} @tab highest (most tightly binding)
@item @code{^} @tab
@item @code{-} @tab (unary negation)
@item @code{*}
@code{.}
@code{/} @tab
@item @code{+}
@code{-} @tab
@item @code{then} @tab lowest (least tightly binding)
@end multitable
@sp 1
@noindent
All operations are left-associative
@cindex operator associativity
@cindex associativity, operator
except for @samp{^}.
Parentheses @samp{( )}
@cindex parentheses
@sxindex ( )@r{, grouping}
are used for grouping to override precedence in the usual way.
As you can see, the dot operator @samp{.}
@sxindex .@r{, dot operator}
is usually a synonym for run-of-the-mill multiplication, @samp{*}.
The meanings differ only for vector operands. The @code{then}
operator
@sxindex then
merely reverses the operand
order with respect to normal multiplication @samp{*}. The intent
here is to make compositions read more naturally. The code
@example
(1,2,3) then scale(2) then rotate(30) then translate([1,3,0])
@end example
@noindent
expresses a series of successive modifications to the point,
whereas the equivalent form
@sxindex *@r{, multiplication operator}
@example
translate([1,3,0]) * rotate(30) * scale(2) * (1,2,3)
@end example
@noindent
will be intuitive only to mathematicians (and perhaps Arabic
language readers).
@node Unary forms, , Two-operand (binary) forms, Arithmetic
@comment node-name, next, previous, up
@subsubsection Unary forms
Unary or one-operand forms
@cindex unary form
@cindex one-operand form
are summarized in the following table, where @code{X}
stands for the operand.
@multitable{@code{inverse(X)}}{transform}{transform}{Long description meant to wrap eventually.}
@headitem Op @tab Operand
@tab Result @tab Description
@item @code{-X} @tab scalar
@sxindex -@r{, unary minus operator}
@tab scalar @tab Unary scalar negation.
@item @code{-X} @tab vector
@tab vector @tab Unary vector negation.
@item @code{|X|} @tab vector
@sxindex |@math{X}|@r{, magnitude operator}
@tab scalar @tab Vector length.
@item @code{unit(X)} @tab vector
@sxindex unit
@tab vector @tab Unit vector with same direction.
@item @code{sqrt(X)} @tab scalar
@sxindex sqrt
@tab scalar @tab Scalar square root.
@item @code{sin(X)} @tab scalar
@sxindex sin
@tab scalar @tab Trigonometric sine (@code{X} in degrees).
@item @code{cos(X)} @tab scalar
@sxindex cos
@tab scalar @tab Trigonometric cosine (@code{X} in degrees).
@item @code{atan2(X,Y)} @tab scalar
@sxindex atan2
@tab scalar @tab Polar angle in degrees of vector @math{[X,Y]}.
@item @code{inverse(X)} @tab transform
@sxindex inverse
@tab transform @tab Inverse transform.
@end multitable
@sp 1
@noindent
Errors are reported when @code{|X|}, @code{unit}, @code{sqrt},
@code{atan2}, and @code{inverse} fail due to bad parameters.
@node Options, , Arithmetic, Language basics
@comment node-name, next, previous, up
@subsection Options
@cindex options
@strong{Syntax:}
@example
[@var{key1}=@var{val1},@var{key2}=@var{val2},@dots{}]
@end example
@noindent
Options are used to specify details of the appearance of drawables.
As shown above, they are given as comma-separated key-value
pairs.
@menu
* PSTricks options:: Options inherited from @code{PSTricks}.
* TikZ/PGF options:: Options inherited from @code{TikZ/PGF}.
* Dots in TikZ/PGF:: Sketch uses @code{TikZ/PGF} circles for dots.
* TikZ/PGF user-defined styles:: Support for @code{TikZ/PGF} named, user-defined styles.
* Transparency:: See-through polygons.
* Internal options:: Options used by @code{sketch}.
@end menu
@node PSTricks options, TikZ/PGF options, Options, Options
@comment node-name, next, previous, up
@subsubsection @code{PSTricks} options
When @code{language pstricks} is selected (the default), permissible
key-value pairs include all those for similar @code{PSTricks} objects.
For example, a polygon might have the options
@verbatim
[linewidth=1pt,linecolor=blue,fillcolor=cyan]
@end verbatim
@noindent
@code{Sketch} merely passes these on to @code{PSTricks} without
checking or modification. Option lists are always optional. A
missing options list is equivalent to an empty one @samp{[]}.
When a @code{polygon} has options for both its face and its edges, and
the polygon is split by the hidden surface algorithm, @code{sketch}
must copy the edge options to @code{psline}s for the edge segments and
the face options to @code{pspolygon}s. Options known to @code{sketch}
for purposes of this splitting operation include @code{arrows},
@code{dash}, @code{dotsep}, @code{fillcolor}, @code{fillstyle},
@code{linecolor}, @code{linestyle}, @code{linewidth}, @code{opacity},
@code{showpoints}, @code{strokeopacity}, and @code{transpalpha}.
@node TikZ/PGF options, Dots in TikZ/PGF, PSTricks options, Options
@comment node-name, next, previous, up
@subsubsection @code{TikZ/PGF} options
@code{TikZ/PGF} options are handled much as for @code{PSTricks}.
Though @code{TikZ/PGF} often allows colors and styles to be given
without corresponding keys, for example,
@verbatim
\draw[red,ultra thick](0,0)--(1,1);
@end verbatim
@noindent
this is not permitted in @code{sketch}. To draw a red, ultra-thick
line in @code{sketch}, the form is
@verbatim
line[draw=red,style=ultra thick](0,0)(1,1)
@end verbatim
Just as for @code{PSTricks}, when a @code{polygon} has options for
both its face and its edges, and the polygon is split by the hidden
surface algorithm, @code{sketch} must copy the edge options to
@code{psline}s for the edge segments and the face options to
@code{pspolygon}s. @code{TikZ/PGF} options known to @code{sketch} for
purposes of this splitting operation include @code{arrows},
@code{cap}, @code{color}, @code{dash pattern}, @code{dash phase},
@code{double distance, draw}, @code{draw opacity}, @code{fill},
@code{fill opacity}, @code{join}, @code{line width}, @code{miter
limit}, @code{pattern}, @code{pattern color}, and @code{style}.
The @code{style} option can contain both face and edge information, so
@code{sketch} must check the style value. Values known to
@code{sketch} include @code{dashed}, @code{densely dashed},
@code{densely dotted}, @code{dotted}, @code{double}, @code{loosely
dashed}, @code{loosely dotted}, @code{nearly opaque}, @code{nearly
transparent}, @code{semithick}, @code{semitransparent}, @code{solid},
@code{thick}, @code{thin}, @code{transparent},
@code{ultra nearly transparent}, @code{ultra thick}, @code{ultra thin},
@code{very nearly transparent}, @code{very thick}, and @code{very thin}.
@node Dots in TikZ/PGF, TikZ/PGF user-defined styles, TikZ/PGF options, Options
@comment node-name, next, previous, up
@subsubsection Dots in @code{TikZ/PGF}
@code{TikZ/PGF} does not have a @code{dots} command as does PSTricks.
Instead, @code{Sketch} emits dots as @code{filldraw} circles. The
diameter may be set using the option @code{dotsize} borrowed from
PSTricks. The @code{dotsize} option will be removed from the option
list in the output @code{filldraw} command. Other options work in the
expected way. For example, @code{fill} sets fill color and
@code{color} sets line color of the circles.
@node TikZ/PGF user-defined styles, Transparency, Dots in TikZ/PGF, Options
@comment node-name, next, previous, up
@subsubsection @code{TikZ/PGF} user-defined styles
@code{TikZ/PGF} allows named styles defined by the user, for
example
@verbatim
\tikzstyle{mypolygonstyle} = [fill=blue!20,fill opacity=0.8]
\tikzstyle{mylinestyle} = [red!20,dashed]
@end verbatim
@noindent
Since @code{sketch} has no information on the contents of such styles,
it omits them entirely from lines, polygons, and their edges during
option splitting. For example,
@verbatim
polygon[style=mypolygonstyle,style=thick](0,0,1)(1,0,0)(0,1,0)
line[style=mylinestyle](-1,-1,-1)(2,2,2)
@end verbatim
@noindent
produces the @code{TikZ} output
@verbatim
\draw(-1,-1)--(.333,.333);
\filldraw[thick,fill=white](0,0)--(1,0)--(0,1)--cycle;
\draw(.333,.333)--(2,2);
@end verbatim
@noindent
Note that the user-defined styles are not present. Sketch also issues
warnings:
@verbatim
warning, unknown polygon option style=mypolygonstyle will be ignored
warning, unknown line option style=mylinestyle will be ignored
@end verbatim
The remedy is to state explicitly whether a user-defined style should
be attched to polygons or lines in the @code{TikZ} output using
@emph{pseudo-options} @code{fill style} and @code{line style},
@cindex pseudo-options
@sxindex fill style
@sxindex line style
@verbatim
polygon[fill style=mypolygonstyle,style=thick](0,0,1)(1,0,0)(0,1,0)
line[line style=mylinestyle](-1,-1,-1)(2,2,2)
@end verbatim
@noindent
Now, the output is
@verbatim
\draw[mylinestyle](-1,-1)--(.333,.333);
\filldraw[mypolygonstyle,thick](0,0)--(1,0)--(0,1)--cycle;
\draw[mylinestyle](.333,.333)--(2,2);
@end verbatim
A useful technique is to include user-defined style definitions in
@code{sketch} code as @code{special}s with option @code{[lay=under]}
to ensure that the styles are emitted first in the output, before
any uses of the style names.
@footnote{This clever trick is due to Kjell Magne Fauske.} For
example,
@verbatim
special|\tikzstyle{mypolygonstyle} = [fill=blue!20,fill opacity=0.8]|[lay=under]
special|\tikzstyle{mylinestyle} = [red!20,dashed]|[lay=under]
@end verbatim
@noindent
The author is responsible for using the key, @code{line style}
or @code{fill style}, that matches the content of the style
definition.
@node Transparency, Internal options, TikZ/PGF user-defined styles, Options
@comment node-name, next, previous, up
@subsubsection Transparency
@cindex transparency
Both @code{PSTricks} and @code{TikZ/PGF} support polygon options that
have the effect of making the polygon appear transparent. For
@code{PSTricks}, keywords @code{opacity} and @code{transpalpha} have
both been used, with the correct one depending on version.
@code{TikZ/PGF} uses @code{opacity} only.
@opindex transpalpha
@opindex opacity
@opindex fill opacity
When transparent polygons are in the foreground, objects behind them
(drawn earlier) are visible with color subdued and tinted. The hidden
surface algorithm of @code{sketch} works well with such transparent
polygons.
Note that @verb{|cull=false|}
@opindex cull
must be used for rear-facing polygons to be visible when positioned
behind other transparent surfaces.
@node Internal options, , Transparency, Options
@comment node-name, next, previous, up
@subsubsection Internal options
There are also @emph{internal} options
@cindex options, internal
@cindex internal options
used only by @code{sketch} and not
passed on to @code{PSTricks}. These are summarized in the following
table.
@sxindex cull
@sxindex lay
@sxindex split
@multitable {@code{split}}{@code{over}, @code{in}, @code{under}}{A column that ought to wrap. Will it wrap? I do not know.}
@headitem Key @tab Possible values @tab Description
@item @code{cull}
@tab @code{true}, @code{false}
@tab Turn culling of backfaces on and off respectively for this object.
The default value is @code{true}.
@item @code{lay}
@tab @code{over}, @code{in}, @code{under}
@tab Force this object to be @code{under} or
@code{over} all other objects in the depth sort
@cindex depth sort
order created by the hidden surface algorithm. The default value
@code{over} guarantees that output due to the @code{special} will be
visible.
@item @code{split}
@tab @code{true}, @code{false}
@tab Turn splitting of sweep-generated body polygons
@cindex body polygon
@cindex polygon, body
on and off respectively. @xref{Sweeps}. The default value @code{true}
causes ``warped'' polygons to be split into triangles, which avoids
mistakes by the hidden surface algorithm.
@end multitable
@subsection Point lists
@sxindex point list
@strong{Syntax:}
@example
(@var{x1},@var{y1},@var{z1})(@var{x2},@var{y2},@var{z2})@dots{}
@end example
@noindent
A sequence of one or more points makes a point list, a feature
common to all drawables. Each of the point components is a scalar
arithmetic expression. Any point may have the @math{z}-component
omitted; it will default to @math{z=0}.
@menu
* Drawables:: Things that are drawn.
* Definitions:: Things with names.
@end menu
@node Drawables, Definitions, Language basics, Input language
@comment node-name, next, previous, up
@section Drawables
@cindex drawable
Drawables are simply @code{sketch} objects that might appear in the
drawing. They include dots, polylines, curves, polygons, and more
complex objects that are built up from simpler ones in various ways.
Finally, @dfn{special} objects are those composed of @LaTeX{} or
@code{PSTricks} code, perhaps including coordinates and angles
computed by @code{sketch}.
@menu
* Dots:: Draw dots.
* Lines:: Draw polylines.
* Curves:: Draw curves.
* Polygons:: Draw polygons.
* Specials:: Embed raw @LaTeX{} and @code{PSTricks}.
* Sweeps:: Draw sweeps of dots and polylines.
* Blocks:: Group other drawables.
* Repeats:: Draw transformed copies of objects.
* Puts:: Draw one object transformed.
@end menu
@node Dots, Lines, Drawables, Drawables
@comment node-name, next, previous, up
@subsection Dots
@sxindex dots
@strong{Syntax:}
@example
dots[@var{options}] @var{point_list}
@end example
@noindent
This command is the three-dimensional equivalent of the
@code{PSTricks} command @code{\psdots}.
@node Lines, Curves, Dots, Drawables
@comment node-name, next, previous, up
@subsection Lines
@sxindex line
@strong{Syntax:}
@example
line[@var{options}] @var{point_list}
@end example
@noindent
This command is the three-dimensional equivalent of the
@code{PSTricks} command @code{\psline}.
@node Curves, Polygons, Lines, Drawables
@comment node-name, next, previous, up
@subsection Curves
@sxindex curve
@strong{Syntax:}
@example
curve[@var{options}] @var{point_list}
@end example
@noindent
This command is the three-dimensional equivalent of the
@code{PSTricks} command @code{\pscurve}. @b{It is not
implemented in the current version of @code{sketch}}.
@node Polygons, Specials, Curves, Drawables
@comment node-name, next, previous, up
@subsection Polygons
@sxindex polygon
@strong{Syntax:}
@example
polygon[@var{options}] @var{point_list}
@end example
@noindent
@noindent
This command is the three-dimensional equivalent of the
@code{PSTricks} command @code{\pspolygon}. The @code{sketch} hidden
surface algorithm assumes that polygons are convex and planar.
@cindex polygon, planar
@cindex planarity of polygons
In practice, drawings may well turn out correctly even if these
assumptions are violated.
@node Specials, Sweeps, Polygons, Drawables
@comment node-name, next, previous, up
@subsection Specials
@sxindex special
@strong{Syntax:}
@example
special $@var{raw_text}$[lay=@var{lay_value}] @var{point_list}
@end example
@noindent
Here @code{$}
@cindex quoting, special
can be any character and is used to delimit the start
and end of @var{raw_text}. The command embeds @var{raw_text} in the
@code{sketch} output after performing substitutions as follows.
@cindex special argument substitution
@cindex argument, special
@itemize
@item
@code{#@var{i}} where @var{i} is a positive integer is replaced by
the @var{i}'th point in @var{point_list}.
@item
@code{#@{@var{i}@}} is also replaced as above.
@item
@code{#@var{i}-@var{j}} where @var{i} and @var{j} are positive
integers is replaced by a string @code{@{@var{angle}@}} where
@var{angle} is the polar angle of a vector from the @var{i}'th point
in @var{point_list} to the @var{j}'th.
@item
@code{#@{@var{i}-@var{j}@}} is also replaced as above.
@item
@code{##} is replaced with @code{#}.
@end itemize
@noindent
The forms with braces @samp{@{ @}} are useful when the argument is
immediately followed by a digit that is part of the @TeX{} code.
The only useful option of @code{special} is @code{lay}.
@sxindex lay
@xref{Internal options}.
@node Sweeps, Blocks, Specials, Drawables
@comment node-name, next, previous, up
@subsection Sweeps
@sxindex sweep
@strong{Syntax:}
@example
sweep @{ @var{n}, @var{T_1}, @var{T_2}, @dots{}, @var{T_@math{r}} @}[@var{options}] @var{swept_object}
sweep @{ @var{n}<>, @var{T_1}, @var{T_2}, @dots{}, @var{T_@math{r}} @}[@var{options}] @var{swept_object}
@end example
@noindent
The sweep connects @var{n} (or perhaps @math{@var{n}+1}) copies of
@var{swept_object}
@cindex swept object
in order to create a new object of higher
dimension. The @var{T_@math{i}} (for @math{i} between @math{1} and
@math{r}) are transforms.
@cindex transform
The @math{k}'th copy of @var{swept_object} is produced by applying the
following transform to the original.
@example
@math{@var{T_1}^k} then @math{@var{T_2}^k} then @dots{} then @math{@var{T_r}^k}
@end example
@noindent
Here @math{@var{T}^k} means ``transform @var{T} applied @math{k}
times.'' The original object is the zero'th copy, with @math{k=0} and
effectively no transform applied (@math{T^0=I}, the identity
transform).
The method of connecting the copies depends on the type of
@var{swept_object} and on whether the closure tag
@sxindex <>@r{, closure tag}
@cindex closure tag, @code{<>}
@samp{<>} is present
or not.
An example of a sweep where @math{r=2} is the Mobius figure at
@ref{More to learn}.
@menu
* Swept points:: Swept points make lines or polygons.
* Swept lines:: Swept lines make open or closed surfaces.
* Swept polygons:: Swept polygons make closed surfaces.
* Swept blocks:: Swept block @equiv{} block of sweeps.
* Sweep face splitting:: Fixing warped faces with triangles.
@end menu
@node Swept points, Swept lines, Sweeps, Sweeps
@comment node-name, next, previous, up
@subsubsection Swept points
@cindex swept point
@cindex point sweep
If @var{swept_object} is a point list and there is no closure tag,
@sxindex <>@r{, closure tag}
@cindex closure tag, @code{<>}
then @code{sweep} connects @math{@var{n}+1} successive copies of each
point (including the original) with straight line segments to form a
polyline. If there are @math{m} points in the original point list,
@cindex point list
then @math{m} polylines with @var{n} segments each are formed by the
sweep. In this manner, @code{sweep} forms a set of one-dimensional
objects (polylines) from zero-dimensional ones (points).
When there @emph{is} a closure tag,
@sxindex <>@r{, closure tag}
@cindex closure tag, @code{<>}
@code{sweep} connects @var{n}
successive copies of each point (including the original) with straight
line segments and finally connects the last copy back to the original
to form a polygon with @var{n} sides. If there are @math{m} points in
the original point list, then @math{m} polygons with @var{n} sides
each are formed by the sweep. In this manner, @code{sweep} forms a
set of two-dimensional objects (polygons) from zero-dimensional ones
(points).
Options
@cindex options, sweep
of the @code{sweep} are copied directly to the resulting
polyline(s).
@node Swept lines, Swept polygons, Swept points, Sweeps
@comment node-name, next, previous, up
@subsubsection Swept lines
@cindex swept line
@cindex line sweep
If @var{swept_object} is a polyline and there is no closure tag,
@sxindex <>@r{, closure tag}
@cindex closure tag, @code{<>}
then
@code{sweep} connects @math{@var{n}+1} successive copies of the
polyline (including the original) with four-sided polygons, each pair
of copies giving rise to a ``polygon strip.'' If there are @math{m}
points in the original polyline, then @math{(m-1)@var{n}} polygons are
formed by the sweep. We call these @dfn{body polygons}.
@cindex body polygon
@cindex polygon, body
In this manner, @code{sweep} forms a
two-dimensional surface from from a one-dimensional polyline.
The order of vertices
@cindex polygon vertex order
@cindex order, polygon vertex
produced by @code{sweep} is important. If a
polygon's vertices do not appear in counter-clockwise order in the
final image, the polygon will be culled
@cindex culling
(unless @code{cull=false} is
set). If the points in the @math{k}'th copy of the polyline are
@math{P_1}, @math{P_2}, @dots{}, @math{P_m}, and the points in the
next copy, the @math{(k+1)}st, are @math{P_1'}, @math{P_2'}, @dots{},
@math{P_m'}, then the vertex order of the generated polygons is
@display
Body polygon 1: @math{P_2} @math{P_1} @math{P_1'} @math{P_2'}
Body polygon 2: @math{P_3} @math{P_2} @math{P_2'} @math{P_3'}
@dots{}
Body polygon @math{m-1}: @math{P_m} @math{P_{m-1}} @math{P_{m-1}'} @math{P_m'}
@end display
Options of unclosed line sweeps
@cindex options, sweep
are copied to each output polygon.
Options of the swept line are ignored.
@cindex options, swept object
When there @emph{is} a closure tag,
@sxindex <>@r{, closure tag}
@cindex closure tag, @code{<>}
then @code{sweep} connects @var{n}
successive copies of the polyline (including the original) with
four-sided body polygons just as the case with no closure tag. It then
connects the last copy back to the original to form a ribbon-shaped
surface that closes on itself with two holes remaining.
Finally, the sweep adds two more polygons to seal the holes and form a
closed surface that, depending on the sweep transforms, may
represent the boundary of a solid. In this manner, @code{sweep} forms
the boundary of a three-dimensional object from a one-dimensional
polyline. We call these hole-filling polygons @dfn{ends}.
@cindex end polygon
@cindex polygon, end
The order of vertices of end polygons
@cindex polygon vertex order
@cindex order, polygon vertex
is important for correct culling
as described above. If @math{P_1^1}, @math{P_1^2}, @dots{},
@math{P_1^n} are the @var{n} copies of the first polyline point and
@math{P_m^1}, @math{P_m^2}, @dots{} ,@math{P_m^n} are the @var{n}
copies of the last polyline point, then the end polygon vertex order
is
@display
End polygon 1: @math{P_1^n}, @math{P_1^{n-1}}, @dots{} ,@math{P_1^1}
End polygon 2: @math{P_m^1}, @math{P_m^2}, @dots{} ,@math{P_m^n}
@end display
If there are no options on the swept line,
@cindex options, swept object
then the @samp{sweep}
options
@cindex options, sweep
are copied to each output polygon. If the swept line does
have options, these are copied to corresponding body polygons; the
sweep options are copied to the end polygons. In this manner, body
and ends may be drawn with different characteristics such as
@code{fillcolor}.
@node Swept polygons, Swept blocks, Swept lines, Sweeps
@comment node-name, next, previous, up
@subsubsection Swept polygons
@cindex polygon sweep
If @var{swept_object} is a polygon, the @code{sweep} connects
@math{@var{n}+1} successive copies of the closed polyline border of
the polygon to form body polygons exactly as though the border were a
swept polyline as described in @ref{Swept lines}.
@cindex body polygon
@cindex polygon, body
If there are @math{m} points in the
original polygon, then @math{m@var{n}} body polygons are formed by
this sweep. The body polygons form an @dfn{extrusion} of the boundary of the
original polygon with two holes at the open ends.
Finally, the sweep adds two copies of the original polygon to cover
the holes. We call these hole-filling polygons @dfn{ends}.
@cindex end polygon
@cindex polygon, end
In this manner, @code{sweep} forms the boundary of a three-dimensional
object from a two-dimensional polygon.
The order of vertices
@cindex polygon vertex order
@cindex order, polygon vertex
of end polygons is important for correct culling as described above.
An exact copy of the original polygon with vertex order intact forms
the first end polygon. The other end polygon results from
transforming and the reversing the order of vertices in the original.
The transform places the original polygon at the uncovered hole;
it is
@example
@math{@var{T_1}^n} then @math{@var{T_2}^n} then @dots{} then @math{@var{T_r}^n}.
@end example
@noindent
If there are no options on the swept polygon, then the @samp{sweep}
options are copied to each output polygon. If the swept polygon does
have options, these are copied to the ends; the sweep options are
copied to the body polygons. In this manner, body and ends may be
drawn with different characteristics such as @code{fillcolor}.
@node Swept blocks, Sweep face splitting, Swept polygons, Sweeps
@comment node-name, next, previous, up
@subsubsection Swept blocks
@cindex swept bock
@cindex block sweep
The swept object @var{swept_object} may also be any collection of
polylines and polygons. This may be a block
@cindex block
@sxindex @{ @}@r{, block drawable}
composed of @code{line}
@sxindex line
and/or @code{polygon}
@sxindex polygon
commands in braces
@samp{@{ @}}, or it may be the result of a @code{repeat}, another
@code{sweep}, etc. The sweep acts independently on each object in the
block exactly as if it were a single swept object described above in
@ref{Swept lines} and @ref{Swept polygons}.
@node Sweep face splitting, , Swept blocks, Sweeps
@comment node-name, next, previous, up
@subsubsection Sweep face splitting
Before sending each four-sided body polygon of a @code{sweep}
to the output, @code{sketch} tests to see if it is roughly planar.
@cindex polygon, planar
@cindex planarity of polygons
Since planarity is necessary for proper functioning of the hidden
surface algorithm, ``warped'' polygons are automatically split into
two triangles.
Hole-filling polygons produced by closure-tagged
@sxindex <>@r{, closure tag}
@cindex closure tag, @code{<>}
line sweeps are not
split. Nor are original polygons in polygon sweeps. It is the user's
responsibility to ensure these are planar.
@node Blocks, Repeats, Sweeps, Drawables
@comment node-name, next, previous, up
@subsection Blocks
@cindex block
@sxindex @{ @}@r{, block drawable}
Any sequence of drawables may be grouped in a @dfn{block} merely by
enclosing them in braces @samp{@{ @}}. A block is itself drawable. A
key use of blocks is to extend the effect of a single @code{def},
@ref{Definitions}, @code{put} @ref{Puts}, @code{sweep} @ref{Sweeps},
or @code{repeat} @ref{Repeats} to include several objects rather than
one.
Definitions (@xref{Definitions}.) inside a block have @dfn{lexical
scope}
@cindex lexical scope
@cindex scope, identifier
extending from the place of definition to the end of the block.
@node Repeats, Puts, Blocks, Drawables
@comment node-name, next, previous, up
@subsection Repeats
@sxindex repeat
@cindex repeated object
@strong{Syntax:}
@example
repeat @{ @var{n}, @var{T_1}, @var{T_2}, @dots{}, @var{T_r} @} @var{repeated_object}
@end example
@noindent
The repeat makes @var{n} transformed copies of @var{repeated_object}
(including the original). The @var{T_@math{i}} are transforms.
@cindex transform
The @math{k}'th copy of the @var{repeated_object} (for
@math{k=0,1,...,n-1}) is produced in the
same manner as for @code{sweep}s described in @ref{Sweeps}. This is
repeated here (no pun intended) for convenience. To make the
@math{k}'th copy, the following transform is applied to the
original object.
@example
@math{@var{T_1}^k} then @math{@var{T_2}^k} then @dots{} then @math{@var{T_r}^k}
@end example
@noindent
Here @math{@var{T}^k} means ``transform @var{T} applied @math{k}
times.''
@node Puts, , Repeats, Drawables
@comment node-name, next, previous, up
@subsection Puts
@sxindex put
@strong{Syntax:}
@example
put @{ @var{T} @} @var{put_object}
@end example
@noindent
Put merely applies transform @var{T} to the drawable @var{put_object}.
@node Definitions, Global environment, Drawables, Input language
@comment node-name, next, previous, up
@section Definitions
@cindex definition
Definitions give names to @code{sketch} objects. Definitions alone
are benign. A @code{sketch} input file consisting entirely of
definitions will generate no drawing. Only when definitions are
@dfn{referenced} do they potentially lead to ink on the drawing.
The intent of definitions is to make @code{sketch} code more concise
and readable. There is no input file employing definitions
that could not be re-written without them.
Definable objects include any result of an affine arithmetic
expression (scalar, point, vector, or transform), any drawable
object (dots, line, curve, polygon, block, sweep, put, repeat, or
special), and option strings. In addition, @dfn{tag definitions},
@cindex definition, tag
@cindex tag definition
which have no associated object at all, allow the meaning of other
definitions to be selected from a set of alternatives. Since tags may
be defined (and undefined) in the command line of @code{sketch}, they
can be an aid in the script-driven preparation of documents.
@menu
* Forms of definitions:: Different defs for different purposes.
* Forms of references:: How references denote types.
@end menu
@node Forms of definitions, Forms of references, Definitions, Definitions
@comment node-name, next, previous, up
@subsection Forms of definitions
Definitions have three possible forms, @dfn{simple},
@cindex simple definition
@cindex definition, simple
@dfn{with alternatives},
@cindex definition with alternatives
@cindex alternatives, definition
and @dfn{tag}
@cindex tag definition
@cindex definition, tag
as shown here in order.
@noindent
@strong{Syntax:}
@example
def @var{id} @var{object} % simple def
def @var{id} <@var{tag_1}> @var{object_1} % def with alternatives
<@var{tag_2}> @var{object_2}
@dots{}
<> @var{default_object}
def @var{id} <> % tag def
@end example
@noindent
The simple definition merely associates @var{object} with the
identifier @var{id}.
The definition with alternatives associates
@var{object_i} with @var{id}, where @var{tag_i} is the
first defined tag in the list of alternative tag references.
@cindex tag reference
@cindex reference, tag
@sxindex <foo>@r{, tag reference}
If no tag in the list is defined, then @var{default_object} is
associated with identifier @var{id}.
The final form defines @var{id} as a tag. Another way to define a tag
is with the @option{-D} command line option. @xref{Command line}.
@node Forms of references, , Forms of definitions, Definitions
@subsection Forms of references
References to defined names are enclosed in bracketing delimiters.
The delimiter characters imply the type of the associated value as
shown in the table below. A type error is raised if the type of a
reference does not match the type of the defined value. The intent of
this mechanism is, again, to make @code{sketch} input files more
readable.
@multitable {transform}{@code{[@var{id}]} or @code{[@var{id1}, ..., @var{idN}]}}
@headitem Type @tab Reference
@item scalar @tab @code{@var{id}}
@cindex scalar reference
@cindex reference, scalar
@item point @tab @code{(@var{id})}
@cindex point reference
@cindex reference, point
@sxindex (foo)@r{, point reference}
@item vector @tab @code{[@var{id}]}
@cindex vector reference
@cindex reference, vector
@sxindex [foo]@r{, vector reference}
@item transform @tab @code{[[@var{id}]]}
@cindex transform reference
@cindex reference, transform
@sxindex [[foo]]@r{, transform reference}
@item drawable @tab @code{@{@var{id}@}}
@cindex drawable reference
@cindex reference, drawable
@sxindex @{foo@}@r{, drawable reference}
@item options @tab @code{[@var{id}]} or @code{[@var{id1},...,@var{idN}]}
@cindex options reference
@cindex reference, options
@sxindex [foo]@r{, options reference}
@cindex options multiple reference
@cindex reference, multiple options
@sxindex [foo,...,bar]@r{, multiple options reference}
@item tag @tab @code{<@var{id}>}
@cindex tag reference
@cindex reference, tag
@sxindex <foo>@r{, tag reference}
@end multitable
@sp 1
@noindent
Note that square brackets @samp{[ ]} are used both for vector and for
options references. Details of @code{sketch} syntax make it
impossible for these two reference types to be confused. The
special multiple reference @code{[@var{id1},@var{id2},...,@var{idN}]}
acts as if the respective lists of options were concatenated.
@node Global environment, , Definitions, Input language
@comment node-name, next, previous, up
@section Global environment
An optional global environment block provides a few ways to affect the
entire scene. The block must appear as the last text in the
@code{sketch} input file. It may include definitions, but note
that previous definitions at the top level (not nested inside
blocks) are also available.
@noindent
@strong{Syntax:}
@sxindex global
@example
global @{ @var{environment_settings} @}
@end example
@noindent
The contents of @var{environment_settings} are discussed in the
sections that follow.
@menu
* Global options:: Attributes of the entire drawing.
* Camera:: A final camera transformation of the scene.
* Picture box:: Setting the bounding box and 2d clipping.
* Frame:: Adding a box around the drawing.
* Language:: Setting the output language.
@end menu
@node Global options, Camera, Global environment, Global environment
@comment node-name, next, previous, up
@subsection Global options
@cindex options, global
@cindex global options
@sxindex set
@strong{Syntax:}
@example
set [ @var{options} ]
@end example
@noindent
The contents of @var{options}, except for @code{sketch} internal
options, are copied as-is to a @verb{|\psset|} that appears before
anything else in the output file. This is a good place to set
@code{unit}, a default @code{linewidth}, etc.
Internal options
@cindex options, internal
@cindex internal options
work on all objects where they make sense.
This includes
@sxindex cull
@sxindex split
@sxindex lay
@code{cull} and @code{split} (but not @code{lay}).
@xref{Internal options}.
@node Camera, Picture box, Global options, Global environment
@comment node-name, next, previous, up
@subsection Camera
@cindex camera
@strong{Syntax:}
@sxindex camera
@example
camera @var{transform_expression}
@end example
The @var{transform_expression} is applied after all other
transformations of the scene. This is currently only useful for
transforming the bounding box. @xref{Picture box}. It will play a
role in any future implementation of clipping.
@node Picture box, Frame, Camera, Global environment
@comment node-name, next, previous, up
@subsection Picture box
@cindex picture box
@strong{Syntax:}
@sxindex picturebox
@example
picturebox[@var{baseline}]
picturebox[@var{baseline}] (@var{p1})(@var{p2})
@end example
@noindent
The first form of @code{picturebox} causes a scalar @var{baseline}
fraction to be emitted in the @code{pspicture}
@cindex @code{pspicture}
@cindex baseline fraction
environment of the output. See
@code{PSTricks} documentation for @code{pspicture}.
In the second form, the @var{baseline} fraction is optional, and the
two points that follow define the diagonal of a three-dimensional
bounding box
@cindex bounding box
for the completed scene. The parallel projection
@cindex parallel projection
@cindex projection, parallel
of the bounding box
determines the corners of the drawing's @code{pspicture*} environment,
which is used in place of @code{pspicture}. This causes PostScript to
clip
@cindex clipping
the final drawing to the bounding box in 2d. If there is a
@code{camera} specified, the camera tranformation is applied to the
bounding box, and the @code{pspicture} is set just large
enough to include the transformed box.
When no bounding box is given, @code{sketch} computes one
automatically.
@node Frame, Language, Picture box, Global environment
@comment node-name, next, previous, up
@subsection Frame
@cindex frame box
@strong{Syntax:}
@sxindex frame
@example
frame [@var{options}]
@end example
@noindent
Causes a @verb{|\psframebox|}
@cindex @code{psframebox}
to surround the @code{pspicture}
environment in the output. If @var{options} are present, they are
copied as-is. Normally one would want to set
@opindex linewidth
@code{linewidth},
@opindex linestyle
@code{linestyle},
@opindex linecolor
@code{linecolor}, etc.
If omitted, then
@opindex framesep
@code{framesep=0pt} is
added so that the frame tightly hugs the @code{pspicture}.
@node Language, , Frame, Global environment
@comment node-name, next, previous, up
@subsection Language
@cindex language, output
@cindex output language
@sxindex language
@example
language tikz
language tikz, context
language pstricks
language pstricks, latex
@end example
@noindent
Sets the output language generated by @code{sketch}.
@sxindex pstricks
@sxindex tikz
The set of options understood by sketch also changes. For example,
the @code{PSTricks} option @code{linewidth} will not be properly
handled if @code{language} is set to @code{tikz}. Similarly, the
@code{TikZ} option @code{line style} (note the space) will not be
properly handled if @code{language} is set to @code{pstricks}. If no
language is specified, the default @code{pstricks} is used.
An optional comma followed by
@code{latex}
@sxindex latex
or
@code{context}
@sxindex context
specifies the macro package that the output should assume. This
affects the @code{picture} environment commands emitted and the
document template used with the @option{-T} option. @xref{Command
line}. Note that at the time this manual was generated,
@code{PSTricks} was not supported by @LaTeX{} or by @code{ConTeXt}.
@node Building a drawing, Command line, Input language, Top
@comment node-name, next, previous, up
@chapter Building a drawing
Successful drawings with @code{sketch} and with any scene description
language
@cindex scene description language
require that the user develop an accurate mental picture of her code
and its meaning. This image is best built in small pieces.
Therefore, @code{sketch} inputs are best created in small increments
with frequent pauses to compile and view the results. Careful
comments in the input often help as a scene grows in complexity.
@menu
* Overview:: Building a substantial drawing.
* A technical drawing:: An example with fine placement.
* A hierarchical model:: An example with sweeps and puts.
* Caveats:: Where trouble can occur.
@end menu
@node Overview, A technical drawing, Building a drawing, Building a drawing
@comment node-name, next, previous, up
@section Overview
As an overview, let's develop a diagram that shows how a perspective
projection transform
@cindex perspective projection
@cindex transform
@cindex projection, perspective
works. We'll start with the traditional reference object
used in computer graphics textbooks, a house-shaped prism. Begin
by defining the points of the house. Rather than defining the faces
of the house as polygons and transforming those, we are going to
transform the points themselves with @code{sketch} arithmetic so that
we have names for the transformed points later.
@sxindex def
@verbatim
% right side (outside to right)
def R1 (1,1,1) def R2 (1,-1,1) def R3 (1,-1,-1) def R4 (1,1,-1)
def R5 (1,1.5,0)
% left side (outside to right--backward)
def W [2,0,0]
def L1 (R1)-[W] def L2 (R2)-[W] def L3 (R3)-[W] def L4 (R4)-[W]
def L5 (R5)-[W]
@end verbatim
@noindent
To add a door to the house, we use a polygon slightly in
front of the foremost face of the house.
@verbatim
% door
def e .01
def D1 (0,-1,1+e) def D2 (.5,-1,1+e) def D3 (.5,0,1+e) def D4 (0,0,1+e)
@end verbatim
@noindent
Now let's create a new set of points that are a to-be-determined
transform of the originals.
@verbatim
def hp scale(1) % house positioner
def pR1 [[hp]]*(R1) def pR2 [[hp]]*(R2) def pR3 [[hp]]*(R3)
def pR4 [[hp]]*(R4) def pR5 [[hp]]*(R5)
def pL1 [[hp]]*(L1) def pL2 [[hp]]*(L2) def pL3 [[hp]]*(L3)
def pL4 [[hp]]*(L4) def pL5 [[hp]]*(L5)
def pD1 [[hp]]*(D1) def pD2 [[hp]]*(D2) def pD3 [[hp]]*(D3)
def pD4 [[hp]]*(D4)
@end verbatim
@noindent
Note the use of a @dfn{transform definition}
@cindex transform definition
@cindex definition, transform
@sxindex [[foo]]@r{, transform reference}
and
@dfn{transform references}.
@cindex transform reference
@cindex reference, transform
@sxindex [[foo]]@r{, transform reference}
Now define the seven polygonal faces of the house and the door using
the transformed points as vertices. Be careful with vertex order!
@cindex polygon vertex order
@cindex order, polygon vertex
@opindex fillcolor
@sxindex def
@sxindex polygon
@sxindex @{ @}@r{, block drawable}
@verbatim
def rgt polygon (pR1)(pR2)(pR3)(pR4)(pR5)
def lft polygon (pL5)(pL4)(pL3)(pL2)(pL1)
def frt polygon (pR2)(pR1)(pL1)(pL2)
def bck polygon (pR4)(pR3)(pL3)(pL4)
def tfr polygon (pR1)(pR5)(pL5)(pL1)
def tbk polygon (pR5)(pR4)(pL4)(pL5)
def bot polygon (pR2)(pL2)(pL3)(pR3)
def door polygon[fillcolor=brown] (pD1)(pD2)(pD3)(pD4)
def house { {rgt}{lft}{frt}{bck}{tfr}{tbk}{bot}{door} }
@end verbatim
Time for a sanity check. Add the line
@sxindex @{foo@}@r{, drawable reference}
@cindex reference, drawable
@verbatim
{house}
@end verbatim
@noindent
and this is what we get.
@center @image{ex130}
@noindent
This is correct, but does not reveal very much. Common errors are
misplaced vertices and polygons missing entirely due to incorrect
vertex order.
@cindex polygon vertex order
@cindex order, polygon vertex
To rule these out, let's inspect all sides of the
house. This is not hard. Merely replace the reference
@verb{|{house}|} with a @code{repeat}. @xref{Repeats}.
@sxindex @{foo@}@r{, drawable reference}
@cindex reference, drawable
@sxindex repeat
@sxindex rotate
@sxindex translate
@verbatim
repeat { 13, rotate(30, [1,2,3]), translate([3,0,0]) } {house}
@end verbatim
@center @image{ex140}
@noindent
Again things look correct. Note that the hidden surface algorithm
handles intersecting polygons correctly where some copies of the house
overlap.
Let's lay out the geometry of perspective projection of the house onto
a plane with rays passing through the origin. Begin by positioning the
house twelve units back on the negative @math{z}-axis and adding a set
of coordinate axes. To move the house we need only change the ``house
positioning'' transform defined earlier.
@sxindex def
@sxindex rotate
@sxindex translate
@opindex arrows
@opindex linewidth
@opindex linecolor
@opindex linestyle
@sxindex special
@sxindex line
@verbatim
def hp rotate(-40, [0,1,0]) then translate([0,0,-12])
def axes {
def sz 1
line [arrows=<->] (sz,0,0)(O)(0,sz,0)
line [arrows=->] (O)(0,0,sz)
line [linewidth=.2pt,linecolor=blue,linestyle=dashed] (O)(0,0,-10)
special |\uput[r]#1{$x$}\uput[u]#2{$y$}\uput[l]#3{$z$}|
(sz,0,0)(0,sz,0)(0,0,sz)
}
@end verbatim
Time for another test. Let's build a real view transform,
creating a @dfn{virtual camera}
@cindex virtual camera
to look at the scene we are constructing. Replace the @code{repeat}
with
@verbatim
def eye (10,4,10)
def look_at (0,0,-5)
put { view((eye), (look_at)) } { {house}{axes} }
@end verbatim
The @dfn{view transform} repositions the scene so that the point
@code{eye} is at the origin and the direction from @code{eye} to
@code{look_at} is the negative @math{z}-axis. This requires a
rotation and a translation that are all packed into the constructor
@code{view}.
@center @image{ex150}
@noindent
This is starting to look good! Add the projection plane half way
between the origin and the house at @math{z=-5}. We'll try
the angle argument feature of @code{special} to position a label.
@verbatim
def p 5 % projection distance (plane at z=-p)
def projection_plane {
def sz 1.5
polygon (-sz,-sz,-p)(sz,-sz,-p)(sz,sz,-p)(-sz,sz,-p)
special |\rput[b]#1-2#3{\footnotesize\sf projection plane}|
(-sz,-sz,-p)(sz,-sz,-p)(0,-sz+.1,-p)
}
@end verbatim
@noindent
Add @verb{|{projection_plane}|} to the list of objects in the
@code{put} above.
@center @image{ex160}
@indent
The way we constructed the points of the house now makes it easy to
draw rays of projection. We'll cast one ray from every visible vertex
of the house and define options so the appearance of
all rays can be changed at the same time.
@verbatim
def projection_rays {
def rayopt [linewidth=.3pt,linecolor=lightgray]
line [rayopt](O)(pR1) line [rayopt](O)(pR2) line[rayopt](O)(pR3)
line [rayopt](O)(pR4) line [rayopt](O)(pR5)
line [rayopt](O)(pL1) line [rayopt](O)(pL2) line[rayopt](O)(pL5)
line [rayopt](O)(pD1) line [rayopt](O)(pD2)
line [rayopt](O)(pD3) line [rayopt](O)(pD4)
}
@end verbatim
@noindent
The result is shown here.
@center @image{ex170}
@noindent
The rays pierce the projection plane at the corresponding points on
the perspective image we are trying to draw. Albrecht D@"urer and his
Renaissance contemporaries had the same idea in the early 1500's.
@center @image{duerer,,1.5in}
All that's left is to find a way to connect the points of the house
on the projection plane. We could pull out a good computer graphics
text, find the necessary matrix, and enter it ourselves as a
transform literal. @xref{Transform literals}. That work is
already done, however. We can use the @code{project(p)} constructor.
There are still some details that require care. Projection will
flatten whatever is transformed onto the plane @math{z=-p}. Therefore
any part of the house could disappear behind the projection plane (the
hidden surface algorithm orders objects at the same depth
arbitrarily). The door may also disappear behind the front of the
house. To make sure everything remains visible, we'll place the house
a tiny bit in front of the projection plane and a second copy of the
door in front of the house.
@verbatim
def projection {
% e is a small number defined above
put { project(p) then translate([0,0,1*e]) } {house}
put { project(p) then translate([0,0,2*e]) } {door}
}
@end verbatim
@center @image{ex180}
If you have studied and understand all this, you are well on the way
to success with @code{sketch}. Not shown are the 20 or so iterations
that were required to find a reasonable viewing angle and house
position, etc. Nonetheless, this drawing was completed in about an
hour. While a GUI tool may have been a little faster, it is unlikely
that a new drawing, itself a perspective projection of the scene,
could be generated with two more minutes' work! Just change the view
transform to
@verbatim
put { view((eye), (look_at)) then perspective(9) } { ...
@end verbatim
@noindent
and produce this.
@center @image{ex190}
@node A technical drawing, A hierarchical model, Overview, Building a drawing
@comment node-name, next, previous, up
@section A technical drawing
Let's look at a drawing that represents the kind of problem
@code{sketch} was meant to solve---a pair of textbook figures
regarding a polygonal approximation of a truncated cone. Here are the
pictures we will produce.
@center @image{ex250}@ @ @ @ @ @image{ex260}
The cone shape is just a swept line with no closure tag and culling
turned off. Begin by setting up some useful constants.
@sxindex def
@sxindex rotate
@verbatim
def O (0,0,0) def I [1,0,0] def J [0,1,0] def K [0,0,1]
def p0 (1,2) def p1 (1.5,0) def N 8
def seg_rot rotate(360 / N, [J])
@end verbatim
@noindent
The points @code{p0} and @code{p1} are the end points of the line to
be swept. The definition @code{seg_rot} is the sweep transformation.
With these, the cone itself is simple.
@sxindex sweep
@opindex cull
@sxindex line
@cindex swept line
@cindex line sweep
@verbatim
sweep[cull=false] { N, [[seg_rot]] } line(p0)(p1)
@end verbatim
The axes are next and include an interesing trick that shows the
hidden parts as dotted lines. The secret is draw the axes
twice---solid lines with the normal
@cindex hidden surface algorithm
hidden surface algorithm in effect, and then dotted with the
option
@opindex lay
@code{lay=over} so that no polygons can hide them.
@sxindex def
@sxindex line
@opindex arrows
@opindex linewidth
@opindex lay
@opindex linestyle
@sxindex special
@verbatim
def ax (dx,0,0) % tips of the axes
def ay (0,dy,0)
def az (0,0,dz)
line[arrows=<->,linewidth=.4pt](ax)(O)(ay)
line[arrows=->,linewidth=.4pt](O)(az)
% repeat dotted as an overlay to hint at the hidden lines
line[lay=over,linestyle=dotted,linewidth=.4pt](ax)(O)(ay)
line[lay=over,linestyle=dotted,linewidth=.4pt](O)(az)
special|\footnotesize
\uput[d]#1{$x$}\uput[u]#2{$y$}\uput[l]#3{$z$}|
(ax)(ay)(az)
@end verbatim
@noindent
The labels are applied with @code{PSTricks} special objects
@cindex special objects
as usual.
For the height dimension mark, the power of affine
@cindex affine arithmetic
arithetic is very helpful.
@sxindex def
@sxindex unit
@sxindex scale
@sxindex line
@sxindex special
@verbatim
def hdim_ref unit((p1) - (O)) then [[seg_rot]]^2
def c0 (p0) then scale([J])
def h00 (c0) + 1.1 * [hdim_ref]
def h01 (c0) + 1.9 * [hdim_ref]
def h02 (c0) + 1.8 * [hdim_ref]
line(h00)(h01)
def h10 (O) + 1.6 * [hdim_ref]
def h11 (O) + 1.9 * [hdim_ref]
def h12 (O) + 1.8 * [hdim_ref]
line(h10)(h11)
line[arrows=<->](h02)(h12)
def hm2 ((h02) - (O) + (h12) - (O)) / 2 + (O)
special|\footnotesize\rput*#1{$h$}|(hm2)
@end verbatim
The general idea employed here is to compute a unit ``reference
vector'' parallel to the @math{xz}-plane in the desired direction of
the dimension from the origin. The transformation
@code{[[seg_rot]]^2} rotates two segments about the @math{y}-axis.
When applied to @code{(p1) - (O)}, the resulting vector points to the
right as shown. In this manner, we can pick any vertex as the
location of the height dimension lines by varying the exponent of
@code{[[seg_rot]]}. This is only one of many possible strategies.
The computation of @code{hm2} is a useful idiom for finding the
@cindex centroid
centroid of a set of points.
The two radius marks are done similarly, so we present the code
without comment.
@sxindex def
@sxindex line
@sxindex special
@sxindex scale
@opindex arrows
@verbatim
% radius measurement marks
def gap [0,.2,0] % used to create small vertical gaps
% first r1
def up1 [0,3.1,0] % tick rises above dimension a little
def r1 ((p1) then [[seg_rot]]^-2) + [up1]
def r1c (r1) then scale([J])
def r1t (r1) + [gap]
def r1b ((r1t) then scale([1,0,1])) + [gap]
line[arrows=<->](r1c)(r1) % dimension line
line(r1b)(r1t) % tick
def r1m ((r1) - (O) + (r1c) - (O)) / 2 + (O) % label position
special |\footnotesize\rput*#1{$r_1$}|(r1m) % label
% same drill for r0, but must project down first
def up0 [0,2.7,0]
def r0 ((p0) then scale([1,0,1]) then [[seg_rot]]^-2) + [up0]
def r0c (r0) then scale([J])
def r0t (r0) + [gap]
def r0b ((p0) then [[seg_rot]]^-2) + [gap]
line[arrows=<->](r0c)(r0)
line(r0b)(r0t)
def r0m ((r0) - (O) + (r0c) - (O)) / 2 + (O)
special |\footnotesize\rput*#1{$r_0$}|(r0m)
@end verbatim
The second drawing uses the same techniques. Only the method for
drawing the elliptical arc is new. Here is the code.
@sxindex def
@sxindex special
@opindex lay
@verbatim
def mid ((p00)-(O)+(p10)-(O)+(p11)-(O)+(p01)-(O))/4+(O)
special|\rput#1{\pscustom{
\scale{1 1.3}
\psarc[arrowlength=.5]{->}{.25}{-60}{240}}}|
[lay=over](mid)
@end verbatim
@noindent
We could have swept a point to make the arc with @code{sketch}, but
using a @code{PSTricks} custom graphic was simpler. Again we computed
the
@cindex centroid
centroid of the quadrilateral by averaging points. Note that scaling
in Postscript distorts the arrowhead, but in this case the distortion
actually looks better in the projection of the slanted face. A
@code{sketch} arrowhead would not have been distorted.
The complete code for this example, which draws either figure
depending on the definition of the tag @code{<labeled>}, is included
in the @code{sketch} distribution in the file @file{truncatedcone.sk}.
@node A hierarchical model, Caveats, A technical drawing, Building a drawing
@comment node-name, next, previous, up
@section A hierarchical model
@cindex hierarchical model
While @code{sketch} was never meant to be a geometric modeling
language, it comes fairly close. The following example puts all we
have seen to work in a very simple model of the human hand. Start by
sweeping a line to make a truncated cone, which will be copied over
and over again to make the segments of fingers.
@sxindex def
@sxindex sweep
@sxindex rotate
@sxindex line
@verbatim
def O (0,0,0) % origin
def I [1,0,0] def J [0,1,0] def K [0,0,1] % canonical unit vectors
def segment {
def n_faces 8
sweep { n_faces<>, rotate(360 / n_faces, [J]) }
line(proximal_rad, 0)(distal_rad, distal_len)
}
@end verbatim
@noindent
In hand anatomy, @emph{distal} is ``at the tip'' and @emph{proximal}
is ``in the area of the palm.'' We have omitted all the scalar
constants. You can find them in @file{hand.sk}, which is provided
in the @code{sketch} distribution.
We also need a prototypical sphere to use for the joints themselves.
@sxindex def
@sxindex sweep
@sxindex rotate
@verbatim
def joint_sphere {
def n_joint_faces 8
sweep [fillcolor=red] { n_joint_faces, rotate(360 / n_joint_faces, [J]) }
sweep { n_joint_faces, rotate(180 / n_joint_faces) }
(0, -joint_rad)
}
@end verbatim
We'll now design the index finger (number@w{ }1 in our notational
convention; finger@w{ }0 is the thumb). The distal rotation for the
finger applies only to the tip, so we define the following.
@sxindex def
@sxindex put
@sxindex translate
@sxindex rotate
@sxindex scale
@verbatim
def distal_1 {
put { translate(joint_gap * joint_rad * [J])
then rotate(distal_1_rot, [I])
then translate((distal_len + joint_gap * joint_rad) * [J]) }
{segment}
put { rotate(distal_1_rot / 2, [I])
then translate((distal_len + joint_gap * joint_rad) * [J]) }
{joint_sphere}
put { scale( [J] + proximal_distal_ratio * ([I]+[K]) ) }
{segment}
}
@end verbatim
@noindent
The identifiers here are for size and location constants. The
exception is @code{distal_rot_1}. This rotation parameter models the
flexing of the finger tip. The first @code{put} makes a copy of the
finger segment that is translated upward
@cindex translation transform
@cindex transform, translation
just far enough to make room
for the spherical joint. Then it applies the distal rotation.
@cindex rotation transform
@cindex transform, rotation
Finally it translates the whole assembly upward again to make room for
the middle phlanges (the next bone toward the palm). The second
@code{put} positions the sphere. There is a rotation to place the
grid on the sphere surface at an nice angle, then a translation to the
base of the distal phlanges, which is also center of its rotation.
Finally, the last @code{put} positions the middle segment itself.
The middle joint is the next one down, with rotation angle
@code{middle_rot_1}. When this angle changes, we need all the objects
in @code{distal_1} to rotate as a unit.
@cindex rotation transform
@cindex transform, rotation
This is the reasoning behind
the next definition.
@verbatim
def finger_1 {
put { translate(joint_gap * joint_rad * [J])
then rotate(middle_1_rot, [I])
then translate((middle_ratio * distal_len +
joint_gap * joint_rad) * [J]) }
{distal_1}
put { scale(proximal_distal_ratio)
then rotate(middle_1_rot / 2, [I])
then translate((middle_ratio * distal_len +
joint_gap * joint_rad) * [J]) }
{joint_sphere}
put { scale( middle_ratio * [J] +
proximal_distal_ratio^2 * ([I]+[K]) ) }
{segment}
}
@end verbatim
@noindent
This looks very similar to the previous definition, and it is. The
important difference is that rather than positioning and rotating a
single segment, we position and rotate the entire ``assembly'' defined
as @code{distal_1}.
@cindex rotation transform
@cindex transform, rotation
The rest is just arithmetic to compute sizes and
positions that look nice. The last @code{put} places an appropriately
shaped segment that is the @emph{proximal phlanges}, the bone that
joins the palm of the hand. This completes the finger itself.
All the other fingers are described identically to this one. We
account for the fact that real fingers are different sizes in the next
step, which is to build the entire hand.
The @code{hand} definition that follows includes a section for each
finger. We'll continue with finger@w{ }1 and omit all the others.
(Of note is that the thumb needs slightly special treatment---an extra
rotation to account for its opposing angle. This is clear in the full
source code.) Not surprisingly, the @code{hand} definition looks very
much like the previous two. It should be no surprise that when the
rotation parameter @code{meta_1_rot} changes, the entire finger
rotates!
@cindex rotation transform
@cindex transform, rotation
There is an additional rotation that allows the fingers to spread
laterally. We say these joints of the proximal phlanges have two
@emph{degrees of freedom}. The joints higher on the finger have only
one. Finally, each finger is scaled by a factor to lend it proportion.
@verbatim
def hand {
% finger 1 [all other fingers omitted]
def scale_1 .85
put { scale(scale_1)
then translate((joint_gap * joint_rad) * [J])
then rotate(meta_1_rot, [I])
then rotate(-spread_rot, [K])
then translate((proximal_1_loc) - (O)) }
{finger_1}
put { scale(scale_1 * proximal_distal_ratio^2)
then rotate(meta_1_rot / 2, [I])
then rotate(-spread_rot, [K])
then translate((proximal_1_loc) - (O)) }
{joint_sphere}
% palm
sweep { 1, rotate(6, (0,15,0), [I]) }
put { rotate(-3, (0,15,0), [I]) } {
polygon(proximal_1_loc)(proximal_2_loc)
(proximal_3_loc)(proximal_4_loc)
(h5)(h6)(h6a)(h9)(h10)
polygon(h6a)(h7)(h8)(h9)
} }
@end verbatim
@noindent
The last section of the definition creates the polytope for the palm
of the hand by @code{sweep}ing
@cindex swept polygon
@cindex polygon sweep
a 10-sided polygon through a very short
arc (9@w{ }degrees). This provides a wedge-shaped profile when viewed
from the side. The thick end of the wedge is the wrist. Because the
polygon is concave, it is split into into two convex shapes with nine
and four vertices.
We can now have fun positioning the hand by adjusting the various
rotation angles. The complete source includes definitions with
alternatives that include the following views and more.
@center @image{ex210}@image{ex220}@image{ex230}@image{ex240}
@node Caveats, , A hierarchical model, Building a drawing
@comment node-name, next, previous, up
@section Caveats
@code{Sketch} is a fairly powerful tool for drawing, but, just as with
@TeX{}, the power to create beautiful results comes along with the
power to make mistakes. The following are some points where care is
necessary and where the current version of @code{sketch} is limited or
has known bugs.
@menu
* Limits on error detection:: What sketch doesn't do.
* Clipping:: No clipping at present.
* Hidden surface removal:: Imperfections to fix.
@end menu
@node Limits on error detection, Clipping, Caveats, Caveats
@comment node-name, next, previous, up
@subsection Limits on @code{sketch} error detection
@code{Sketch} catches many kinds of errors, but not all. For example,
options that sketch does not recognize, even incorrect ones, are
quietly copied to @code{PSTricks} commands in the output. It is also
unfortunately easy to produce @code{sketch} inputs that lead to no
picture at all (improper vertex ordering causes everything to be
culled), to pictures that are too big or too small for @code{PSTricks}
to draw (due to limits of @TeX{} math), and pictures that look nothing
like what was intended. A picture with one of these problems can be
difficult to ``debug.'' We offer the following suggestions.
@itemize
@item
Follow the suggested incremental development method described in
@ref{Overview}.
@item
Always maintain one or two back-versions of a drawing so that it is
easy to fall back to a known-good increment.
@item
When using @code{perspective}, ensure all finally transformed objects
satisfy @math{z<0} and, in fact, do not come very close to the origin
at all.
@item
Temporarily use @code{cull=false} to see where vertex ordering
problems lie.
@item
Use temporary changes of color of one or more objects to ensure that
your understanding of the scene geometry is correct.
@item
If @code{PSTricks} complains about something, inspect the output
directly for clues.
@end itemize
@node Clipping, Hidden surface removal, Limits on error detection, Caveats
@comment node-name, next, previous, up
@subsection Clipping
The current version of @code{sketch} has no clipping
@cindex clipping
operations. The entire scene is always drawn. This means that when a
perspective transform is employed, it is the user's responsibility to
make sure the entire scene remains in front of the viewer, the region
@math{z<0}.
@node Hidden surface removal, , Clipping, Caveats
@comment node-name, next, previous, up
@subsection Hidden surface removal and polygon splitting
@code{Sketch} uses the @dfn{depth sort algorithm}
@cindex depth sort
@cindex hidden surface algorithm
for hidden surface removal. This is a very old technique due to
Newell.@footnote{Newell, M.E., R.G.@: Newell, and T.L.@: Sancha, A
solution to the hidden surface problem. @i{Proceedings of the ACM
annual conference - Volume 1}, page 443--450, ACM Press, 1972.} It is
generally regarded as too slow for real time graphics, but it is
ideal for our purpose where speed is not very important.@footnote{We
have run @code{sketch} on the famous Stanford Bunny, which consists
of nearly @math{70,000} triangles. Run time was about 6 seconds.
Most of this was spent writing the output file rather than in the
hidden surface algorithm. @LaTeX{} took much longer to process the
resulting @code{PSTricks} code. The obvious conclusion is that the
speed of the depth sort algorithm is not a worry.}
The depth sort algorithm merely sorts objects on a key of increasing
@math{z}-coordinate, equivalent to decreasing depth. Objects are then
drawn in the sorted sequence so that those at the rear of the scene
are overwritten by those closer to the viewer. Since this is also
how oil painters practice their art, depth sort is sometimes called
``the painter's algorithm.''
In some cases it is impossible to strictly order polygons according to
depth. Moreover, even if a correct depth ordering exists, the
computation needed to find it may be too complex and slow. In these
cases, @code{sketch} splits
@cindex splitting, line and surface
one or more polygons into pieces. The
expectation is that the new, smaller polygons will be simpler to
order. @code{Sketch} uses a @acronym{BSP,binary space partition}
@cindex binary space partition
@cindex BSP, binary space partition
to handle the splitting operation.
@menu
* Statistics:: Performance numbers on depth sort.
* Bugs and anomalies:: Imperfections in this implementation.
@end menu
@node Statistics, Bugs and anomalies, Hidden surface removal, Hidden surface removal
@comment node-name, next, previous, up
@subsubsection Statistics
For the curious, @code{sketch} writes one line of depth sort
statistics. Here is an example for a large collection of triangles.
@verbatim
remark, node=34824 probe=581.9 swap=5 split=2 (in=4 out=6) ols=24851/0
@end verbatim
@noindent
It means that @math{34,824} objects were depth sorted after culling.
For each, an average of @math{581.9} others had to be checked to
ensure that the initial, approximate ordering was correct. Among all
these checks, only @math{5} resulted in swaps to reorder the initial
sort. In two cases, a correct ordering could not be determined, so
binary space partitions
@cindex binary space partition
were constructed for splitting. A total of @math{4}
objects (triangles in this case) were inserted in the partitions, and
@math{6} polygons were produced. Finally, @math{24,851} ``last
resort'' polygon overlap checks were performed after simpler, faster
checks failed to yield conclusive results. The final @math{/0} is for
line-polygon overlap checks. For comparison, the statistics for the
last figure in @ref{Overview} follow.
@verbatim
remark, node=27 probe=14.6 swap=36 split=15 (in=30 out=45) ols=0/69
@end verbatim
@noindent
Note that there was proportionally much more swapping and splitting
activity in this highly connected scene.
@node Bugs and anomalies, , Statistics, Hidden surface removal
@comment node-name, next, previous, up
@subsubsection Bugs and anomalies
Polygon and line splitting can both cause anomalies in the output.
@code{PSTricks} dash patterns, specified with @code{linestyle=dashed},
@opindex linestyle
can be disrupted by splitting. This occurs when the depth sort
@cindex depth sort
gives up too early and splits a line where it is not really
necessary.
A workaround is to use gray or finely dotted
lines instead. If your drawing is small, you can also edit the
@code{sketch} output by hand to merge the pieces of the offending
line.
Another anomaly is tiny (or in degenerate cases not-so-tiny) notches
in the lines that border split polygons. These derive from the way
each polygon is painted: first, all pixels within the boundary are
@dfn{filled} with color (perhaps white), then the same boundary is
@dfn{stroked} (a Postscript term) with a line. The result is that
half the line lies inside the boundary and half outside, while the
Painter's algorithm assumes the polygon lies entirely within its
boundary. The notches are due to one polygon fill operation
overwriting the already-drawn inside of the border of another
polygon.@footnote{I know how to fix this problem, but I don't like my
solution, and I'm interested in yours.} One workaround is to make
border lines very thin. In fact @code{linewidth=0pt} is guaranteed to
eliminate this problem, though this results in the thinnest line your
output device can draw, which is usually too thin. You might get
lucky by merely reordering things in the input file, which is likely
to move the splits to different places. The only sure-fire solution
is pretty terrible: custom fit @code{special} overlay lines (with
@code{\psline}) to cover the notches.
Polygon splitting also breaks @code{PSTricks} hatch patterns. The
only known workaround is to substitute a solid fill for the hatch.
@node Command line, Installing sketch, Building a drawing, Top
@comment node-name, next, previous, up
@chapter Command line
@cindex command line, @code{sketch}
@strong{Synopsis:}
@example
sketch [-h][-V x.y][-v][-b][-d][t doctmp][-T[u|e][p[P|T][L|C]]][-o output.tex]
[-D @var{tag} @dots{}] input1.sk [-U @var{tag} @dots{}] input2.sk @dots{}
@end example
@noindent
@strong{Description}
Processes the @code{sketch} input files in order to produce
@code{PSTricks} output code suitable for inclusion in a @TeX{} or
@LaTeX{} document.
@noindent
@strong{Options:}
@cindex options, command line
@cindex command line options
@table @code
@item -h
Print a short catalog of options.
@item -V
Set the @code{PSTricks} version assumed for output purposes to
@code{x.y}, for example 1.19. Usually needed only if your
@code{PSTricks} is old compared to your @code{sketch}. Use
@code{-v} to see what @code{sketch} assumes by default.
@item -v
Print version information to standard output, including the version
of @code{PSTricks} assumed for output (can be changed with @code{-V} above).
@item -b
Use a BSP
@cindex binary space partition
@cindex BSP, binary space partition
(@xref{Hidden surface removal}.) for
@emph{all} hidden surface removal rather than the default, which is
the depth sort algorithm with BSPs used only for cycle resolution.
This may produce correct output in certain degenerate cases where the
depth sort cannot, but it also leads to many gratuitous splits, hence
more anomalies @ref{Bugs and anomalies} and big output files.
@item -d
Run @code{sketch}'s parser in debugging mode. This is primarily for
development.
@item -t
Use contents of file @file{doctmp} as a document template
@cindex document template
@cindex template, document
in which to enclose @code{PSTricks} output code. The code is inserted
in place of the first instance of the escape string
@verb{|%%SKETCH_OUTPUT%%|}.
@item -T
Causes @code{PSTricks} output to be enclosed in default US document
template text. Option @option{-Tu} is a synonym. Option @option{-Te}
causes the Euro standard document template to be used. A @option{p}
appended to any of these options causes the respective default
@code{PSTricks} document template to be printed to standard output. An
appended @option{P} is a synonym. An appended @option{T} causes the
the @code{TikZ/PGF} template to be printed. An appended @option{L}
prints the @LaTeX{} version of the document template, a synonym for
the default. A @option{C} prints the @code{ConTeXt} template.
@item -o
Use @file{output.tex} as the output file. The default is standard output.
@item -D
Define a tag
@cindex tag definition
@cindex definition, tag
for purposes of selecting definition alternatives.
@xref{Definitions}. The definition applies for all input files that
follow unless the tag is undefined with @option{-U}.
@item input@math{i}.sk
Input files, read in the sequence they are given.
@item -U
Un-define a tag for purposes of selecting definition alternatives.
@end table
@node Installing sketch, Index of syntax, Command line, Top
@comment node-name, next, previous, up
@chapter Building and installing @code{sketch}
@code{Sketch} is so small that compiling by brute force is probably
best. The following command ought to do the trick on any
systems where @code{gcc} is installed. Make sure to first change
current directories to the place where you have unpacked the sources.
@example
gcc *.c -o sketch.exe -lm
@end example
@noindent
The @samp{.exe} at the end is necessary for Windows systems. Drop it
if your system is some version of Unix. Other C compilers ought
to work as just as well. For example,
@example
cl *.c -o sketch.exe
@end example
@noindent
is the correct command for many versions of MS Visual C. In the
latest versions, Microsoft has deprecated the @code{-o} option and, by
default, does not define the @code{__STDC__} macro. This causes
problems with some versions of @code{flex}, @code{bison}, @code{lex},
and @code{yacc}, which are used to create the @code{sketch} scanner
and parser. It's nearly always possible to find a set of options that
compiles with no errors or warnings, and this means @code{sketch} is
@emph{very} likely to work correctly. For example, the Visual C++
2005 Express Edition compiler (available free of charge from the
Microsoft web site), @code{flex} version 2.5.4, and @code{bison}
version 2.1 build error-free with
@example
cl -DYY_NEVER_INTERACTIVE=1 -Za -Ox -Fesketch.exe *.c
@end example
For purists, there is also a @code{makefile} compatible with GNU
@code{make} and @code{gcc}. The command
@example
make
@end example
@noindent
will build the executable, including the rebuilding of the scanner and
parser with @code{flex} and @code{bison} if you have changed
@file{sketch.l} or @code{sketch.y} respectively.
To build this document in all its myriad forms (assuming you have the
necessary conversion programs on your system), use
@example
make docs
@end example
@noindent
The possibilities are listed in this following table.
@multitable {@code{manual/index.html}}{texi2dvi,dvips}{@b{Pictures}}{wide column that needs to be as big as it needs to be,}
@headitem Format @tab Converter @tab Pictures @tab Description
@item manual.info
@tab makeinfo @tab @file{.txt} @tab @acronym{GNU} Info.
@item manual.dvi
@tab texi2dvi @tab @file{.eps} @tab @TeX{} typeset output.
@item manual.ps
@tab texi2dvi,dvips @tab @file{.eps} @tab Postscript.
@item manual.pdf
@tab texi2dvi @tab @file{.pdf} @tab Adobe PDF.
@item manual.html
@tab makeinfo @tab @file{.png} @tab A single web page.
@item manual/index.html
@tab makeinfo @tab @file{.png} @tab Linked web pages, one per node.
@end multitable
@node Index of syntax, Index, Installing sketch, Top
@comment node-name, next, previous, up
@unnumbered Index of syntax
@printindex sx
@node Index, , Index of syntax, Top
@comment node-name, next, previous, up
@unnumbered Index of concepts
@printindex cp
@bye
|