Debian Codegraph @

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

raw
1 % thethreekindsofperspec.mp
2 % L. Nobre G.
3 % 2003
4
5 input featpost3Dplus2D;
6
7 % bash: export TEX=latex
8 % tcsh: setenv TEX latex
9
10 f := (4,2,2.5);
11 Spread := 45;
12
13 verbatimtex
14 \documentclass{article}
15 \usepackage{beton,concmath,ccfonts}
16 \begin{document}
17 etex
18
19 color psdf, psdu, psdv, rll, rlr, rur, rul, pll, plr, pur, pul;
20 color pc;
21 numeric projecplanesize, sizefraction, positfraction, aspectratio, rectsize;
22 pen realpen, lightpen, projpen, dotpen;
23 path projecplanepath, realpath;
24 psdf = 3.1*(0,1,0.37);
25 projecplanesize = 1.7;
26 sizefraction = 0.19;
27 positfraction = 0.65;
28 aspectratio = 1.0;
29 rectsize = 0.15;
30 realpen = pencircle scaled 2.6pt;
31 lightpen = pencircle scaled 0.55pt;
32 projpen = pencircle scaled 1.8pt;
33 dotpen = pencircle scaled 3.8pt;
34 psdv = N( (-Y(psdf), X(psdf), 0) );
35 psdu = ncrossprod( psdf, psdv );
36 pll = projecplanesize*(-aspectratio*psdv-psdu);
37 plr = projecplanesize*(+aspectratio*psdv-psdu);
38 pur = projecplanesize*(+aspectratio*psdv+psdu);
39 pul = projecplanesize*(-aspectratio*psdv+psdu);
40 projecplanepath = rp(pll)--rp(plr)--rp(pur)--rp(pul)--cycle;
41 pc = positfraction*psdf;
42 rll = pc+sizefraction*projecplanesize*(-psdv-psdu);
43 rlr = pc+sizefraction*projecplanesize*(+psdv-psdu);
44 rur = pc+sizefraction*projecplanesize*(+psdv+psdu);
45 rul = pc+sizefraction*projecplanesize*(-psdv+psdu);
46 realpath = rp(rll)--rp(rlr)--rp(rur)--rp(rul)--cycle;
47
48 beginfig(1);
49 draw projecplanepath withpen realpen;
50 draw realpath withpen realpen;
51 draw rp(psdf) withpen lightpen;
52 drawoptions( withpen lightpen );
53 squareangline( psdf, psdv, black, rectsize );
54 squareangline( psdf, psdu, black, rectsize );
55 drawoptions();
56 pair prll, prlr, prur, prul;
57 prll = rp(rll-pc);
58 prlr = rp(rlr-pc);
59 prur = rp(rur-pc);
60 prul = rp(rul-pc);
61 path projpath;
62 projpath = prll--prlr--prur--prul--cycle;
63 draw projpath withpen projpen;
64 draw prll--rp(rll+(1-positfraction)*psdf) withpen lightpen;
65 draw prlr--rp(rlr+(1-positfraction)*psdf) withpen lightpen;
66 draw prur--rp(rur+(1-positfraction)*psdf) withpen lightpen;
67 draw prul--rp(rul+(1-positfraction)*psdf) withpen lightpen;
68 draw rp(black)--rp(psdf) withpen lightpen;
69 draw rp(black) withpen dotpen;
70 draw rp(psdf) withpen dotpen;
71 label.rt( btex f etex, rp(psdf) );
72 % label.bot( btex viewcentr etex, rp(black) );
73 endfig;
74
75 beginfig(2);
76 draw projecplanepath withpen realpen;
77 draw realpath withpen realpen;
78 draw rp(psdf) withpen lightpen;
79 drawoptions( withpen lightpen );
80 squareangline( psdf, psdv, black, rectsize );
81 squareangline( psdf, psdu, black, rectsize );
82 drawoptions();
83 pair prll, prlr, prur, prul;
84 LightSource:=psdf;
85 prll = rp(projectpoint(black,rll));
86 prlr = rp(projectpoint(black,rlr));
87 prur = rp(projectpoint(black,rur));
88 prul = rp(projectpoint(black,rul));
89 path projpath;
90 projpath = prll--prlr--prur--prul--cycle;
91 draw projpath withpen projpen;
92 draw prll--rp(psdf) withpen lightpen;
93 draw prlr--rp(psdf) withpen lightpen;
94 draw prur--rp(psdf) withpen lightpen;
95 draw prul--rp(psdf) withpen lightpen;
96 draw rp(black)--rp(psdf) withpen lightpen;
97 draw rp(black) withpen dotpen;
98 draw rp(psdf) withpen dotpen;
99 label.rt( btex f etex, rp(psdf) );
100 label.bot( btex viewcentr etex, rp(black) );
101 endfig;
102
103 beginfig(3);
104 draw projecplanepath withpen realpen;
105 draw realpath withpen realpen;
106 draw rp(psdf) withpen lightpen;
107 drawoptions( withpen lightpen );
108 squareangline( psdf, psdv, black, rectsize );
109 squareangline( psdf, psdu, black, rectsize );
110 numeric dist;
111 dist = conorm( psdf );
112 color ml, mt, mr, mb;
113 mb = 0.5[rll,rlr];
114 ml = 0.5[rll,rul];
115 mr = 0.5[rur,rlr];
116 mt = 0.5[rur,rul];
117 drawoptions( withpen projpen );
118 angline( rll, mb, psdf, dist, "", top );
119 angline( rll, ml, psdf, dist, "", top );
120 angline( rur, mt, psdf, dist, "", top );
121 angline( rur, mr, psdf, dist, "", top );
122 angline( mb, rlr, psdf, dist, "", top );
123 angline( ml, rul, psdf, dist, "", top );
124 angline( mr, rlr, psdf, dist, "", top );
125 angline( mt, rul, psdf, dist, "", top );
126 angline( black, mb, psdf, dist, "", top );
127 angline( black, ml, psdf, dist, "", top );
128 angline( black, mr, psdf, dist, "", top );
129 angline( black, mt, psdf, dist, "", top );
130 drawoptions();
131 numeric marc, darc, dmarc, ddarc;
132 marc = 0.01745*getangle(-psdf,mt-psdf)*dist;
133 darc = 0.01745*getangle(-psdf,rll-psdf)*dist*0.707;
134 color pro[], esf[], proc[], esfc[];
135 pro1 = darc*(-psdv-psdu);
136 pro2 = marc*(-psdu);
137 pro3 = darc*(+psdv-psdu);
138 pro4 = marc*(+psdv);
139 pro5 = darc*(+psdv+psdu);
140 pro6 = marc*(+psdu);
141 pro7 = darc*(-psdv+psdu);
142 pro8 = marc*(-psdv);
143 esf1 = psdf+dist*N(rll-psdf);
144 esf2 = psdf+dist*N(mb-psdf);
145 esf3 = psdf+dist*N(rlr-psdf);
146 esf4 = psdf+dist*N(mr-psdf);
147 esf5 = psdf+dist*N(rur-psdf);
148 esf6 = psdf+dist*N(mt-psdf);
149 esf7 = psdf+dist*N(rul-psdf);
150 esf8 = psdf+dist*N(ml-psdf);
151 ddarc = conorm(pro1-esf1)/3;
152 dmarc = conorm(pro2-esf2)/3;
153 proc1 = pro1+ddarc*N(psdf);
154 proc2 = pro2+dmarc*N(psdf);
155 proc3 = pro3+ddarc*N(psdf);
156 proc4 = pro4+dmarc*N(psdf);
157 proc5 = pro5+ddarc*N(psdf);
158 proc6 = pro6+dmarc*N(psdf);
159 proc7 = pro7+ddarc*N(psdf);
160 proc8 = pro8+dmarc*N(psdf);
161 esfc1 = esf1+ddarc*N(rll-psdf);
162 esfc2 = esf2+dmarc*N(mb-psdf);
163 esfc3 = esf3+ddarc*N(rlr-psdf);
164 esfc4 = esf4+dmarc*N(mr-psdf);
165 esfc5 = esf5+ddarc*N(rur-psdf);
166 esfc6 = esf6+dmarc*N(mt-psdf);
167 esfc7 = esf7+ddarc*N(rul-psdf);
168 esfc8 = esf8+dmarc*N(ml-psdf);
169 numeric i;
170 drawoptions( withpen lightpen );
171 for i=1 upto 8:
172 draw rp(esf[i])..controls rp(esfc[i]) and rp(proc[i])..rp(pro[i]);
173 draw rp(psdf)--rp(esf[i]);
174 endfor;
175 draw rp(pro2)--rp(pro6);
176 draw rp(pro4)--rp(pro8);
177 draw rp(mb)--rp(mt);
178 draw rp(ml)--rp(mr);
179 drawoptions( withpen projpen );
180 draw rp(pro1)...rp(pro2)..rp(pro3);
181 draw rp(pro3)...rp(pro4)..rp(pro5);
182 draw rp(pro5)...rp(pro6)..rp(pro7);
183 draw rp(pro7)...rp(pro8)..rp(pro1);
184 draw rp(black)--rp(psdf) withpen lightpen;
185 draw rp(black) withpen dotpen;
186 draw rp(psdf) withpen dotpen;
187 label.rt( btex f etex, rp(psdf) );
188 % label.ulft( btex viewcentr etex, rp(black) );
189 endfig;
190
191 verbatimtex
192 \end{document}
193 etex
194
195 end;