Debian Codegraph @

texmf-dist/doc/metapost/base/source-manual/mpman.mp

raw
1 % Figures for MetaPost manual, by John Hobby. Public domain.
2
3 if scantokens(mpversion) < 1.200:
4 filenametemplate
5 else:
6 outputtemplate :=
7 fi
8 "%j-%c.mps";
9
10 %%% This redefinition of dotlabel draws dots as a closed path
11 %%% which are rendered more smoothly in Adobe Reader.
12 vardef dotlabel@#(expr s,z) text t_ =
13 label@#(s,z) t_;
14 addto currentpicture
15 contour (makepath pencircle scaled dotlabeldiam) shifted z t_;
16 enddef;
17
18
19 beginfig(1);
20 draw (20,20)--(0,0)--(0,30)--(30,0)--(0,0);
21 endfig;
22
23
24 beginfig(2); numeric u;
25 u=1cm;
26 draw (2u,2u)--(0,0)--(0,3u)--(3u,0)--(0,0);
27 pickup pencircle scaled 4pt;
28 for i=0 upto 2:
29 for j=0 upto 2:
30 drawdot (i*u,j*u);
31 endfor
32 endfor
33 endfig;
34
35
36 beginfig(3);
37 z0 = (0,0); z1 = (60,40);
38 z2 = (40,90); z3 = (10,70);
39 z4 = (30,50);
40 draw z0..z1..z2..z3..z4;
41 dotlabels.top(0,2,4);
42 dotlabels.lft(3);
43 dotlabels.lrt(1);
44 endfig;
45
46
47 beginfig(104);
48 z0 = (0,0); z1 = (60,40);
49 z2 = (40,90); z3 = (10,70);
50 z4 = (30,50);
51 draw z0..z1..z2..z3..z4..cycle;
52 dotlabels.top(2,4);
53 dotlabels.lft(0,3);
54 dotlabels.lrt(1);
55 endfig;
56
57
58 beginfig(204);
59 z0 = (0,0); z1 = (60,40);
60 z2 = (40,90); z3 = (10,70);
61 z4 = (30,50);
62 draw z0..z1..z2..z3--z4--cycle;
63 dotlabels.top(2,4);
64 dotlabels.lft(0,3);
65 dotlabels.lrt(1);
66 endfig;
67
68
69 beginfig(5);
70 z0 = (0,0); z1 = (60,40);
71 z2 = (40,90); z3 = (10,70);
72 z4 = (30,50);
73 path p; p = z0..z1..z2..z3..z4;
74 draw p;
75 for t=0 upto 3:
76 draw point t of p--postcontrol t of p
77 --precontrol t+1 of p--point t+1 of p
78 dashed (evenly scaled .5);
79 endfor
80 dotlabels.top(0,2,4);
81 dotlabels.lft(3);
82 dotlabels.lrt(1);
83 endfig;
84
85
86 beginfig(6);
87 z0 = (0,0); z1 = (60,40);
88 z2 = (40,90); z3 = (10,70);
89 z4 = (30,50);
90 draw z0..z1{up}..z2{left}..z3..z4;
91 dotlabels.top(0,2,4);
92 dotlabels.lft(3);
93 dotlabels.lrt(1);
94 endfig;
95
96
97 beginfig(7)
98 for a=0 upto 9:
99 draw (0,0){dir 45}..{dir -10a}(6cm,0);
100 endfor
101 endfig;
102
103 beginfig(8)
104 for a=0 upto 7:
105 draw (0,0){dir 45}..{dir 10a}(6cm,0);
106 endfor
107 endfig;
108
109
110 beginfig(109);
111 z2=-z0=(1in,0); z1=(0,.2in);
112 draw z0{up}..z1{right}..z2{down};
113 dotlabels.bot(0,1,2);
114 endfig;
115
116
117 beginfig(209);
118 z2=-z0=(1in,0); z1=(0,.2in);
119 draw z0{up}...z1{right}...z2{down};
120 dotlabels.bot(0,1,2);
121 endfig;
122
123
124 beginfig(110);
125 numeric u; 10u=1.5in;
126 -z0=z3=(5u,0);
127 (-x1,y1)=z2=(3u,2u);
128 draw z0..z1..z2..z3;
129 dotlabels.bot(0,1,2,3);
130 endfig;
131
132
133 beginfig(210);
134 numeric u; 10u=1.5in;
135 -z0=z3=(5u,0);
136 (-x1,y1)=z2=(3u,2u);
137 draw z0..z1..tension 1.3..z2..z3;
138 dotlabels.bot(0,1,2,3);
139 endfig;
140
141
142 beginfig(310);
143 numeric u; 10u=1.5in;
144 -z0=z3=(5u,0);
145 (-x1,y1)=z2=(3u,2u);
146 draw z0..z1..tension 1.5 and 1..z2..z3;
147 dotlabels.bot(0,1,2,3);
148 endfig;
149
150
151 beginfig(111);
152 numeric u, c; 10u=1.4in; c=0;
153 z1=(0,0); (x0,-y0)=z2=(2u,5u);
154 draw z0{curl c}..z1..{curl c}z2;
155 dotlabels.rt(0,1,2);
156 endfig;
157
158
159 beginfig(211);
160 numeric u, c; 10u=1.4in; c=1;
161 z1=(0,0); (x0,-y0)=z2=(2u,5u);
162 draw z0{curl c}..z1..{curl c}z2;
163 dotlabels.rt(0,1,2);
164 endfig;
165
166
167 beginfig(311);
168 numeric u, c; 10u=1.4in; c=2;
169 z1=(0,0); (x0,-y0)=z2=(2u,5u);
170 draw z0{curl c}..z1..{curl c}z2;
171 dotlabels.rt(0,1,2);
172 endfig;
173
174
175 beginfig(411);
176 numeric u, c; 10u=1.4in; c=infinity;
177 z1=(0,0); (x0,-y0)=z2=(2u,5u);
178 draw z0{curl c}..z1..{curl c}z2;
179 dotlabels.rt(0,1,2);
180 endfig;
181
182
183 beginfig(13);
184 z1=-z2=(.2in,0);
185 x3=-x6=.3in;
186 x3+y3=x6+y6=1.1in;
187 z4=1/3[z3,z6];
188 z5=2/3[z3,z6];
189 z20=whatever[z1,z3]=whatever[z2,z4];
190 z30=whatever[z1,z4]=whatever[z2,z5];
191 z40=whatever[z1,z5]=whatever[z2,z6];
192 draw z1--z20--z2--z30--z1--z40--z2;
193 pickup pencircle scaled 1pt;
194 draw z1--z2;
195 draw z3--z6;
196 %
197 dotlabels.bot(1,2);
198 dotlabels.rt(3);
199 dotlabels.lft(6);
200 dotlabels.top(20,30,40);
201 endfig;
202
203
204 vardef llet(expr c) =
205 c infont defaultfont scaled magstep3
206 enddef;
207
208 primarydef p centered h =
209 (p shifted (h - xpart .5[llcorner p,lrcorner p], 0))
210 enddef;
211
212 beginfig(14);
213 string s; s = "abcde";
214 numeric u,n, ytop, ybot;
215 n = 5;
216 ytop = 3bp + ypart urcorner llet(s);
217 ybot = -3bp + ypart llcorner llet(s);
218 ytop - ybot = u;
219 draw (n*u,ybot)--(0,ybot)--(0,ytop)--(n*u,ytop);
220 for i=1 upto n:
221 draw (i*u,ybot)..(i*u,ytop);
222 draw llet(substring (i-1,i) of s) centered ((i-.5)*u);
223 label.bot(decimal i, (i*u,ybot));
224 endfor
225 picture llab; llab = btex \llap{$x={}$}0 etex;
226 z0 = urcorner llab;
227 draw llab shifted (-.5*x0, ybot-labeloffset-y0);
228 endfig;
229
230
231 beginfig(17);
232 a=.7in; b=.5in;
233 z0=(0,0);
234 z1=-z3=(a,0);
235 z2=-z4=(0,b);
236 draw z1..z2..z3..z4..cycle;
237 draw z1--z0--z2;
238 label.top("a", .5[z0,z1]);
239 label.lft("b", .5[z0,z2]);
240 dotlabel.bot("(0,0)", z0);
241 endfig;
242
243
244 beginfig(18);
245 numeric u;
246 u = 1cm;
247 draw (0,2u)--(0,0)--(4u,0);
248 pickup pencircle scaled 1pt;
249 draw (0,0){up}
250 for i=1 upto 8: ..(i/2,sqrt(i/2))*u endfor;
251 label.lrt(btex $\sqrt x$ etex, (3,sqrt 3)*u);
252 label.bot(btex $x$ etex, (2u,0));
253 label.lft(btex $y$ etex, (0,u));
254 endfig;
255
256
257 beginfig(19);
258 numeric ux, uy;
259 120ux=1.2in; 4uy=2.4in;
260 draw (0,4uy)--(0,0)--(120ux,0);
261 pickup pencircle scaled 1pt;
262 draw (0,uy){right}
263 for ix=1 upto 8:
264 ..(15ix*ux, uy*2/(1+cosd 15ix))
265 endfor;
266 label.bot(btex $x$ axis etex, (60ux,0));
267 label.lft(btex $y$ axis etex rotated 90,
268 (0,2uy));
269 label.lft(
270 btex $\displaystyle y={2\over1+\cos x}$ etex,
271 (120ux, 4uy));
272 endfig;
273
274
275 beginfig(20);
276 picture p;
277 p = "testing" infont "ptmr8r" scaled 7;
278 draw p;
279 draw llcorner p--lrcorner p--urcorner p--ulcorner p--cycle;
280 dotlabel.lft(btex \tt llcorner etex, llcorner p);
281 dotlabel.rt(btex \tt lrcorner etex, lrcorner p);
282 dotlabel.lft(btex \tt ulcorner etex, ulcorner p);
283 dotlabel.rt(btex \tt urcorner etex, urcorner p);
284 endfig;
285
286
287 beginfig(21);
288 path p;
289 p = (-1cm,0)..(0,-1cm)..(1cm,0);
290 fill p{up}..(0,0){-1,-2}..{up}cycle;
291 draw p..(0,1cm)..cycle;
292 endfig;
293
294
295 beginfig(22);
296 path a, b, aa, ab;
297 a = fullcircle scaled 2cm;
298 b = a shifted (0,1cm);
299 aa = halfcircle scaled 2cm;
300 ab = buildcycle(aa, b);
301 picture pa, pb;
302 pa = thelabel(btex $A$ etex, (0,-.5cm));
303 pb = thelabel(btex $B$ etex, (0,1.5cm));
304 fill a withcolor .7white;
305 fill b withcolor .7white;
306 fill ab withcolor .4white;
307 unfill bbox pa;
308 draw pa;
309 unfill bbox pb;
310 draw pb;
311 label.lft(btex $U$ etex, (-1cm,.5cm));
312 draw bbox currentpicture;
313 endfig;
314
315
316 beginfig(123);
317 path aa, b;
318 b = a shifted (0,1cm);
319 aa = halfcircle scaled 2cm;
320 draw aa;
321 draw b dashed evenly;
322 z1 = aa intersectionpoint reverse b;
323 z2 = reverse aa intersectionpoint b;
324 dotlabel.rt(btex 1 etex, z1);
325 dotlabel.lft(btex 2 etex, z2);
326 label.bot(btex \tt aa etex, point 0 of aa);
327 label.bot(btex \tt b etex, point 2 of b);
328 endfig;
329
330 beginfig(223);
331 path aa, b;
332 b = a shifted (0,1cm);
333 aa = halfcircle scaled 2cm;
334 numeric t[], tt[];
335 (t1,8-tt1) = aa intersectiontimes reverse b;
336 (4-t2,tt2) = reverse aa intersectiontimes b;
337 pickup(pencircle scaled .3);
338 draw aa;
339 draw b;
340 pickup(pencircle scaled .8);
341 draw subpath (t1,t2) of aa;
342 draw subpath (tt2,tt1) of b;
343 dotlabel.rt(btex 1 etex, point t1 of aa);
344 dotlabel.lft(btex 2 etex, point t2 of aa);
345 label.bot(btex \tt aa etex, point 0 of aa);
346 label.bot(btex \tt b etex, point 2 of b);
347 endfig;
348
349
350 beginfig(24);
351 h=2in; w=2.7in;
352 path p[], q[], pp;
353 for i=2 upto 4: ii:=i**2;
354 p[i] = (w/ii,h){1,-ii}...(w/i,h/i)...(w,h/ii){ii,-1};
355 endfor
356 q0.5 = (0,0)--(w,0.5h);
357 q1.5 = (0,0)--(w/1.5,h);
358 pp = buildcycle(q0.5, p2, q1.5, p4);
359 fill pp withcolor .7white;
360 z0=center pp;
361 picture lab; lab=thelabel(btex $f>0$ etex, z0);
362 unfill bbox lab; draw lab;
363 draw q0.5; draw p2; draw q1.5; draw p4;
364 dotlabel.top(btex $P$ etex, p2 intersectionpoint q0.5);
365 dotlabel.rt(btex $Q$ etex, p2 intersectionpoint q1.5);
366 dotlabel.lft(btex $R$ etex, p4 intersectionpoint q1.5);
367 dotlabel.bot(btex $S$ etex, p4 intersectionpoint q0.5);
368 endfig;
369
370
371 beginfig(25);
372 numeric u;
373 u = .2in;
374 path a, b;
375 a = (0,0){up}..(4u,0)..(8u,0)..(8u,4u);
376 b = (10u,3u)..(5u,u)..(-u,u);
377 numeric t; t=0;
378 forsuffixes $=bot, llft, lrt, lft:
379 dotlabel$(decimal t, point t of a);
380 t:=t+1;
381 endfor
382 for i=0 upto 2:
383 dotlabel.top(decimal i, point i of b);
384 endfor
385 pickup(pencircle scaled .3);
386 draw a;
387 pickup(pencircle scaled .8);
388 draw b;
389 % intersections (atime, btime):
390 % (0.2501,1.77225)
391 % (2.58316,0.23619)
392 % (0.75288,1.40094)
393 endfig;
394
395
396 beginfig(26);
397 numeric scf, #, t[];
398 3.2scf = 2.4in;
399 path fun;
400 # = .1; % Keep the function single-valued
401 fun = ((0,-1#)..(1,.5#){right}..(1.9,.2#){right}..{curl .1}(3.2,2#))
402 yscaled(1/#) scaled scf;
403 x1 = 2.5scf;
404 for i=1 upto 2:
405 (t[i],whatever) =
406 fun intersectiontimes ((x[i],-infinity)--(x[i],infinity));
407 z[i] = point t[i] of fun;
408 z[i]-(x[i+1],0) = whatever*direction t[i] of fun;
409 draw (x[i],0)--z[i]--(x[i+1],0);
410 fill fullcircle scaled 3bp shifted z[i];
411 endfor
412 label.bot(btex $x_1$ etex, (x1,0));
413 label.bot(btex $x_2$ etex, (x2,0));
414 label.bot(btex $x_3$ etex, (x3,0));
415 draw (0,0)--(3.2scf,0);
416 pickup pencircle scaled 1pt;
417 draw fun;
418 endfig;
419
420 beginfig(261);
421 path p[] ;
422 pen mypen ;
423 pen mypenC;
424 numeric L ;
425 numeric S ;
426 L:=10;
427 Sa:=1;
428 Sb:=2;
429 Rot=32;
430 p[-1] := ( (Sa*cosd(0),Sb*sind(0)) for i=1 upto L-1: -- (Sa*cosd(i/L*360), Sb*sind(i/L*360)) endfor -- cycle ) rotated Rot;
431 mypen := makepen(p[-1]) ;
432 mypenC:= (pencircle xscaled 2Sa yscaled 2Sb) rotated Rot;
433 p0 := (0,0){down} .. {up} (100,0) ;
434 p1 := envelope mypen of p0 ;
435 draw p1 withcolor black withpen pencircle scaled 0.2pt ;
436 draw p0 withcolor 0.8white withpen mypenC;
437 for t=1 upto length(p1):
438 draw (point t of p1) withpen pencircle scaled 0.8pt;
439 endfor;
440 %currentpicture := currentpicture scaled 30 ;
441 endfig;
442
443
444
445 beginfig(28);
446 path p[];
447 p1 = fullcircle scaled .6in;
448 z1=(.75in,0)=-z3;
449 z2=directionpoint left of p1=-z4;
450 p2 = z1..z2..{curl1}z3..z4..{curl 1}cycle;
451 fill p2 withcolor .4[white,black];
452 unfill p1;
453 draw p1;
454 transform T;
455 z1 transformed T = z2;
456 z3 transformed T = z4;
457 xxpart T=yypart T; yxpart T=-xypart T;
458 picture pic;
459 pic = currentpicture;
460 for i=1 upto 2:
461 pic:=pic transformed T;
462 draw pic;
463 endfor
464 dotlabels.top(1,2,3); dotlabels.bot(4);
465 endfig;
466
467
468 beginfig(29);
469 if unknown withdots: % So this works w/o MetaPost version 0.5
470 picture withdots; withdots=dashpattern(off 2.5 on 0 off 2.5);
471 fi
472 z0 = (0,0);
473 z1 = (2in-2bp,0);
474 for i=1 upto 4:
475 z[2i]-z[2i-2] = z[2i+1]-z[2i-1] = (0,14pt);
476 endfor
477 draw z0..z1 dashed evenly;
478 label.rt(btex \tt dashed evenly etex, z1);
479 draw z2..z3 dashed evenly scaled 2;
480 label.rt(btex \tt dashed evenly scaled 2 etex, z3);
481 draw z4..z5 dashed evenly scaled 4;
482 label.rt(btex \tt dashed evenly scaled 4 etex, z5);
483 draw z6..z7 dashed withdots;
484 label.rt(btex \tt dashed withdots etex, z7);
485 draw z8..z9 dashed withdots scaled 2;
486 label.rt(btex \tt dashed withdots scaled 2 etex, z9);
487 endfig;
488
489
490 beginfig(30);
491 picture e[]; e4=evenly scaled 4;
492 z0 = (0,0);
493 z1 = (2in,0);
494 for i=1 upto 3:
495 z[2i]-z[2i-2] = z[2i+1]-z[2i-1] = (0,14pt);
496 endfor
497 dotlabels.lft(0,2,4,6);
498 draw z0..z1 dashed e4;
499 dotlabel.rt(btex 1 \tt\ draw z0..z1 dashed e4 etex, z1);
500 draw z2..z3 dashed e4 shifted (6bp,0);
501 dotlabel.rt(btex 3 \tt\ draw z2..z3 dashed e4 shifted (6bp,0) etex, z3);
502 draw z4..z5 dashed e4 shifted (12bp,0);
503 dotlabel.rt(btex 5 \tt\ draw z4..z5 dashed e4 shifted (12bp,0) etex, z5);
504 draw z6..z7 dashed e4 shifted (18bp,0);
505 dotlabel.rt(btex 7 \tt\ draw z6..z7 dashed e4 shifted (18bp,0) etex, z7);
506 endfig;
507
508
509 beginfig(31);
510 picture d; d = dashpattern(on 6bp off 12bp on 6bp);
511 draw d;
512 endfig;
513
514
515 beginfig(32);
516 draw dashpattern(on 15bp off 15bp) dashed evenly;
517 picture p;
518 p=currentpicture;
519 currentpicture:=nullpicture;
520 draw fullcircle scaled 1cm xscaled 3 dashed p;
521 endfig;
522
523
524 beginfig(33);
525 for i=0 upto 2:
526 z[i]=(0,-40i); z[i+3]-z[i]=(100,30);
527 endfor
528 pickup pencircle scaled 18;
529 draw z0..z3 withcolor .8white;
530 linecap:=butt;
531 draw z1..z4 withcolor .8white;
532 linecap:=squared;
533 draw z2..z5 withcolor .8white;
534 dotlabels.top(0,1,2,3,4,5);
535 endfig; linecap:=rounded;
536
537
538 beginfig(34);
539 for i=0 upto 2:
540 z[i]=(0,-50i); z[i+3]-z[i]=(60,40);
541 z[i+6]-z[i]=(120,0);
542 endfor
543 pickup pencircle scaled 24;
544 draw z0--z3--z6 withcolor .8white;
545 linejoin:=mitered;
546 draw z1..z4--z7 withcolor .8white;
547 linejoin:=beveled;
548 draw z2..z5--z8 withcolor .8white;
549 dotlabels.bot(0,1,2,3,4,5,6,7,8);
550 endfig; linejoin:=rounded;
551
552
553 beginfig(35);
554 z2a=(0,0);
555 (-x1a,y1a) = -z3a = .5in*unitvector(6,1);
556 z1b - z1a = .75*z1a rotated -90;
557 z2b - z1b = whatever*(z2a-z1a);
558 z3b - z2b = whatever*(z3a-z2a);
559 y2b = 0;
560 z3b - z3a = whatever*(z3a rotated 90);
561 z0b-z1b = z0a-z1a = z1a;
562 x4a=x2a; x4b=x2b;
563 y4a = y4b = 1.3*y3b;
564 fill z1a--z2a--z3a--z3b--z2b--z1b--cycle withcolor .8 white;
565 for p= z2a--z4a, z2b--z4b, z0a--z1a, z0b--z1b:
566 draw p dashed evenly;
567 endfor
568 drawdblarrow z4a--z4b;
569 drawdblarrow z0a--z0b;
570 label.bot(btex miter length etex, .5[z4a,z4b]);
571 label.ulft(btex line width etex, .5[z0a,z0b]);
572 endfig;
573
574
575 beginfig(36);
576 z[-1]=(0,0); z0=(1in,0);
577 for i=1 upto 6:
578 z[i]-z[i-2] = (0,-15pt);
579 if x[i]=0: label.lft(decimal i, z[i]);
580 fi
581 endfor
582 drawarrow z1..z2;
583 drawarrow reverse(z3..z4);
584 drawdblarrow z5..z6;
585 label.rt(btex 2 \tt\ drawarrow z1..z2 etex, z2);
586 label.rt(btex 4 \tt\ drawarrow reverse(z3..z4) etex, z4);
587 label.rt(btex 6 \tt\ drawdblarrow z5..z6 etex, z6);
588 endfig;
589
590
591 beginfig(37);
592 path p, q, r;
593 ahlength := 1.5cm;
594 pickup pencircle scaled .2cm;
595 p = (0,0)..{right}(2.5cm,2cm);
596 q = counterclockwise arrowhead p;
597 z0 = directionpoint up of q;
598 z.a = directionpoint right of q;
599 z.b = directionpoint (-1,-1) of q;
600 drawarrow p withcolor .4white;
601 pickup defaultpen;
602 undraw p;
603 undraw q;
604 ahlength:=4bp;
605 z.a1-z0 = .3cm*unitvector(z.a-z0) rotated 90;
606 z.a1-z.a2 = z0-z.a;
607 z.b1-z0 = .3cm*unitvector(z.b-z0) rotated -90;
608 z.b1-z.b2 = z0-z.b;
609 z.ab = whatever[z.a1,z.a2] = whatever[z.b1,z.b2];
610 z.a0-z.ab = .4cm*unitvector(z.a1-z.a2);
611 z.b0-z.ab = .4cm*unitvector(z.b1-z.b2);
612 drawdblarrow z.a1..z.a2;
613 label.lrt(btex \tt ahlength etex, .9[z.a1,z.a2]);
614 draw z.a1..z.a0 dashed evenly;
615 drawdblarrow z.b1..z.b2;
616 label.urt(btex \tt ahlength etex, .9[z.b1,z.b2]);
617 draw z.b1..z.b0 dashed evenly;
618 r = z.a0{(z.a2-z.a0) rotated 90}..{(z.b2-z.b0)rotated 90}z.b0;
619 draw r;
620 label.rt(btex \tt ahangle etex, point .5 of r);
621 endfig;
622
623
624 beginfig(38);
625 pickup pencircle scaled .2in yscaled .08 rotated 30;
626 x0=x3=x4;
627 z1-z0 = .45in*dir 30;
628 z2-z3 = whatever*(z1-z0);
629 z6-z5 = whatever*(z1-z0);
630 z1-z6 = 1.2*(z3-z0);
631 rt x3 = lft x2;
632 x5 = .55[x4,x6];
633 y4 = y6;
634 lft x3 = bot y5 = 0;
635 top y2 = .9in;
636 draw z0--z1--z2--z3--z4--z5--z6 withcolor .7white;
637 dotlabels.top(0,1,2,3,4,5,6);
638 endfig;
639
640
641 beginfig(40);
642 path p[];
643 p1 = (0,0){curl 0}..(5pt,-3pt)..{curl 0}(10pt,0);
644 p2 = p1..(p1 yscaled-1 shifted(10pt,0));
645 p0 = p2;
646 for i=1 upto 3: p0:=p0.. p2 shifted (i*20pt,0);
647 endfor
648 for j=0 upto 8: draw p0 shifted (0,j*10pt);
649 endfor
650 p3 = fullcircle shifted (.5,.5) scaled 72pt;
651 clip currentpicture to p3;
652 draw p3;
653 endfig;
654
655
656 marksize=4pt;
657 angle_radius=8pt;
658
659 def draw_mark(expr p, a) =
660 begingroup
661 save t, dm; pair dm;
662 t = arctime a of p;
663 dm = marksize*unitvector direction t of p
664 rotated 90;
665 draw (-.5dm.. .5dm) shifted point t of p;
666 endgroup
667 enddef;
668
669 def draw_marked(expr p, n) =
670 begingroup
671 save amid;
672 amid = .5*arclength p;
673 for i=-(n-1)/2 upto (n-1)/2:
674 draw_mark(p, amid+.6marksize*i);
675 endfor
676 draw p;
677 endgroup
678 enddef;
679
680 def mark_angle(expr a, b, c, n) =
681 begingroup
682 save s, p; path p;
683 p = unitvector(a-b){(a-b)rotated 90}..unitvector(c-b);
684 s = .9marksize/length(point 1 of p - point 0 of p);
685 if s<angle_radius: s:=angle_radius; fi
686 draw_marked(p scaled s shifted b, n);
687 endgroup
688 enddef;
689
690 def mark_rt_angle(expr a, b, c) =
691 draw ((1,0)--(1,1)--(0,1))
692 zscaled (angle_radius*unitvector(a-b)) shifted b
693 enddef;
694
695 beginfig(42);
696 pair a,b,c,d;
697 b=(0,0); c=(1.5in,0); a=(0,.6in);
698 d-c = (a-b) rotated 25;
699 dotlabel.lft("a",a);
700 dotlabel.lft("b",b);
701 dotlabel.bot("c",c);
702 dotlabel.llft("d",d);
703 z0=.5[a,d];
704 z1=.5[b,c];
705 (z.p-z0) dotprod (d-a) = 0;
706 (z.p-z1) dotprod (c-b) = 0;
707 draw a--d;
708 draw b--c;
709 draw z0--z.p--z1;
710 draw_marked(a--b, 1);
711 draw_marked(c--d, 1);
712 draw_marked(a--z.p, 2);
713 draw_marked(d--z.p, 2);
714 draw_marked(b--z.p, 3);
715 draw_marked(c--z.p, 3);
716 mark_angle(z.p, b, a, 1);
717 mark_angle(z.p, c, d, 1);
718 mark_angle(z.p, c, b, 2);
719 mark_angle(c, b, z.p, 2);
720 mark_rt_angle(z.p, z0, a);
721 mark_rt_angle(z.p, z1, b);
722 endfig;
723
724
725 def getmid(suffix p) =
726 pair p.mid[], p.off[], p.dir[];
727 for i=0 upto 36:
728 p.dir[i] = dir(5*i);
729 p.mid[i]+p.off[i] = directionpoint p.dir[i] of p;
730 p.mid[i]-p.off[i] = directionpoint -p.dir[i] of p;
731 endfor
732 enddef;
733
734 def joinup(suffix pt, d)(expr n) =
735 begingroup
736 save res, g; path res;
737 res = pt[0]{d[0]};
738 for i=1 upto n:
739 g:= if (pt[i]-pt[i-1]) dotprod d[i] <0: - fi 1;
740 res := res{g*d[i-1]}...{g*d[i]}pt[i];
741 endfor
742 res
743 endgroup
744 enddef;
745
746 beginfig(45)
747 path p, q;
748 p = ((5,2)...(3,4)...(1,3)...(-2,-3)...(0,-5)...(3,-4)
749 ...(5,-3)...cycle) scaled .3cm shifted (0,5cm);
750 getmid(p);
751 draw p;
752 draw joinup(p.mid, p.dir, 36)..cycle;
753 q = joinup(p.off, p.dir, 36);
754 draw q..(q rotated 180)..cycle;
755 drawoptions(dashed evenly);
756 for i=0 upto 3:
757 draw p.mid[9i]-p.off[9i]..p.mid[9i]+p.off[9i];
758 draw -p.off[9i]..p.off[9i];
759 endfor
760 endfig;
761
762
763 beginfig(55)
764 picture wheel, car;
765 path body;
766 u := 5bp;
767 % Use a calligraphic pen.
768 pickup pencircle scaled .1u yscaled .6 rotated 30;
769 % Define a wheel object.
770 wheel := image(
771 draw fullcircle scaled 2u xscaled .8 rotated 30;
772 draw fullcircle scaled .1u xscaled .8 rotated 30
773 withpen currentpen scaled .5;
774 );
775 % Construct path for car body.
776 body := (3.2u,0){right}..(4.5u,1.5u){up}..(1.5u,2.5u){dir(-170)}
777 ..(1.5u,4.25u){up}...(0,5u){left};
778 body := body .. reverse body reflectedabout (origin, (0,u));
779 % Define a car object.
780 car := image(
781 draw wheel shifted (2u, 0);% Draw two wheels.
782 draw wheel shifted (-2u, 0);
783 draw (-.8u,0){dir(5)}..(.8u,0);% Draw connection betweeen wheels.
784 draw body;% Draw body.
785 % Draw speed indicators.
786 for i=1.5, 2, 2.5:
787 draw (5u, u*i){right}..{dir(-10)}(6.5u,u*i*.95);
788 endfor
789 ) shifted (0, u) slanted -.2 rotated 1;% Introduce asymmetries.
790 % Draw two cars and a faster one.
791 draw car shifted (5u,0);
792 draw car shifted (20u,0);
793 draw car slanted -.25 shifted (45u,0);
794 % Draw motorway.
795 draw (-5u,-u)...(25u,-.5u)...(60u,-u)
796 withpen currentpen scaled 4 withcolor .7white;
797 endfig;
798
799
800 fontmapfile "=lm-ec.map";
801 beginfig(56);
802 picture q;
803 path p;
804 interim ahlength := 12bp;
805 interim ahangle := 25;
806 q := glyph "Dcaron" of "ec-lmr10" scaled .2;
807 for item within q:
808 p := pathpart item;
809 drawarrow p withcolor (.6,.9,.6)
810 withpen pencircle scaled 1.5;
811 for j=0 upto length p:
812 pickup pencircle scaled .7;
813 draw (point j of p -- precontrol j of p)
814 dashed evenly withcolor blue;
815 draw (point j of p -- postcontrol j of p)
816 dashed evenly withcolor blue;
817 pickup pencircle scaled 3;
818 draw precontrol j of p withcolor red;
819 draw postcontrol j of p withcolor red;
820 pickup pencircle scaled 2;
821 draw point j of p withcolor black;
822 endfor
823 endfor
824 endfig;
825
826
827 %%% Title page rule.
828 beginfig(60);
829 pickup pencircle scaled 1.1bp;
830 linecap := rounded;
831 draw origin--(4.38in,0);
832 endfig;
833
834
835 beginfig(61);
836 def shape_with_cardinal_points(expr shape) =
837 image(
838 interim ahangle := 30;
839 interim ahlength := 6bp;
840 drawarrow shape withpen pencircle scaled .5;
841 for k = 0 upto length shape:
842 drawdot point k of shape withpen pencircle scaled dotlabeldiam;
843 endfor
844 )
845 enddef;
846
847 draw shape_with_cardinal_points(fullcircle scaled 1in);
848 draw shape_with_cardinal_points(unitsquare scaled 1in) withcolor .5white;
849 endfig;
850
851 end