Debian Codegraph @

texmf-dist/doc/latex/circuit-macros/examples/exp.m4

raw
1 .PS
2 # exp.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 # See the macro `PhadedPolygon' in libgen.m4
11
12 # Projected box object:
13 [
14 g = 1.2
15 define(`axlen',1.2*g)
16 define(`O3',`0,0,0')
17 define(`X0',`axlen,0,0')
18 define(`Y0',`0,axlen,0')
19 define(`Z0',`0,0,axlen')
20
21 # diagram viewing angle
22 dazim = 54
23 delev = 15
24 setview(dazim,delev)
25
26 # projection azimuth, elevation
27 pazim = 20*dtor_
28 pelev = 35*dtor_
29 arad = 0.6*g
30
31 # object displacement
32 define(`D3',`0.3*g,0.6*g,0.9*g')
33
34 # fixed coordinate frame
35 O: Project(O3)
36 X: Project(X0)
37 Y: Project(Y0)
38 Fector(X0,Z0) with .Origin at O ; "$x_0$" at X rjust
39 Fector(Y0,Z0) with .Origin at O ; "$y_0$" at Y ljust below
40 Fector(Z0,Y0) with .Origin at O ; "`$z_0$'" at Project(Z0) above
41
42 define(`R01',`rot3Dz(pazim,rot3Dy(-pelev,$1,$2,$3))')
43 define(`R10',`rot3Dy(pelev,rot3Dz(-pazim,$1,$2,$3))')
44
45 thinlines_ ; psset_(linecolor=gray)
46 line from O to Project(rot3Dz(pazim,axlen,0,0))
47 psset_(linecolor=black)
48 arc -> ccw from Project(arad,0,0) to Project(rot3Dz(pazim,arad,0,0)) rad arad
49 "$\theta$" below
50 up_
51 arc -> cw from Project(rot3Dz(pazim,arad,0,0)) \
52 to Project(R01(arad,0,0)) rad arad
53 "$\phi$" rjust at Project(rot3Dz(pazim,rot3Dy(-pelev/2,arad,0,0)))
54 arc -> from Project(0,arad,0) to Project(R01(0,arad,0)) rad arad
55 "$\theta$" above
56 right_
57 arc -> cw from Project(0,0,arad/2) to Project(R01(0,0,arad/2)) rad arad/2
58 "$\phi$" ljust at Here+(-1pt__,-3pt__)
59
60 Fector(R01(X0),R01(Z0)) with .Origin at O ;
61 "$x_1$" above rjust at Project(R01(X0))
62 Fector(R01(Y0),R01(Z0)) with .Origin at O ;
63 "$y_1$" ljust at Project(R01(Y0))
64 Fector(R01(Z0),R01(Y0)) with .Origin at O ;
65 "$z_1$" above at Project(R01(Z0))
66 thicklines_
67
68 # box object dimension
69 b = 0.6*g
70 d = 0.4*g
71 h = 0.20*g
72
73 # box object corners
74 define(`B0',`D3')
75 define(`B1',`sum3D(D3,d,0,0)') PB1: Project(B1)
76 define(`B2',`sum3D(D3,d,b,0)') PB2: Project(B2)
77 define(`B3',`sum3D(D3,0,b,0)') PB3: Project(B3)
78 define(`B4',`sum3D(D3,0,0,h)') PB4: Project(B4)
79 define(`B5',`sum3D(D3,d,0,h)') PB5: Project(B5)
80 define(`B6',`sum3D(D3,d,b,h)') PB6: Project(B6)
81 define(`B7',`sum3D(D3,0,b,h)') PB7: Project(B7)
82
83 # projected corners
84 P0:Project(R01(0,dcosine3D(2,R10(B0)),dcosine3D(3,R10(B0))))
85 P1:Project(R01(0,dcosine3D(2,R10(B1)),dcosine3D(3,R10(B1))))
86 P2:Project(R01(0,dcosine3D(2,R10(B2)),dcosine3D(3,R10(B2))))
87 P3:Project(R01(0,dcosine3D(2,R10(B3)),dcosine3D(3,R10(B3))))
88 P4:Project(R01(0,dcosine3D(2,R10(B4)),dcosine3D(3,R10(B4))))
89 P5:Project(R01(0,dcosine3D(2,R10(B5)),dcosine3D(3,R10(B5))))
90 P6:Project(R01(0,dcosine3D(2,R10(B6)),dcosine3D(3,R10(B6))))
91 P7:Project(R01(0,dcosine3D(2,R10(B7)),dcosine3D(3,R10(B7))))
92 thinlines_
93 line from PB1 to P1
94 line from PB2 to P2
95 line from PB7 to P7
96 line from PB4 to P4
97 thicklines_
98
99 # draw the object
100 ifdpic(`line invis fill_(1) from PB4 to PB7 to PB6 to PB5
101 line from PB4 to PB7; line to PB6; line to PB5 ; line to PB4
102 line invis fill_(0.5) from PB5 to PB6 to PB2 to PB1
103 line from PB5 to PB6; line to PB2; line to PB1 ; line to PB5
104 line invis fill_(0.85) from PB6 to PB7 to PB3 to PB2
105 line from PB6 to PB7; line to PB3; line to PB2 ; line to PB6',
106 `gshade(1,PB4,PB7,PB6,PB5,PB4,PB7)
107 gshade(0.5,PB5,PB6,PB2,PB1,PB5,PB6)
108 gshade(0.85,PB6,PB7,PB3,PB2,PB6,PB7)')
109 line from PB4 to PB5 to PB1 to PB2 to PB3 to PB7 to PB4
110 line from PB5 to PB6 to PB7
111 line from PB6 to PB2
112
113 arrow from O to PB1 chop linethick pt__; "$X$" rjust
114
115 line from P4 to P5 to P1 to P2 to P3 to P7 to P4
116 line from P5 to P6 to P7
117 line from P6 to P2
118 line dashed from P4 to P0 to P3
119 line dashed from P0 to P1
120 ]
121
122 # Globe:
123 [
124 # Set small text size
125 iflatex(`textoffset = 1bp__; ifpsfrag(`textht = 9.5bp__',
126 `latexcommand({\small)') ')
127
128 azimuth = 15 # View angles in degrees
129 elevation = 35
130 setview(azimuth,elevation)
131
132 rectwid = 3.5 # Basic dimensions
133 rectht = 2.4
134 alpha = rectht/3
135
136 # # Rectangle
137 NW: Project(-rectht/2,-rectwid*0.25,0)
138 SW: Project( rectht/2,-rectwid*0.25,0)
139 SE: Project( rectht/2, rectwid*0.75,0)
140 NE: Project(-rectht/2, rectwid*0.75,0)
141
142 ShadedPolygon(NW:NE:SE:SW,,-90,
143 0,0.25,0.25,0.25,
144 1,1,1,1) with .Start at NW
145
146 define(`C3D',`0,0,alpha') # Centre of the sphere
147 C: Project(C3D)
148
149 # # Shaded sphere using PSTricks or tikz:
150 # # this is black magic but PSTricks
151 # # seems to give more control
152 # ifpstricks(
153 # `Highlight: \
154 # Project(sum3D(C3D,rot3Dz(-15*dtor_,rot3Dy(-60*dtor_,alpha,0,0))))
155 # command "\pscustom[fillstyle=gradient,gradmidpoint=0.0,%"
156 # command sprintf("gradbegin=gray,gradend=white,gradlines=%g,%%",alpha*200)
157 # command "GradientCircle=true,GradientScale=1.5,%"
158 # command sprintf("GradientPos={(%g,%g)}]{",Highlight.x,Highlight.y)
159 # circle rad alpha at C
160 # command "}%"',
161 #
162 # `ifpgf( # A little too dark with tikz-pgf, maybe:
163 # `command sprintf(\
164 # "\dpicdraw[ball color=white](%g,%g) circle (%gin)\dpicstop",\
165 # C.x,C.y,alpha/2.54)',
166 #
167 # `circle rad alpha at C fill_(1) ')')
168
169 # Shaded sphere with pic shading:
170 shadedball(alpha) at C
171
172 S: 0,0 # The sphere bottom touch point
173 "$S$" at S+(0,-2pt__) rjust
174 "$\alpha$" at 0.5<S,C> ljust
175
176 define(`N3D',`0,0,2*alpha') # North pole
177 N: Project(N3D)
178 "$N$" at N+(0,3pt__) ljust
179
180 phi = 65*dtor_
181 define(`Phat3D',`rot3Dz(phi,alpha*3,0,0)')
182 Phat: "$\hat{P}$" at Project(Phat3D) 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; "$x$" below
199 invisline(Y)
200 arrow to Y chop 0.05 chop 0; "$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 ; "$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 "$\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: "$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 "$\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