Debian Codegraph @

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

raw
1 .PS
2 # graysurfDPV.m4
3 threeD_init
4 NeedDpicTools
5
6 Overall: [
7 []
8 Surface:[
9 # This just draws the facets back to front
10
11 setview(20,30)
12 dimen = 1.5
13
14 xmax = 2*dimen
15 ymax = 1.5*dimen
16 zmax = 1*dimen
17
18 define(`fn',
19 `expe(-(`$1')/tt)*cos((`$2')/xmax*1.75*twopi_)*cos((`$1')/ymax*twopi_)')
20
21 nx = 24; dx = xmax/nx
22 ny = 30; dy = ymax/ny
23 tt = 1.5
24 fnmax = fn(0,0,0)
25
26 Orig: (0,0)
27 linethick_(1.2)
28 arrow from Orig to 1.2 <Orig,Project(xmax,0,0)> ; "svg_it(x)" wid 0.08 below
29 arrow from Orig to 1.2 <Orig,Project(0,ymax,0)> ; "svg_it(y)" ljust
30 arrow from Orig to 1.2 <Orig,Project(0,0,zmax)> ; "svg_it(z)" rjust
31
32 linethick_(0)
33 for i = 0 to nx-1 do {
34 x = xmax*i/nx
35 for j = 0 to ny-1 do {
36 y = ymax*j/ny
37 fnxy = fn(x,y)
38 shade((fnmax+fnxy)/fnmax/2,
39 line from Project(x,y,fnxy) to Project(x,(y+dy),`fn(x,(y+dy))')\
40 then to Project((x+dx),(y+dy),`fn((x+dx),(y+dy))')\
41 then to Project((x+dx),y,`fn((x+dx),y)')\
42 then to Project(x,y,fnxy)
43 ) } }
44 ] with .w at last [].e+(-0.2,0)
45
46 Torus: [
47 # Calculate all the facet centres but draw
48 # only a subset of them after sorting
49
50 viewazimuth = 20 # Set view angles in degrees
51 viewelevation = 30
52
53 setview(viewazimuth,viewelevation,0)
54
55 sfactor = 0.7
56 tradius = 2*sfactor
57 sradius = 0.75*sfactor
58
59 define(`torus',`rot3Dz((`$1')*dtor_,
60 sum3D(tradius,0,0,rot3Dy((`$2')*dtor_,sradius,0,0)))')
61
62 define(`tvisible',`dot3D(view3D1,view3D2,view3D3,
63 rot3Dz((`$1')*dtor_,rot3Dy((`$2')*dtor_,1,0,0)))')
64
65 Orig: (0,0)
66 X: arrow from Orig to Project(tradius+sradius*4,0,0); "x" rjust
67 Y: arrow from Orig to Project(0,tradius+sradius*2,0); "y" below wid 4bp__
68
69 dt = 10 # major angle degrees per facet
70 ds = 10 # minor angle degrees per facet
71
72 # create the arrays and sort
73 n = 0
74 for t = dt to 360+dt/2 by dt do {
75 for s=ds/2 to 360.1 by ds do {
76 if tvisible(t,s) >= 0 then {
77 n +=1
78 t[n] = t
79 s[n] = s
80 d[n] = dot3D(torus(t,s),view3D1,view3D2,view3D3) # view distance
81 ix[n] = n
82 } } }
83 #prval(n)
84 dpquicksort(d,1,n,ix)
85
86 # draw the facets
87 thinlines_
88 for i = 1 to n do {
89 tc = t[ix[i]]; sc = s[ix[i]]
90 SE: Project(torus(tc+dt/2,sc-ds/2))
91 SW: Project(torus(tc-dt/2,sc-ds/2))
92 NW: Project(torus(tc-dt/2,sc+ds/2))
93 NE: Project(torus(tc+dt/2,sc+ds/2))
94 f = ((dcosine3D(3,torus(tc,sc))/sradius+1)/2)^2
95 g = min(f,0.9)
96 setrgb(g,g,g)
97 # line fill f ifpdf( invis ) \
98 # from SE to SW then to NW then to NE then to SE
99 shade(f,
100 line invis fill f from SE to SW then to NW then to NE then to SE )
101
102 resetrgb
103 }
104
105 thicklines_
106 arrow from Orig to Project(0,0,tradius*1.4); "z" above
107 dashline(from Orig to Project(torus(0,0)),,,,G)
108 arrow to X.end
109 dashline(from Orig to Project(torus(90,0)),,,,G)
110 arrow to Y.end
111
112 ] with .sw at last [].se+(0.2,0)
113
114 Hat: [
115 # Sort as for the torus but draw edges too
116
117 azimuth = 25 # View angles in degrees
118 elevation = 20
119 setview(azimuth,elevation)
120 # the 3D object: `hat(t,y)'
121 define(`hat',`cosd($1)*($2),sind($1)*($2),(($2)^2-1)^2')
122 define(`gradient',`(-4*($2)*(($2)^2-1)*cosd(`$1')),
123 (-4*($2)*(($2)^2-1)*sind(`$1')),1')
124 define edge {$2=dot3D(View3D,gradient($1,y))}
125 define(`hatvis',
126 `(($2 > 0.6) || (dot3D(View3D,gradient($1,$2)) > 0))')
127
128 # grid parameters
129 dang = 09
130 maxy = 1.25
131 dy = 0.05
132
133 Orig: (0,0)
134 X: arrow from Orig to Project(maxy*1.2,0,0); "x" rjust
135 Y: arrow from Orig to Project(0,maxy*1.2,0); "y" ljust
136 Xv: Project(1,0,0)
137 Yv: Project(0,1,0)
138 Zv: Project(0,0,1)
139 # create the arrays and sort
140 n = 0
141 for t = dang/2 to 360.1 by dang do {
142 for y=dy/2 to maxy by dy do {
143 if hatvis(t,y) then {
144 n +=1
145 t[n] = t
146 y[n] = y
147 d[n] = dot3D(hat(t,y),View3D) #distance toward the front
148 ix[n] = n
149 } } }
150 #prval(n)
151 dpquicksort(d,1,n,ix)
152 # draw the facets
153 ellipse wid maxy*2 ht maxy*2*sind(elevation) \
154 with .c at Project(0,0,(maxy^2-1)^2)+(0,linethick bp__/2)
155 thinlines_
156 for i = 1 to n do {
157 tc = t[ix[i]]; yc = y[ix[i]]
158 SE: Project(hat(tc+dang/2,yc-dy/2))
159 SW: Project(hat(tc-dang/2,yc-dy/2))
160 NW: Project(hat(tc-dang/2,yc+dy/2))
161 NE: Project(hat(tc+dang/2,yc+dy/2))
162 f = abs(yc^2-1)
163 line invis fill f from SE to SW then to NW then to NE then to SE
164 }
165
166 # Outline where the surface goes invisible
167 mm = int(maxy/dy)
168 nr = -1
169 for i=1 to mm do { y = i/(mm+3)
170 findroot(edge,(azimuth+2),(azimuth+180-2),1e-8,t)
171 nr +=1
172 R[mm+nr]: Project(hat(t,y))
173 R[mm-1-nr]: (-R[mm+nr].x,R[mm+nr].y)
174 }
175 fitcurve(R,mm*2-1)
176
177 # Z axis
178 thicklines_
179 Z: arrow from Zv to Project(0,0,1.2); "z" ljust
180 line dashed from Orig to Zv chop 0 chop dashwid/2
181 line dashed from Orig to Xv
182 line dashed from Orig to Yv
183
184 # Partial rim
185 ellipsearc(maxy*2,maxy*2*sind(elevation),-pi_*1.4,pi_/3) \
186 with .C at Project(0,0,(maxy^2-1)^2)+(0,linethick bp__/2)
187 ] scaled 1.25 with .s at 2nd [].ne+(0,-0.75)
188 ] scaled 0.85
189
190 .PE