Debian Codegraph @

texmf-dist/doc/metapost/featpost/example/deperspective.mp

raw
1 % deperspective.mp
2 % L. Nobre G.
3 % 2006
4
5 input featpost3Dplus2D;
6
7 defaultscale := 1.5;
8
9 verbatimtex \documentclass{article}\begin{document} etex
10
11 numeric cont, cmax;
12 cmax = 4;
13 color focus[];
14 focus1 = (5, 3.5,1);
15 focus2 = 0.4*(5, 3.5,3);
16 focus3 = 0.4*(5, 1.5,1.5);
17 focus4 = 0.4*(2.5,5, 1.5);
18 for cont= 1 upto cmax:
19 f := focus[cont];
20 beginfig(cont);
21 numeric gridnum, axesmarg, xlen, ylen;
22 gridnum = 15;
23 axesmarg = 0.5;
24 xlen = 1.0;
25 ylen = 1.5;
26 cartaxes(xlen+axesmarg,ylen+axesmarg,1);
27 color va, vb, vc, vd;
28
29 va = ( 0, 0,0);
30 vb = ( 0,ylen,0);
31 vc = (xlen,ylen,0);
32 vd = (xlen, 0,0);
33
34 z3 = rp(va);
35 z4 = rp(vb);
36 z5 = rp(vc);
37 z6 = rp(vd);
38
39 draw z3--z4--z5--z6--cycle dashed evenly;
40 z1 = whatever[z3,z4];
41 z1 = whatever[z6,z5];
42 z2 = whatever[z6,z3];
43 z2 = whatever[z5,z4];
44 draw z1--z3 dashed evenly;
45 draw z1--z6 dashed evenly;
46 draw z2--z3 dashed evenly;
47 draw z2--z4 dashed evenly;
48
49 numeric aonei, atwoi, bonei, btwoi, conei, ctwoi, donei, dtwoi;
50 aonei = 1/abs(z3-z1);
51 atwoi = 1/abs(z3-z2);
52 bonei = 1/abs(z4-z1);
53 btwoi = 1/abs(z4-z2);
54 conei = 1/abs(z5-z1);
55 ctwoi = 1/abs(z5-z2);
56 donei = 1/abs(z6-z1);
57 dtwoi = 1/abs(z6-z2);
58
59 numeric aone, atwo, bone, btwo, cone, ctwo, done, dtwo;
60 aone = abs(z3-z1);
61 atwo = abs(z3-z2);
62 bone = abs(z4-z1);
63 btwo = abs(z4-z2);
64 cone = abs(z5-z1);
65 ctwo = abs(z5-z2);
66 done = abs(z6-z1);
67 dtwo = abs(z6-z2);
68
69 numeric i, wei, aux, good;
70 for i=0 upto gridnum-1:
71 wei := (0.5+i)/gridnum;
72 draw z1--rp(wei[vb,vc]) withcolor red;
73 draw z2--rp(wei[vd,vc]) withcolor red;
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% The following lines
75 %%%%%%%%%%%%%%%%%%%%%% show how rounding error can destroy accuracy!
76 % aux := dtwoi/((1-wei)*atwoi+wei*dtwoi);
77 % good := dtwoi/(atwoi+wei*(dtwoi-atwoi));
78 % show (aux,good);
79 % draw z1--(good[z2,z6]);
80 % draw z2--((bonei/((1-wei)*aonei+wei*bonei))[z1,z4]);
81 draw z1--((1/((1-wei)*abs(z6-z2)/abs(z3-z2)+wei))[z2,z6]) withcolor blue;
82 draw z2--((1/((1-wei)*abs(z4-z1)/abs(z3-z1)+wei))[z1,z4]) withcolor blue;
83 endfor;
84 labels.top(1,2,3,4,5,6);
85 show ((atwo/dtwo)*(ctwo/btwo),(aone/bone)*(cone/done));
86 %show ylen/xlen-(bonei-aonei)/(dtwoi-atwoi);
87 %show (abs(z2-z6)/abs(z1-z4))*(abs(z1-z4)-abs(z1-z3))/(abs(z2-z6)-abs(z2-z3));
88 %show sqrt(abs(z3-z4))*sqrt(abs(z5-z6))/(sqrt(abs(z6-z3))*sqrt(abs(z5-z4)));
89 endfig;
90 endfor;
91
92 verbatimtex \end{document} etex
93
94 end;