Debian Codegraph @

texmf-dist/doc/latex/circuit-macros/examples/extras/Views.m4

raw
1 .PS
2 # Views.m4
3 threeD_init
4
5 sinclude(Lettering.m4def)
6 sinclude(../Lettering.m4def)
7 Letter_init
8
9 define(`textwidth',5.5)
10
11 `# Perspective transformations
12 # mult4( matrix, vector, vector )
13 define mult4 { for i=1 to 4 do {
14 $3[i] = 0
15 for j=1 to 4 do { $3[i] = $3[i] + $1[(j-1)*4+i]*$2[j] }}}
16 # eye4 make unit matrix
17 define eye4 { for i=1 to 4 do { for j=1 to 4 do { $1[(j-1)*4+i] = 0 }}}
18 # rotx4( theta, vector, vector )
19 define rotx4 { $3[1] = $2[1]
20 $3[2] = cos($1)*$2[2]-sin($1)*$2[3]
21 $3[3] = sin($1)*$2[2]+cos($1)*$2[3]
22 $3[4] = $2[4] }
23 # roty4( theta, vector, vector )
24 define roty4 { $3[1] = cos($1)*$2[1]-sin($1)*$2[3]
25 $3[2] = $2[2]
26 $3[3] = sin($1)*$2[1]+cos($1)*$2[3]
27 $3[4] = $2[4] }
28 # rotz4( theta, vector, vector )
29 define rotz4 { $3[1] = cos($1)*$2[1]-sin($1)*$2[2]
30 $3[2] = sin($1)*$2[1]+cos($1)*$2[2]
31 $3[3] = $2[3]
32 $3[4] = $2[4] }
33 # add4( vector, vector, vector )
34 define add4 {
35 if (($1[4]==0) && ($2[4]==0)) then {
36 for i=1 to 4 do { $3[i] = $1[i]+$2[i] } } \
37 else { if $1[4]==0 then { for i=1 to 4 do { $3[i] = $1[i] } } \
38 else { if $2[4]==0 then { for i=1 to 4 do { $3[i] = $2[i] } } \
39 else { for i=1 to 3 do { $3[i] = $1[i]/$1[4]+$2[i]/$2[4] }; $3[4] = 1 }
40 } } }
41
42 # vec4( x,y,z, vector )
43 define vec4 { $4[1] = $1; $4[2] = $2; $4[3] = $3; $4[4] = 1 }
44 # copy4( vector, vector )
45 define copy4 { $2[1] = $1[1]; $2[2] = $1[2]; $2[3] = $1[3]; $2[4] = $1[4] }
46 # pr4( vector, label ) # projected vector (see pr below)
47 define pr4 { if $1[4]==0 then { print "Divide by zero" } \
48 else { $2: pr($1[1]/$1[4],$1[2]/$1[4],$1[3]/$1[4]) }}
49
50 define print4 { print sprintf("%g,%g,%g,%g",$1[1],$1[2],$1[3],$1[4]) }
51 '
52 # Basic dimensions
53 u = 1*27/28.7*0.7 ifdef(`xsnotes',`*1.14')
54 a = 2*u
55 b = 1*u
56 c = 1.2*u
57 d = c*1/2
58 e = c/3
59 f = u*1/4
60 r = c/3
61
62 visibleth = 1.2
63 dimensionth = 0.4
64 hiddenth = dimensionth
65 linethick_(visibleth)
66
67 # Iso diagram viewing angle
68 dazim = 45
69 delev = -30
70 setview(dazim,delev)
71
72 define(`pr',`(project(`$3',`$1',`$2'))')
73 define(`xpnd',$1)
74
75 define(`X0', `0,0,0')
76 define(`X1', `0,b,0')
77 define(`X2', `a,b,0')
78 define(`X3', `a,0,0')
79 define(`X4', `0,0,c')
80 define(`X5', `0,b,c')
81 define(`X6', `a,b,c')
82 define(`X7', `a,0,c')
83 define(`X8', `-e,0,c/2-f/2')
84 define(`X9', `-e,d,c/2-f/2')
85 define(`X10',`0,d,c/2-f/2')
86 define(`X11',`0,0,c/2-f/2')
87 define(`X12',`-e,0,c/2+f/2')
88 define(`X13',`-e,d,c/2+f/2')
89 define(`X14',`0,d,c/2+f/2')
90 define(`X15',`0,0,c/2+f/2')
91 define(`X16',`0,b*1.25,c')
92 define(`X17',`a/4,b*1.25,c')
93 define(`X18',`a/4,b,c')
94 define(`X19',`0,b,c/2')
95 define(`X20',`a/4,b,c/2')
96 define(`xn',20)
97
98 define(`ncirc',18)
99 dt = 360/ncirc
100 tx = a*2/3; ty = b; tz = c/2
101 define(`TR',`tx,ty,tz')
102
103 define(`loopX',`ifelse(eval(`$1'>=0),1,
104 `define(`X'eval(`$1'+xn+1),`tx+r*cosd(`$1'*dt),ty,tz+r*sind(`$1'*dt)')
105 loopX(eval($1-1))')')
106
107 loopX(ncirc)
108
109 define(`loopTT',`ifelse(eval(`$1'>=0),1,
110 `TT[`$1']: ifelse(`$3',0,`pr(X$2)',`Y$2')
111 loopTT(eval(`$1'-1),eval(`$2'-1),`$3')')')
112
113 define(`drawobj',`
114 line from pr(xpnd(`$1'0)) to pr(xpnd(`$1'1)) to pr(xpnd(`$1'2))
115 line to pr(xpnd(`$1'3)) to pr(xpnd(`$1'0))
116 line from pr(xpnd(`$1'0)) to pr(xpnd(`$1'11)) to pr(xpnd(`$1'8)) \
117 to pr(xpnd(`$1'12)) to pr(xpnd(`$1'13))
118 line to pr(xpnd(`$1'9)) to pr(xpnd(`$1'8))
119 line from pr(xpnd(`$1'13)) to pr(xpnd(`$1'14)) to pr(xpnd(`$1'10))
120 line to pr(xpnd(`$1'9))
121 line from pr(xpnd(`$1'10)) to pr(xpnd(`$1'11))
122 ifelse(`$2',0,
123 `shade(0.92,line width 0 from pr(xpnd(`$1'1)) to pr(xpnd(`$1'5)) \
124 to pr(xpnd(`$1'6)) to pr(xpnd(`$1'2)) to pr(xpnd(`$1'1)))
125 perspective(X1,Z)
126 ellipse fill_(0.7) ht 2*r*tmx[2]/tmx[4]/b wid 2*r at pr(TR)
127 shade(1,line width 0 from pr(xpnd(`$1'19)) to pr(xpnd(`$1'16)) \
128 to pr(xpnd(`$1'17)) to pr(xpnd(`$1'20)) to pr(xpnd(`$1'19)))
129 shade(0.7,line width 0 from pr(xpnd(`$1'0)) to pr(xpnd(`$1'1)) \
130 to pr(xpnd(`$1'2)) to pr(xpnd(`$1'3)) to pr(xpnd(`$1'0)))
131 shade(0.6,line width 0 from pr(xpnd(`$1'0)) to pr(xpnd(`$1'1)) \
132 to pr(xpnd(`$1'19)) to pr(xpnd(`$1'16)) to pr(xpnd(`$1'4)) \
133 to pr(xpnd(`$1'0)))
134 shade(0.9,line width 0 from pr(xpnd(`$1'13)) to pr(xpnd(`$1'14)) \
135 to pr(xpnd(`$1'10)) to pr(xpnd(`$1'9)) to pr(xpnd(`$1'13)))
136 shade(0.7,line width 0 from pr(xpnd(`$1'8)) to pr(xpnd(`$1'9)) \
137 to pr(xpnd(`$1'10)) to pr(xpnd(`$1'11)) to pr(xpnd(`$1'8)))
138 shade(0.6,line width 0 from pr(xpnd(`$1'8)) to pr(xpnd(`$1'9)) \
139 to pr(xpnd(`$1'13)) to pr(xpnd(`$1'12)) to pr(xpnd(`$1'8)))
140 A: line invis from pr(xpnd(`$1'4)) to pr(xpnd(`$1'0))
141 B: line invis from pr(xpnd(`$1'12)) to pr(xpnd(`$1'13))
142 line from Intersect_(A,B) to pr(xpnd(`$1'4))
143 line from pr(xpnd(`$1'4)) to pr(xpnd(`$1'16))',
144
145 `A: line invis from pr(xpnd(`$1'4)) to pr(xpnd(`$1'16))
146 B: line invis from pr(xpnd(`$1'14)) to pr(xpnd(`$1'13))
147 line from Intersect_(A,B) to pr(xpnd(`$1'16))
148 line thick dimensionth from pr(xpnd(`$1'2)) to -0.5 between \
149 pr(xpnd(`$1'2)) and pr(xpnd(`$1'1)) chop 0.05
150 line thick dimensionth from pr(xpnd(`$1'3)) to -0.5 between \
151 pr(xpnd(`$1'3)) and pr(xpnd(`$1'0)) chop 0.05
152 line thick dimensionth from pr(xpnd(`$1'5)) to -1.0 between \
153 pr(xpnd(`$1'5)) and pr(xpnd(`$1'1)) chop 0.05
154 line thick dimensionth from pr(xpnd(`$1'4)) to -1.0 between \
155 pr(xpnd(`$1'4)) and pr(xpnd(`$1'0)) chop .1 chop 0.05
156 loopTT(ncirc,eval(xn+ncirc+1),`$2')
157 fitcurve(TT,ncirc)
158 ')
159 line from pr(xpnd(`$1'16)) to pr(xpnd(`$1'19)) \
160 to pr(xpnd(`$1'20)) to pr(xpnd(`$1'17)) to pr(xpnd(`$1'16))
161 line from pr(xpnd(`$1'19)) to pr(xpnd(`$1'1))
162 A: line invis from pr(xpnd(`$1'5)) to pr(xpnd(`$1'6))
163 B: line invis from pr(xpnd(`$1'17)) to pr(xpnd(`$1'20))
164 line from Intersect_(A,B) to pr(xpnd(`$1'6))
165 line from pr(xpnd(`$1'6)) to pr(xpnd(`$1'2))
166 ')
167
168 dp = 1.0*a
169 s4f = 1.6
170 fth = 180*dtor_
171
172 # perspective(x,y,z,position)
173 `define perspective {
174 vec4($3,$1,$2,tmp)
175 roty4(180*dtor_,tmp,tmx)
176 rotz4(90*dtor_,tmx,tmp)
177 rotx4(-90*dtor_,tmp,tmx)
178 roty4(-45*dtor_,tmx,tmp)
179 tmp[4] = tmp[3]/dp+tmp[4]
180 rotx4(55*dtor_,tmp,tmx)
181 $4: (tmx[1]/tmx[4],tmx[2]/tmx[4])
182 }
183 '
184 lu = 0.1/6 * 0.8
185
186 # Handle forward referencing of lettering guide line lengths
187 nguides = 0
188 sh "touch Views.dms"
189 for i=1 to 10 do { w[i] = 1 }
190 copy "Views.dms"
191 sh "rm -f Views.dms"
192
193 define(`guideletter',`[ nguides += 1
194 line thick grthick from (0,0) right w[nguides]*lu outlined "lightgridgray"
195 line thick grthick from (0,-6*lu) right w[nguides]*lu outlined "lightgridgray"
196 T: $1 with .nw at (0,0)
197 print sprintf("w[%g]=%g",nguides,T.wid/lu) >> "Views.dms"
198 ]')
199
200 define(`pfront',`(`$1',`$2')')
201 define(`ptop',`(`$1',`$3')')
202 define(`pside',`(-(`$3'),`$2')')
203 sep = 0.6*u
204 define(`centreline',`rpoint_(ifelse(`$1',,`to rvec_(linewid,0)',`$1'))
205 line thick dimensionth to rvec_(rp_len/2-.08,0)
206 move to rvec_(.03,0)
207 line thick dimensionth to rvec_(.1,0)
208 move to rvec_(.03,0)
209 line thick dimensionth to rvec_(rp_len/2-.08,0)')
210
211 Orthographics: [
212 Top: [
213 line from ptop(X1) to ptop(X5) to ptop(X6) to ptop(X2) to ptop(X1)
214 line from ptop(X17) to ptop(X20) to ptop(X19)
215 line from ptop(X10) to ptop(X9) to ptop(X13) to ptop(X14)
216 circle rad r at ptop(TR)
217 centreline(from ptop(TR)+(0,r) down 2*r chop -.1)
218 centreline(from ptop(TR)+(-r,0) right 2*r chop -.1)
219 W: ptop(X9)
220 E: ptop(X2)
221 ]
222 Front: [
223 line from pfront(X0) to pfront(X1) to pfront(X2) to pfront(X3) to pfront(X0)
224 line from pfront(X0) to pfront(X8) to pfront(X9) to pfront(X10)
225 line from pfront(X19) to pfront(X16) to pfront(X17) to pfront(X20)
226 line thick hiddenth dashed from pfront(TR)+(-r,0) down b
227 line thick hiddenth dashed from pfront(TR)+( r,0) down b
228 centreline(from pfront(TR) down b chop -.1)
229 W: pfront(X9)
230 E: pfront(X2)
231 N: pfront(X16)
232 S: pfront(X8)
233 ] with .nw at Top.sw+(0,-sep)
234
235 Side: [
236 line from pside(X0) to pside(X4) to pside(X16) to pside(X19) to pside(X1) \
237 to pside(X0) to pside(X4)
238 line from pside(X12) to pside(X13) to pside(X9) to pside(X8)
239 line thick hiddenth dashed from pside(X5) to pside(X19)
240 line thick hiddenth dashed from pside(TR)+(-r,0) down b
241 line thick hiddenth dashed from pside(TR)+( r,0) down b
242 centreline(from pside(TR) down b chop -.1)
243 N: pside(X16)
244 S: pside(X0)
245 ] with .ne at Front.nw+(-sep,0)
246
247 if 1 then {
248 linethick_(0.8)
249 guideletter([Letters(`F R O N T8V I5E1W')]) with .n at Front.s+(0,-.05)
250 guideletter([Letters(`S4I5D4E8V I5E1W')]) with .n at Side.s+(0,-.05)
251 guideletter([Letters(`T O4P8V I5E1W')]) with .n at Top.s+(0,-.10)
252 linethick_(visibleth)
253 }
254
255 line thick dimensionth from Side.N to Front.N chop 0.05
256 line thick dimensionth from Side.S to Front.S chop 0.05
257 line thick dimensionth from Top.W to Front.W chop 0.05
258 line thick dimensionth from Top.E to Front.E chop 0.05
259
260 ] # End Orthographics
261
262 define(`looppersp',`ifelse(eval(`$1'>=0),1,`perspective(xpnd(X`$1'),Z`$1')
263 Y`$1': (cos(fth)*Z`$1'.x-sin(fth)*Z`$1'.y,\
264 sin(fth)*Z`$1'.x+cos(fth)*Z`$1'.y)*s4f
265 looppersp(eval($1-1))')')
266
267 if 1 then {
268 Perspective: [
269 pushdef(`pr',`$1')
270 right_
271 looppersp(eval(xn+ncirc+1))
272 drawobj(Y,1)
273 popdef(`pr')
274 # ] with .sw at Isometric.ne+(-3.5*sep,0)
275 ] with .se at Orthographics.sw+(-1.5*sep,0)
276
277 linethick_(0.8)
278 guideletter([[Letters(T2W O)]; move right lu; line right 4*lu; move right lu
279 [Letters(P O4I5N T8P E R S P E C T I V E)]])\
280 with .w at Perspective.s+(.2*u,0)
281 linethick_(visibleth)
282 }
283
284 if 1 then {
285 # Pictorials:
286 Isometric: [
287 drawobj(X,0)
288 # command "{\small"
289 # define(`loopprt',`ifelse(eval(`$1'>=0),1,`"`$1'" at pr(X$1)
290 # loopprt(eval($1-1))')')
291 # loopprt(xn)
292 # for i=0 to ncirc do { sprintf("%g",i) at TT[i] }
293 # command "}%"
294 #] with .sw at (Orthographics.e+(-textwidth,0),Orthographics.Side.sw+(0,0.1))
295 #] at Orthographics.nw
296 ] with .s at Perspective.n+(0,0.2)
297
298 linethick_(0.8)
299 guideletter([Letters(`S4H2A2D E D8I S O M5E2T2R5I C8V I5E1W')])\
300 with .w at Isometric.s+(.2*u,0) #(0,-.2)
301 linethick_(visibleth)
302 }
303
304 .PE