Debian Codegraph @

texmf-dist/doc/latex/circuit-macros/examples/dpv/expDPV.m4

raw
1 .PS
2 # expDPV.m4
3 threeD_init
4 NeedDpicTools
5
6 # Graduated shading is probably best done using the built-in functions
7 # of PSTricks or the somewhat equivalent tikz capabilities. Other
8 # postprocessors do not have the same functionality so the following
9 # demonstrates how it can be done in the pic language with m4 macros.
10
11 # Projected box object:
12 [
13 g = 1.2
14 define(`axlen',1.2*g)
15 define(`O3',`0,0,0')
16 define(`X0',`axlen,0,0')
17 define(`Y0',`0,axlen,0')
18 define(`Z0',`0,0,axlen')
19
20 # diagram viewing angle
21 dazim = 54
22 delev = 15
23 setview(dazim,delev)
24
25 # projection azimuth, elevation
26 pazim = 20*dtor_
27 pelev = 35*dtor_
28 arad = 0.6*g
29
30 # object displacement
31 define(`D3',`0.3*g,0.6*g,0.9*g')
32
33 # fixed coordinate frame
34 O: Project(O3)
35 X: Project(X0)
36 Y: Project(Y0)
37 Fector(X0,Z0) with .Origin at O ; "svg_it(x`'svg_sub(0))" at X rjust
38 Fector(Y0,Z0) with .Origin at O ; "svg_it(y`'svg_sub(0))" at Y ljust below
39 Fector(Z0,Y0) with .Origin at O ; "svg_it(z`'svg_sub(0))" at Project(Z0) above
40
41 define(`R01',`rot3Dz(pazim,rot3Dy(-pelev,$1,$2,$3))')
42 define(`R10',`rot3Dy(pelev,rot3Dz(-pazim,$1,$2,$3))')
43
44 thinlines_ ; psset_(linecolor=gray)
45 line from O to Project(rot3Dz(pazim,axlen,0,0))
46 psset_(linecolor=black)
47 arc -> ccw from Project(arad,0,0) to Project(rot3Dz(pazim,arad,0,0)) rad arad
48 "svg_theta" below
49 up_
50 arc -> cw from Project(rot3Dz(pazim,arad,0,0)) \
51 to Project(R01(arad,0,0)) rad arad
52 "svg_phi" rjust at Project(rot3Dz(pazim,rot3Dy(-pelev/2,arad,0,0)))
53 arc -> from Project(0,arad,0) to Project(R01(0,arad,0)) rad arad
54 "svg_theta" above
55 right_
56 arc -> cw from Project(0,0,arad/2) to Project(R01(0,0,arad/2)) rad arad/2
57 "svg_phi" ljust at Here+(-1pt__,-3pt__)
58
59 Fector(R01(X0),R01(Z0)) with .Origin at O ;
60 "svg_it(x`'svg_sub(1))" above rjust at Project(R01(X0))
61 Fector(R01(Y0),R01(Z0)) with .Origin at O ;
62 "svg_it(y`'svg_sub(1))" ljust at Project(R01(Y0))
63 Fector(R01(Z0),R01(Y0)) with .Origin at O ;
64 "svg_it(z`'svg_sub(1))" above at Project(R01(Z0))
65 thicklines_
66
67 # box object dimension
68 b = 0.6*g
69 d = 0.4*g
70 h = 0.20*g
71
72 # box object corners
73 define(`B0',`D3')
74 define(`B1',`sum3D(D3,d,0,0)') PB1: Project(B1)
75 define(`B2',`sum3D(D3,d,b,0)') PB2: Project(B2)
76 define(`B3',`sum3D(D3,0,b,0)') PB3: Project(B3)
77 define(`B4',`sum3D(D3,0,0,h)') PB4: Project(B4)
78 define(`B5',`sum3D(D3,d,0,h)') PB5: Project(B5)
79 define(`B6',`sum3D(D3,d,b,h)') PB6: Project(B6)
80 define(`B7',`sum3D(D3,0,b,h)') PB7: Project(B7)
81
82 # projected corners
83 P0:Project(R01(0,dcosine3D(2,R10(B0)),dcosine3D(3,R10(B0))))
84 P1:Project(R01(0,dcosine3D(2,R10(B1)),dcosine3D(3,R10(B1))))
85 P2:Project(R01(0,dcosine3D(2,R10(B2)),dcosine3D(3,R10(B2))))
86 P3:Project(R01(0,dcosine3D(2,R10(B3)),dcosine3D(3,R10(B3))))
87 P4:Project(R01(0,dcosine3D(2,R10(B4)),dcosine3D(3,R10(B4))))
88 P5:Project(R01(0,dcosine3D(2,R10(B5)),dcosine3D(3,R10(B5))))
89 P6:Project(R01(0,dcosine3D(2,R10(B6)),dcosine3D(3,R10(B6))))
90 P7:Project(R01(0,dcosine3D(2,R10(B7)),dcosine3D(3,R10(B7))))
91 thinlines_
92 line from PB1 to P1
93 line from PB2 to P2
94 line from PB7 to P7
95 line from PB4 to P4
96 thicklines_
97
98 # draw the object
99 ifdpic(`line invis fill_(1) from PB4 to PB7 to PB6 to PB5
100 line from PB4 to PB7; line to PB6; line to PB5 ; line to PB4
101 line invis fill_(0.5) from PB5 to PB6 to PB2 to PB1
102 line from PB5 to PB6; line to PB2; line to PB1 ; line to PB5
103 line invis fill_(0.85) from PB6 to PB7 to PB3 to PB2
104 line from PB6 to PB7; line to PB3; line to PB2 ; line to PB6',
105 `gshade(1,PB4,PB7,PB6,PB5,PB4,PB7)
106 gshade(0.5,PB5,PB6,PB2,PB1,PB5,PB6)
107 gshade(0.85,PB6,PB7,PB3,PB2,PB6,PB7)')
108 line from PB4 to PB5 to PB1 to PB2 to PB3 to PB7 to PB4
109 line from PB5 to PB6 to PB7
110 line from PB6 to PB2
111
112 arrow from O to PB1 chop linethick pt__; "svg_it(X)" rjust
113
114 line from P4 to P5 to P1 to P2 to P3 to P7 to P4
115 line from P5 to P6 to P7
116 line from P6 to P2
117 line dashed from P4 to P0 to P3
118 line dashed from P0 to P1
119 ]
120
121 # Globe:
122 [
123 # Set small text size
124 iflatex(`textoffset = 1bp__; ifpsfrag(`textht = 9.5bp__',
125 `latexcommand({\small)') ')
126
127 azimuth = 15 # View angles in degrees
128 elevation = 35
129 setview(azimuth,elevation)
130
131 rectwid = 3.5 # Basic dimensions
132 rectht = 2.4
133 alpha = rectht/3
134
135 # # Rectangle
136 NW: Project(-rectht/2,-rectwid*0.25,0)
137 SW: Project( rectht/2,-rectwid*0.25,0)
138 SE: Project( rectht/2, rectwid*0.75,0)
139 NE: Project(-rectht/2, rectwid*0.75,0)
140
141 ShadedPolygon(NW:NE:SE:SW,,-90,
142 0,0.25,0.25,0.25,
143 1,1,1,1) with .Start at NW
144
145 define(`C3D',`0,0,alpha') # Centre of the sphere
146 C: Project(C3D)
147
148 # # Shaded sphere using PSTricks or tikz:
149 # # this is black magic but PSTricks
150 # # seems to give more control
151 # ifpstricks(
152 # `Highlight: \
153 # Project(sum3D(C3D,rot3Dz(-15*dtor_,rot3Dy(-60*dtor_,alpha,0,0))))
154 # command "\pscustom[fillstyle=gradient,gradmidpoint=0.0,%"
155 # command sprintf("gradbegin=gray,gradend=white,gradlines=%g,%%",alpha*200)
156 # command "GradientCircle=true,GradientScale=1.5,%"
157 # command sprintf("GradientPos={(%g,%g)}]{",Highlight.x,Highlight.y)
158 # circle rad alpha at C
159 # command "}%"',
160 #
161 # `ifpgf( # A little too dark with tikz-pgf, maybe:
162 # `command sprintf(\
163 # "\dpicdraw[ball color=white](%g,%g) circle (%gin)\dpicstop",\
164 # C.x,C.y,alpha/2.54)',
165 #
166 # `circle rad alpha at C fill_(1) ')')
167
168 # Shaded sphere with pic shading:
169 shadedball(alpha) at C
170
171 S: 0,0 # The sphere bottom touch point
172 "svg_it(S)" at S+(0,-2pt__) rjust
173 "svg_alpha" at 0.5<S,C> ljust
174
175 define(`N3D',`0,0,2*alpha') # North pole
176 N: Project(N3D)
177 "svg_it(N)" at N+(0,3pt__) ljust
178
179 phi = 65*dtor_
180 define(`Phat3D',`rot3Dz(phi,alpha*3,0,0)')
181 Phat: "svg_it(P)" at Project(Phat3D) ljust
182 "svg_symbol(&`#'94;)" at last "".n ljust
183
184 X: Project(rectht/2*0.8,0,0)
185 Y: Project(0,rectwid/2*0.8,0)
186
187 `define' linevis { # ratio # Visibility function for lines fom S to Tmp
188 Tlv: $1 between S and Tmp
189 $2 = distance(Tlv,C)-alpha }
190
191 `define' invisline { # name # Draw dashed invisible part of line in
192 Tmp: $1 # the plane
193 findroot(linevis, 0, 1, 1e-8, x)
194 line dashed from S to x between S and Tmp chop 0 chop 0.05 }
195
196 thinlines_ # axes
197 invisline(X)
198 arrow to X chop 0.05 chop 0; "svg_it(x)" below
199 invisline(Y)
200 arrow to Y chop 0.05 chop 0; "svg_it(y)" ljust
201 line dashed from S to N chop 0 chop 0.05
202 arrow up alpha*0.5 chop 0.05 chop 0 ; "svg_it(z)" above
203 invisline(Phat)
204 line to Phat chop 0.05 chop 0
205 arc ccw -> rad alpha from Project(alpha/2,0,0) to \
206 Project(rot3Dz(phi,alpha/2,0,0))
207 "svg_phi" below at 0.5 between last arc.start and last arc.end
208
209 # vector (ratio along (N to Phat))
210 define(`ray',`sum3D(N3D,sprod3D($1,diff3D(Phat3D,N3D)))')
211 `define' rayvis { # ratio
212 $2 = length3D(diff3D(ray($1),C3D))-alpha }
213
214 findroot(rayvis, 1e-3, 1, 1e-8, p) # Find P
215 P: "svg_it(P)" at Project(ray(p)) ljust above
216
217 thicklines_
218 line dashed from N to P chop 0 chop 0.05
219 line to Phat chop 0.05 chop 0
220
221 define(`meridian',`rot3Dz(phi,rot3Dy(-($1),alpha,0,0))')
222 `define' meridianvis { # angle # Visibility function on the meridian
223 $2 = dot3D(meridian($1),View3D) }
224
225 thinlines_ # Draw the meridian
226 findroot(meridianvis, 0, pi_, 1e-8, y)
227 n = 0
228 for ang = y-pi_ to y by pi_/20 do {
229 Q[n]: Project(sum3D(C3D,meridian(ang))); n+=1 }
230 fitcurve(Q,n-1)
231 n = 0
232 for ang = y to y+pi_ by pi_/20 do {
233 Q[n]: Project(sum3D(C3D,meridian(ang))); n+=1 }
234 fitcurve(Q,n-1,dashed)
235
236 define(`equator',`rot3Dz($1,alpha,0,0)')
237 `define' equatorvis { # angle # Visibility function on the equator
238 $2 = dot3D(View3D,equator($1)) }
239
240 findroot(equatorvis, 0, pi_, 1e-8, y)
241 n = 0
242 for ang = y-pi_ to y by pi_/20 do {
243 Q[n]: Project(sum3D(C3D,equator(ang))); n+=1 }
244 fitcurve(Q,n-1)
245 n = 0
246 for ang = y to y+pi_ by pi_/20 do {
247 Q[n]: Project(sum3D(C3D,equator(ang))); n+=1 }
248 fitcurve(Q,n-1,dashed)
249
250 line dashed from C to P # beta
251 line dashed from C to Project(sum3D(C3D,equator(phi)))
252 arc ccw -> from 0.6 along_(last line) to 0.6 between C and P
253 "svg_beta" ljust at last arc.e+(0,2pt__)
254
255 iflatex(ifpsfrag(,`latexcommand(})'))
256 ] with .w at last [].e+(0.5,0)
257
258 .PE