Debian Codegraph @

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

raw
1 .PS
2 # Smithchart.m4
3 gen_init
4 #https://utah.instructure.com/courses/684846
5 #https://www.youtube.com/watch?v=RptPsP8hS4g
6 #https://www.youtube.com/watch?v=UUk1R01uEoE
7 ##https://www.youtube.com/watch?v=TsXd6GktlYQ
8
9 scalefactor = 6.5/2 # to vary the final chart diameter
10 #calefactor = 6.5/2*3/4 # 3/4 scale for svg examples
11 # Basic definitions
12 define Rac {($1/($1+1),0)*scalefactor} # centre of const ra circle
13 define rar {1/abs($1+1)*scalefactor} # radius
14 define Xac {(1,1/($1))*scalefactor} # centre of const xa circle
15 define xar {1/abs($1)*scalefactor} # radius
16 define Rc {CRc[$1*100]} # Rc circle indexed by value
17 define Xc {CXc[$1*100]} # Xc circle indexed by value
18 define grayline {outlined graystring($1)}
19 define arct {arc thick $1}
20
21 # `SGamma(ra,xa) chart location of complex value'
22 define(`SGamma',`(ifelse(`$2',0,`Rc($1).w',
23 `Cintersect(Rac(`$1'),rar(`$1'),Xac(`$2'),xar(`$2'), dnl
24 ifelse(substr(`$2',0,1),-,R))'))')
25 # 1-piece Ra arc
26 define(`RaArc1',`ifinstr(`$1',to,for ix=`$1' do,ix=`$1';) {
27 Rc(ix): arct(`$2') grayline(`$2'g) dnl
28 from SGamma(ix,`$3') to SGamma(ix,-(`$3')) with .c at Rac(ix)}')
29 # 2-piece Ra arc
30 define(`RaArc2',`ifinstr(`$1',to,for ix=`$1' do,ix=`$1';) {
31 Rc(ix): arct(`$2') grayline(`$2'g) dnl
32 from SGamma(ix,`$3') to SGamma(ix,`$4') with .c at Rac(ix)
33 arct(`$2') grayline(`$2'g) dnl
34 from SGamma(ix,-(`$4')) to SGamma(ix,-(`$3')) with .c at Rac(ix)}')
35 # Positive and negative Xa arcs
36 define(`XaArc2',`ifinstr(`$1',to,for ix=`$1' do,ix=`$1';) {
37 Xc(ix): arct(`$2') grayline(`$2'g) dnl
38 from SGamma(`$3',ix) to SGamma(`$4',ix) with .c at Xac(ix)
39 Xc(-ix): arct(`$2') grayline(`$2'g) dnl
40 cw from SGamma(`$3',-ix) to SGamma(`$4',-ix) with .c at Xac(-ix)}')
41
42 define(`Smithchart',`[
43 iflatex(s_init(tst))
44 ifpostscript(,latexcommand({\tiny))
45 ifsvg(svg_font(sans-serif,10bp__)
46 svg_rot_init(SmithchartDPV))
47
48 thk = 1.2 # width of thick lines (pt)
49 thn = 0.4 # thin lines
50 thkg = 0.33 # weight of thick lines
51 thkg =0.5
52 thng = 0.4 # weight of thin lines
53 thng = 0.6
54
55 C: circle thick thk rad rar(0) at (0,0)
56 line thick thk grayline(thkg) from C.w to C.e
57
58 Rc(50): circle thick thk grayline(thkg) rad rar(50) at Rac(50)
59 foreach_(`term',`RaArc1(patsubst(term,:,`,'))',
60 20:thn:50,
61 30 to 40 by 10:thn:50,
62 20:thk:20,
63 12 to 18 by 2:thn:20,
64 10:thn:50,
65 10:thk:20,
66 6 to 9:thn:10,
67 5:thk:10,
68 2.2 to 4.81 by 0.2:thn:5,
69 4:thn:20,
70 4:thk:5,
71 3:thn:10,
72 3:thk:5,
73 2:thn:20,
74 2:thk:5,
75 1.1 to 1.91 by 0.2:thn:2,
76 1.2 to 2.01 by 0.2:thk:2,
77 1:thn:10,
78 1:thk:5,
79 0.2 to 1.81 by 0.2:thn:5,
80 0.2 to 0.81 by 0.2:thk:2,
81 0.6 to 0.91 by 0.1:thk:1,
82 0.55 to 0.951 by 0.1:thn:1,
83 0.1 to 0.91 by 0.2:thn:2,
84 0.1 to 0.91 by 0.2:thk:1,
85 0.22 to 0.481 by 0.02:thn:0.5,
86 0.01 to 0.191 by 0.01:thn:0.2,
87 0.05 to 0.151 by 0.1:thk:0.2)
88
89 foreach_(`term',`RaArc2(patsubst(term,:,`,'))',
90 0.05 to 0.451 by 0.1:thn:1:0.5,
91 0.02 to 0.181 by 0.02:thn:0.5:0.1)
92
93 Xc(50): arct(thk) cw grayline(thkg) from C.e \
94 to SGamma(0,50) with .c at Xac(50)
95 Xc(-50): arct(thk) grayline(thkg) from C.e \
96 to SGamma(0,-50) with .c at Xac(-50)
97
98 foreach_(`term',`XaArc2(patsubst(term,:,`,'))',
99 10 to 20 by 10:thn:0:50,
100 7 to 9 by 2:thn:0:10,
101 2 to 18 by 2:thn:0:20,
102 0.2 to 4.81 by 0.2:thn:0:5,
103 1.1 to 1.91 by 0.2:thn:0:2,
104 1 to 4:thn:0:10,
105 0.1 to 0.91 by 0.2:thn:0:2,
106 0.22 to 0.481 by 0.02:thn:0:0.5,
107 0.55 to 0.951 by 0.1:thn:0:1,
108 10 to 20 by 10:thk:0:20,
109 5:thk:0:10,
110 1.2 to 1.81 by 0.2:thk:0:2,
111 1 to 4:thk:0:5,
112 0.2 to 0.81 by 0.2:thk:0:2,
113 0.1 to 0.91 by 0.2:thk:0:1)
114
115 foreach_(`term',`XaArc2(patsubst(term,:,`,'))',
116 0.05 to 0.451 by 0.1:thn:0.5:1,
117 0.02 to 0.181 by 0.02:thn:0:0.5,
118 0.02 to 0.191 by 0.01:thn:0:0.2, dnl 0.02 should be 0.01
119 0.05 to 0.151 by 0.1:thk:0:0.2)
120 dnl these avoid TeX arithmetic overflow:
121 line thick thn grayline(thng) from SGamma(0,0.01) to SGamma(0.2,0.01)
122 line thick thn grayline(thng) from SGamma(0,-0.01) to SGamma(0.2,-0.01)
123 dot(at C,,1,grayline(thkg))
124
125 dnl Internal labels start here
126 textht = C.wid/120
127 # Horizontal axis
128 foreach_(`t',`box wid textht ht textht*1.5 colored "white" \
129 with .se at Rc(t).w+(-2bp__,2bp__)
130 r_text(90,"t",at Rc(t).w+(-textht/3,textht*1.5))',
131 0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9, 1,1.2,1.4,1.6,1.8, 2,3,4,5,10,20,50)
132 # Xc=1 labels
133 foreach_(`tt',
134 `define(`m4ta',patsubst(tt,:.*))define(`m4vl',patsubst(tt,.*:))dnl
135 X: SGamma(m4vl,1)
136 M: move from Rc(m4vl) to X; ax = lin_ang(M)*rtod_-90 #; print ax
137 r_text(m4ta,m4vl,at X+(Rect_(textht*2,ax+30)))
138 Y: X-Rc(m4vl); X: Rc(m4vl)+(Y.x,-Y.y)
139 r_text(-m4ta,m4vl,at X+(Rect_(textht*1.7,-(ax+30)))) ',
140 10:0.2, 19:0.4, 26:0.6, 32:0.8, 37:1)
141 # right-side circumference
142 foreach_(`tt',
143 `define(`m4ta',patsubst(tt,:.*))define(`m4vl',patsubst(tt,.*:))dnl
144 X: Xc(m4vl).start; ax = atan2(X.y,X.x)*rtod_ ; # print round_(ax)
145 r_text(m4ta,m4vl,at X+(Rect_(textht*2,ax-120)))
146 if m4vl>=2 then {
147 r_text(-m4ta,m4vl,at (X.x,-X.y)+(Rect_(textht*1.5,-ax+135))) }\
148 else { r_text(-m4ta,m4vl,at (X.x,-X.y)+(Rect_(textht*2,-ax+150))) } ',
149 6:20, 11:10, 23:5, 28:4, 37:3, 53:2, 58:1.8, 64:1.6, 71:1.4, 80:1.2, 90:1)
150 # left-side circumference
151 foreach_(`tt',
152 `X: Xc(m4Lx*0.1).start; # print round_(atan2(X.y,X.x)*rtod_-180)
153 r_text(-patsubst(tt,:,`,'),at X+(Rect_(textht*1.7,-m4Lx*11+40)))
154 r_text( patsubst(tt,:,`,'),at (X.x,-X.y)+(Rect_(textht*2.1,m4Lx*11-30))) ',
155 11:0.1, 23:0.2, 33:0.3, 44:0.4, 53:0.5, 62:0.6, 70:0.7, 77:0.8, 84:0.9)
156 # Ra=1 labels
157 foreach_(`tt',`X: SGamma(1,m4Lx*0.2)
158 M: move from Rac(1) to X; # print round_(lin_ang(M)*rtod_-180)
159 r_text(-eval(m4Lx*11),ifelse(m4Lx,5,1,0.eval(m4Lx*2)),
160 at X+(Rect_(textht*1.5,-m4Lx*11+40)))
161 r_text( eval(m4Lx*11),ifelse(m4Lx,5,1,0.eval(m4Lx*2)),
162 at (X.x,-X.y)+(Rect_(textht*2,m4Lx*11-30))) ',
163 11:0.2, 23:0.4, 33:0.6, 44:0.8, 53:1)
164
165 textht *=0.9
166 # Wavelength circle and tics
167 wvsep = textht*3/2
168 wltic = C.wid/120
169 circle thick thn grayline(thkg) diam C.diam+wltic/2+wvsep*11 at C
170 W: circle thick thn grayline(thkg) diam C.diam+wvsep*8 at C
171 for tc=0 to 249 do {ax = 180-tc/250*360; line thick thn grayline(thkg) \
172 from W+(Rect_(W.rad+wltic/2,ax)) to W+(Rect_(W.rad-wltic/2,ax)) }
173 # Wavelength circle labels
174 for_(0,49,1,
175 `ifelse(eval(m4x<5),1,,
176 `r_text(eval(90-m4x*180/25),ifelse(m4x,0,0,eval(m4x<10),1,0.0`'m4x,0.`'m4x),
177 at W+(Rect_(W.rad+wltic/2+textht*0.5,180-m4x*180/25)))')
178 ifelse(eval(m4x<47),1,
179 `r_text(eval(90-m4x*180/25),ifelse(m4x,0,0,eval(m4x>40),1,0.0`'eval(50-m4x),
180 0.`'eval(50-m4x)), at W+(Rect_(W.rad-wltic/2-textht*1.0,180-m4x*180/25)))')')
181
182 circle thick thn grayline(thkg) diam C.diam+wvsep*5 at C
183 A: circle thick thn grayline(thkg) diam C.diam+wvsep*2.5 at C
184 for tc=0 to 359 by 2 do {line thick thn grayline(thkg) \
185 from A+(Rect_(A.rad+wltic/2,tc)) to A+(Rect_(A.rad,tc)) }
186 for_(20,170,10,
187 `r_text(eval(-90+m4x),m4x,at A+(Rect_(A.rad+textht*0.5,m4x)))
188 r_text(eval( 90-m4x),-m4x,at A+(Rect_(A.rad+textht*1.2,-m4x)))
189 ')
190 r_text(90,180,at A-(A.rad+textht/2,0))
191 foreach_(`rca',
192 `r_text(eval(90-(180-rca/10)),eval(m4Lx*5+5),
193 at A+(Rect_(A.rad-textht*0.7,rca/10)))
194 r_text(eval(-90+(180-rca/10)),eval(-m4Lx*5-5),
195 at A+(Rect_(A.rad-textht*0.7,-rca/10))) ',
196 195,295,392,490,588,685,782,880,967,1072,
197 1165,1260,1352,1438,1518,1598,1645)
198
199 # Internal labels
200 setrgb(thng,thng,thkg)
201 "RESISTANCE R/Zo OR CONDUCTANCE G/Yo" at C+SGamma(0.5,0)-(0,C.rad/40)
202 foreach_(`Lttr',`ifelse(Lttr,*,,`r_text(eval(87-m4Lx*86/100),Lttr,
203 at W+(Rect_(W.rad+wltic/2+textht*0.5, 177-m4Lx*0.86))) ')',
204 W,A,V,E,L,E,N,G,T,H,S,*,T,O,W,A,R,D,*,G,E,N,E,R,A,T,O,R)
205 foreach_(`Lttr',`ifelse(Lttr,*,,`r_text(eval(115-m4Lx*86/100),Lttr,
206 at W+(Rect_(W.rad-wltic/2-textht*1.0, 204-m4Lx*0.86))) ')',
207 W,A,V,E,L,E,N,G,T,H,S,*,T,O,W,A,R,D,*,L,O,A,D)
208 foreach_(`Lttr',`ifelse(Lttr,*,,`define(`xa','13-m4Lx*86/100`)
209 r_text(eval(xa-90),Lttr,at A+(Rect_(A.rad+textht*0.7, xa))) ')',
210 R,E,F,L,E,C,T,I,O,N,*,C,O,E,F,F,I,C,I,E,N,T,*,A,N,G,L,E)
211 foreach_(`Lttr',`ifelse(Lttr,*,,`define(`xa','14-m4Lx*86/100`)
212 r_text(eval(xa-90),Lttr,at A+(Rect_(A.rad-textht*0.7, xa))) ')',
213 T,R,A,N,S,M,I,S,S,I,O,N,*,C,O,E,F,F,I,C,I,E,N,T,*,A,N,G,L,E)
214 resetrgb
215
216 ifpostscript(,latexcommand(}%))
217 ifsvg(command "</g>")
218 ] ')
219
220 Smithchart at (0,0)
221
222 .PE