Debian Codegraph @

texmf-dist/tex/generic/pgfplots/libs/tikzlibrarypgfplots.smithchart.code.tex

raw
1 %--------------------------------------------
2 %
3 % Package pgfplots, library for smith charts.
4 %
5 % Copyright 2010 by Christian Feuersänger.
6 %
7 % This program is free software: you can redistribute it and/or modify
8 % it under the terms of the GNU General Public License as published by
9 % the Free Software Foundation, either version 3 of the License, or
10 % (at your option) any later version.
11 %
12 % This program is distributed in the hope that it will be useful,
13 % but WITHOUT ANY WARRANTY; without even the implied warranty of
14 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 % GNU General Public License for more details.
16 %
17 % You should have received a copy of the GNU General Public License
18 % along with this program. If not, see <http://www.gnu.org/licenses/>.
19 %
20 % A smithchart maps the complex halfplane
21 % H subset \C,
22 % H := [0,infty] x [-infty,infty]
23 % =~ \{ z = a+ j *b | a >=0, b \in \R }
24 %
25 % to the unit circle.
26 %
27 % A number z = a+jb is mapped to r(z) = (z-1) / (z+1) which is, per
28 % definition, in the 2d unit circle.
29 %
30 % Grid lines (i.e. a==const or b==const) are mapped on circles.
31 %
32 % In PGFPlots, the a=Re(z) is the x axis and b = Im(z) is the y axis.
33 %
34 % - CARTESIAN INPUT
35 % - tick/grid coordinates are from
36 % - input coordinates can be either from H or (perhaps preferred) from
37 % the unit circle.
38 % this "preferred" needs to be discussed.
39 % - the transformed data range is the unit circle (or a sequeezed variant)
40 % - in order to compute limits etc., I should accept data in H. this
41 % should simplify the logic to determine ticks etc considerably.
42 % problem: this transformation appears to be quite difficult (?)
43 % -> r(z) = (z-1)/(z+1)
44 % in complex arithmetics (but the G-tutorial.pdf says something
45 % about these circle equations!?)
46 %
47 % www.amanogawa.com/archive/docs/G-tutorial.pdf
48 %
49 %
50 % Idea:
51 % - work on H
52 % - transform wherever necessary
53 % - implement all pgfplots wrinkles in analogy to polar axes
54 % - provide support for normalized input coords (combined with
55 % untransformed limits or something like that)
56
57 \pgfplotsdefineaxistype{smithchart}{%
58 \pgfplots@smithchartaxis@activate
59 }%
60
61 \newif\ifpgfplotspointisinsmithchartCS
62 \newif\ifpgfplots@smithchart@showorigin
63 \newif\ifpgfplots@smithchart@mirrored
64
65 \pgfplotsset{
66 /pgfplots/xgrid each nth passes y/.initial=,% format: CSV list, each entry of the form '<at> | <at> ':' <eachnth> | <at> 'if <' <xvalue> | <at> ':' <eachnth> 'if <' <xvalue>'
67 /pgfplots/xgrid each nth passes y start/.initial=0,
68 /pgfplots/ygrid each nth passes x/.initial=,
69 /pgfplots/ygrid each nth passes x start/.initial=0,
70 %
71 /pgfplots/xgrid stop at y/.initial=,% individual stop map of the form '<xpos> ':' <stopaty>', separated by white space
72 /pgfplots/ygrid stop at x/.initial=,
73 %
74 % FIXME : this is undocumented:
75 /pgfplots/smithchart mirrored/.is if=pgfplots@smithchart@mirrored,
76 /pgfplots/smithchart mirrored/.default=true,
77 %
78 % this boolean may only be used inside of \addplot. It will be
79 % ignored otherwise.
80 /pgfplots/is smithchart cs/.is if=pgfplotspointisinsmithchartCS,
81 /pgfplots/is smithchart cs/.default=true,
82 /pgfplots/show origin/.is if=pgfplots@smithchart@showorigin,
83 /pgfplots/show origin/.default=true,
84 /pgfplots/show origin code/.code={%
85 \path[draw=black,fill=white] (0pt,0pt) circle (2.5pt);
86 \path[fill=black] (0pt,0pt) circle (0.5pt);
87 },
88 /pgfplots/every smithchart axis/.style={
89 grid=both,
90 xmin=0,
91 xmax=16000,% FIXME : more is not possible because some code uses the \pgfplots@xmin@reg registers... (ticks)
92 ymin=-16000,ymax=16000,
93 scaled ticks=false, % never draw the \cdot 10^4 labels
94 major tick style={draw=black},
95 xtick align=center,
96 ytick align=center,
97 every axis title shift=1.2\baselineskip,
98 legend style={anchor=center},
99 },
100 /pgfplots/default smithchart xtick/.code=,
101 /pgfplots/default smithchart ytick/.code=,
102 /pgfplots/default smithchart xytick/.code=,
103 /pgfplots/smithchart ticks by size/.code 2 args={%
104 \ifdim#1<14cm
105 \pgfkeysalso{/pgfplots/few smithchart ticks}%
106 \else
107 \ifdim#1<20cm
108 \pgfkeysalso{/pgfplots/many smithchart ticks}%
109 \else
110 \pgfkeysalso{/pgfplots/dense smithchart ticks}%
111 \fi
112 \fi
113 },
114 /pgfplots/few smithchart ticks*/.style={
115 default smithchart xtick/.style={
116 xtick={0.2,0.5,1,2,5},
117 },
118 default smithchart ytick/.style={
119 ytick={%
120 0,%
121 0.2, 0.5, 1, 2, 5,%
122 -0.2,-0.5,-1,-2,-5},
123 },
124 default smithchart xytick/.style={
125 xgrid each nth passes y={2},
126 ygrid each nth passes x={2},
127 },
128 },
129 /pgfplots/few smithchart ticks/.style={/pgfplots/few smithchart ticks*},
130 /pgfplots/few smithchart ticks*,% use it as initial config
131 /pgfplots/many smithchart ticks*/.style={
132 default smithchart xtick/.style={
133 xtick={
134 0.1,0.2,0.3,0.4,0.5,1,1.5,2,3,4,5,10,20%
135 },
136 minor xtick={0.6,0.7,0.8,0.9,1.1,1.2,1.3,1.4,1.6,1.7,1.8,1.9,2.2,2.4,2.6,2.8,3.2,3.4,3.6,3.8,4.5,6,7,8,9,50},
137 },
138 default smithchart ytick/.style={
139 ytick={%
140 0,%
141 0.1,0.2,...,1,1.5,2,3,4,5,10,20,%
142 -0.1,-0.2,...,-1,-1.5,-2,-3,-4,-5,-10,-20%
143 },
144 minor ytick={%
145 1.1,1.2,1.3,1.4,1.6,1.7,1.8,1.9,2.2,2.4,2.6,2.8,3.2,3.4,3.6,3.8,4.5,6,7,8,9,50,%
146 -1.1,-1.2,-1.3,-1.4,-1.6,-1.7,-1.8,-1.9,-2.2,-2.4,-2.6,-2.8,-3.2,-3.4,-3.6,-3.8,-4.5,-6,-7,-8,-9,-50%
147 },
148 },
149 default smithchart xytick/.style={
150 xgrid each nth passes y={1,2,4,5,10,20},
151 ygrid each nth passes x={1,2,3,5,10:3,20:3},
152 },
153 },
154 /pgfplots/many smithchart ticks/.style={
155 many smithchart ticks*,
156 every axis title shift=6pt,
157 yticklabel in circle,
158 show origin=true,
159 },
160 /pgfplots/dense smithchart ticks*/.style={
161 default smithchart xtick/.style={
162 %ygrid each nth passes x start=0,
163 xtick={
164 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%
165 },
166 minor xtick={%
167 0.01,0.02,0.03,0.04,0.05,0.06,0.07,0.08,0.09,0.11,0.12,0.13,0.14,0.15,0.16,0.17,0.18,0.19,%
168 0.22,0.24,0.26,0.28,0.32,0.34,0.36,0.38,0.42,0.44,0.46,0.48,%
169 0.52,%
170 0.55,0.65,0.75,0.85,0.95,%
171 %0.6,0.7,0.8,0.9,%
172 1.1,1.3,1.5,1.7,1.9,%
173 2.2,2.4,2.6,2.8,3.2,3.4,3.6,3.8,4.5,6,7,8,9,50},
174 },
175 default smithchart ytick/.style={
176 ytick={%
177 0,%
178 0.1,0.2,...,1,1.2,1.4,1.6,1.8,2,3,4,5,10,20,%
179 -0.1,-0.2,...,-1,-1.2,-1.4,-1.6,-1.8,-2,-3,-4,-5,-10,-20%
180 },
181 minor ytick={%
182 0.01,0.02,0.03,0.04,0.05,0.06,0.07,0.08,0.09,0.11,0.12,0.13,0.14,0.15,0.16,0.17,0.18,0.19,%
183 0.22,0.24,0.26,0.28,0.32,0.34,0.36,0.38,0.42,0.44,0.46,0.48,%
184 0.55,0.65,0.75,0.85,0.95,%
185 1.1,1.3,1.5,1.7,1.9,2.2,2.4,2.6,2.8,3.2,3.4,3.6,3.8,4.5,6,7,8,9,50,%
186 -0.01,-0.02,-0.03,-0.04,-0.05,-0.06,-0.07,-0.08,-0.09,-0.11,-0.12,-0.13,-0.14,-0.15,-0.16,-0.17,-0.18,-0.19,%
187 -0.22,-0.24,-0.26,-0.28,-0.32,-0.34,-0.36,-0.38,-0.42,-0.44,-0.46,-0.48,%
188 -0.55,-0.65,-0.75,-0.85,-0.95,%
189 -1.1,-1.3,-1.5,-1.7,-1.9,-2.2,-2.4,-2.6,-2.8,-3.2,-3.4,-3.6,-3.8,-4.5,-6,-7,-8,-9,-50%
190 },
191 },
192 default smithchart xytick/.style={
193 xgrid each nth passes y={0.2 if < 0.2001,0.5 if < 0.50001,1 if < 1.001,2,4,5,10,20},
194 ygrid each nth passes x={0.2 if < 0.2001,0.52 if < 0.52001,1 if < 1.001,2,3,5,10:3,20:3},
195 },
196 },
197 /pgfplots/dense smithchart ticks/.style={
198 yticklabel in circle,
199 every axis title shift=6pt,
200 dense smithchart ticks*,
201 show origin=true,
202 every major grid/.style={black!60},
203 },
204 /pgfplots/yticklabel in circle/.style={
205 ytick align=inside,
206 yticklabel style={
207 rotate=90,
208 sloped like y axis={%
209 execute for upside down={\tikzset{anchor=north east}},
210 %allow upside down,
211 reset nontranslations=false},
212 anchor=south west,
213 %font=\tiny,
214 }
215 },
216 yticklabel around circle/.style={
217 ytick align=center,
218 yticklabel style={
219 rotate=90,
220 sloped like y axis={%
221 execute for upside down={\tikzset{anchor=south west}},
222 %allow upside down,
223 reset nontranslations=false},
224 anchor=south east,
225 %font=\tiny,
226 }
227 },
228 yticklabel around circle*/.style={
229 ytick align=center,
230 yticklabel style={
231 rotate=90,
232 sloped like y axis={%
233 execute for upside down={\tikzset{anchor=north west}},
234 %allow upside down,
235 reset nontranslations=false},
236 anchor=north east,
237 %font=\tiny,
238 }
239 }
240 }
241
242 \pgfkeys{
243 /pgfplots/warning/smithchart/no such tick/.code 2 args={%
244 \pgfplotsthrow@warning{There is no #1tick with index '#2'. Skipping it.}%
245 },
246 }
247
248 \def\pgfplots@smithchartaxis@activate{%
249 \def\axisdefaultwidth{207pt}%
250 \def\axisdefaultheight{207pt}%
251 \let\pgfplotsqpointxy@cart=\pgfplotsqpointxy
252 \let\pgfplotsqpointxy=\pgfplotsqpointxy@smithchartaxis
253 \let\pgfplotsqpointxy@orthogonal=\pgfplotsqpointxy
254 \def\pgfplotsqpointxyz##1##2##3{\pgfplotsqpointxy{##1}{##2}}% FIXME
255 \let\pgfplotspointouternormalvectorofaxis@=\pgfplotspointouternormalvectorofaxis@smithchartaxis
256 \def\pgfplotspointouternormalvectorofaxis@ifdependson@v##1##2##3{##2}%
257 \def\pgfplots@drawticklines@INSTALLCLIP@onorientedsurf##1{}%
258 \let\pgfplots@drawgridlines@INSTALLCLIP@onorientedsurf=\pgfplots@drawgridlines@INSTALLCLIP@onorientedsurf@smithchartaxis
259 \def\pgfplots@visphase@notify@changeofcanvaslimits##1{}%
260 \def\pgfplots@avoid@empty@axis@range@for##1{}%
261 \def\pgfplotsaxisifcontainspoint##1##2{##1}%
262 \let\pgfplots@set@default@size@options=\pgfplots@set@default@size@options@smithchart%
263 %
264 \def\b@pgfplots@smithchart@defaultticks@x{0}%
265 \def\b@pgfplots@smithchart@defaultticks@y{0}%
266 \let\pgfplots@assign@default@tick@foraxis=\pgfplots@assign@default@tick@foraxis@smithchart
267 \def\pgfplots@checkisuniformLINEARtick##1##2{%
268 % don't do anything here. I suppose it is useless and is a
269 % waste of time for many ticks.
270 \global\pgfplots@isuniformtickfalse
271 }%
272 \let\pgfplots@clippath@prepare@for@axistype=\pgfplots@clippath@prepare@for@axistype@smithchartaxis
273 %
274 % invalid range: do not clear plots. simply assign default limits.
275 \let\pgfplots@handle@invalid@range@defaultlimits=\pgfplots@handle@invalid@range@defaultlimits@smithchart%
276 \def\pgfplots@handle@invalid@range{\pgfplots@handle@invalid@range@defaultlimits}%
277 %
278 \let\pgfplotspointonorientedsurfaceabwithbshift=\pgfplotspointonorientedsurfaceabwithbshift@smithchartaxis
279 \let\pgfplots@draw@axis@is@prepared=\pgfplots@draw@axis@is@prepared@smithchartaxis
280 \let\pgfplots@drawgridlines@onorientedsurf@fromto=\pgfplots@drawgridlines@onorientedsurf@fromto@smithchart
281 \let\pgfplots@drawaxis@innerlines@onorientedsurf=\pgfplots@drawaxis@innerlines@onorientedsurf@smithchart
282 \let\pgfplots@drawaxis@outerlines@separate@onorientedsurf=\pgfplots@drawaxis@outerlines@separate@onorientedsurf@smithchartaxis
283 \let\pgfplotspoint@initialisation@axes=\pgfplotspoint@initialisation@axes@smithchart%
284 \let\pgfplotspoint@initialisation@units=\pgfplotspoint@initialisation@units@smithchart
285 \expandafter\def\expandafter\pgfplots@create@axis@descriptions@\expandafter{%
286 \pgfplots@create@axis@descriptions@
287 \ifpgfplots@smithchart@showorigin
288 \pgfkeysvalueof{/pgfplots/show origin code/.@cmd}\pgfeov%
289 \fi
290 }%
291 \def\axisdefaultheight{\axisdefaultwidth}%
292 \let\pgfplots@BB@for@plotbox@get@unit@scales@for@limits=\pgfplots@BB@for@plotbox@get@unit@scales@for@limits@smithchart
293 %\let\pgfplots@limits@ready=\pgfplots@limits@ready@smithchart
294 %\let\pgfplots@show@ticklabel@=\pgfplots@show@ticklabel@@smithchart
295 %\def\pgfplots@xtick@disable@last@tick{0}%
296 \let\pgfplots@xtick@check@tickshow=\pgfplots@xtick@check@tickshow@smithchart%
297 \let\pgfplots@ytick@check@tickshow=\pgfplots@ytick@check@tickshow@smithchart%
298 \let\pgfplots@set@options@sanitize=\relax
299 \let\pgfplots@set@options@sanitizemode=\relax
300 \let\pgfplotscoordmathnotifydatascalesetfor=\pgfplotscoordmathnotifydatascalesetfor@smithchart
301 %
302 \expandafter\def\expandafter\pgfplots@notify@options@are@set\expandafter{%
303 \pgfplots@notify@options@are@set
304 \pgfplotsset{%
305 separate axis lines,%
306 is smithchart cs=false,%
307 xtick pos=left,
308 ytick pos=left,
309 axis x line*=center,
310 disabledatascaling,
311 }%
312 \def\pgfplots@xtickposnum{2}%
313 %
314 \ifx\pgfplots@xtick\pgfutil@empty
315 \def\b@pgfplots@smithchart@defaultticks@x{1}%
316 \fi
317 \ifx\pgfplots@ytick\pgfutil@empty
318 \def\b@pgfplots@smithchart@defaultticks@y{1}%
319 \fi
320 \pgfplotscoordmath{default}{parsenumber}{0.002}%
321 \let\pgfplots@almost@zero@thresh=\pgfmathresult
322 }%
323 \def\pgfplots@xticklabel@pos{}%
324 \def\pgfplots@yticklabel@pos{}%
325 \def\pgfplots@zticklabel@pos{}%
326 \def\pgfplots@init@ticklabelaxisspecfor##1##2{}%
327 \def\pgfplots@init@ticklabelaxisspec@twodim@for##1##2{}%
328 \def\pgfplotspointonorientedsurfaceabmatchaxisline@warn##1{}% clear warning. It works for smith charts.
329 \def\pgfplots@xticklabelaxisspec{v20}%
330 \def\pgfplots@yticklabelaxisspec{0v0}%
331 \def\pgfplots@zticklabelaxisspec{00v}%
332 %
333 % cartesian cs
334 \tikzdeclarecoordinatesystem{cartesian}{\edef\pgfplots@loc@TMPa{##1}\expandafter\pgfplotspointcartesian@\pgfplots@loc@TMPa\pgfplots@coord@end}%
335 %
336 %
337 % Special treatment for
338 % \pgfplots@prepare@tick@coordlists@for: make sure we don't need
339 % to use the register arithmetics in \pgfplots@xmin@reg and its
340 % variants! I want an UNRESTRICTED max data range!
341 \def\pgfplots@prepare@tick@coordlists@for@assign##1=##2{\edef##1{##2}}%
342 \def\pgfplots@prepare@tick@coordlists@for@advance##1by##2{%
343 % THIS IS NEVER USED (at the time of this writing).
344 \edef\pgfplots@loc@TMPa{##2}%
345 \pgfplotscoordmath{default}{parsenumber}{##1}%
346 \pgfplotscoordmath{default}{op}{add}{{\pgfmathresult}{\pgfplots@loc@TMPa}}%
347 \pgfplotscoordmath{default}{tofixed}{\pgfmathresult}%
348 \let##1=\pgfmathresult
349 }%
350 \def\pgfplots@prepare@tick@coordlists@for@tofixed##1{\edef\pgfmathresult{##1}}%
351 \def\pgfplots@prepare@tick@coordlists@for@handletolerance##1{}% does not apply to smithcharts.
352 \def\pgfplots@prepare@tick@coordlists@for@checktickmin##1{%
353 \pgfplotscoordmath{default}{parsenumber}{\pgfplots@tmpa}%
354 \let\pgfplots@loc@TMPa=\pgfmathresult
355 \pgfplotscoordmath{default}{parsenumber}{\csname pgfplots@##1tickmin\endcsname}%
356 \let\pgfplots@loc@TMPb=\pgfmathresult
357 \pgfplotscoordmath{default}{if less than}{\pgfplots@loc@TMPa}{\pgfplots@loc@TMPb}{%
358 \pgfplots@tickshowfalse
359 }{%
360 }%
361 }%
362 \def\pgfplots@prepare@tick@coordlists@for@checktickmax##1{%
363 \pgfplotscoordmath{default}{parsenumber}{\pgfplots@tmpa}%
364 \let\pgfplots@loc@TMPa=\pgfmathresult
365 \pgfplotscoordmath{default}{parsenumber}{\csname pgfplots@##1tickmin\endcsname}%
366 \let\pgfplots@loc@TMPb=\pgfmathresult
367 \pgfplotscoordmath{default}{if less than}{\pgfplots@loc@TMPb}{\pgfplots@loc@TMPa}{%
368 \pgfplots@tickshowfalse
369 }{%
370 }%
371 }%
372 \def\pgfplots@prepare@tick@coordlists@for@checkdatalimits##1{}% I won't do this here. Smithcharts are somewhat special.
373 }%
374
375 \def\pgfplotspointcartesian@#1,#2\pgfplots@coord@end{%
376 \pgfpointxy@orig{#1}{#2}%
377 }%
378 \def\pgfplotscoordmathnotifydatascalesetfor@smithchart#1{%
379 \def\pgfplotscoordmathnotifydatascalesetfor##1{}%
380 \edef\pgfplotscoordmathnotifydatascalesetfor@{#1}%
381 \def\pgfplotscoordmathnotifydatascalesetfor@@{x}%
382 \ifx\pgfplotscoordmathnotifydatascalesetfor@@\pgfplotscoordmathnotifydatascalesetfor@
383 \pgfplotscoordmath{#1}{datascaletrafo set params}{0}{0}%
384 \else
385 \def\pgfplotscoordmathnotifydatascalesetfor@@{y}%
386 \ifx\pgfplotscoordmathnotifydatascalesetfor@@\pgfplotscoordmathnotifydatascalesetfor@
387 \pgfplotscoordmath{#1}{datascaletrafo set shift}{0}%
388 \fi
389 \fi
390 \let\pgfplotscoordmathnotifydatascalesetfor=\pgfplotscoordmathnotifydatascalesetfor@smithchart
391 }%
392
393 % #1: the "a" value on the oriented surf
394 % #2: the "b" value.
395 % #3: the shift along the normal.
396 %
397 \def\pgfplotspointonorientedsurfaceabwithbshift@smithchartaxis#1#2#3{%
398 % implement the shift in "b" direction explicitly:
399 \pgfpointadd
400 {\pgfplotspointonorientedsurfaceab{#1}{#2}}%
401 {%
402 \pgfplotspointonorientedsurfaceabtolinespec{v}{0}%
403 \afterassignment\pgfplots@gobble@until@relax
404 \pgf@xa=-#3\relax
405 \edef\pgfplots@shift@no@unit{\pgf@sys@tonumber\pgf@xa}%
406 \pgfqpointscale
407 {\pgfplots@shift@no@unit}
408 {\expandafter\pgfplotspointouternormalvectorofaxis\expandafter{\pgfplotsretval}}%
409 }%
410 }
411
412
413 % Computes the complex division
414 % (A + j B) / (C + j D) = (A C + B D + j (B C - A D) ) / (C^2 + D^2)
415 % and assigns the result to \pgfmathresult and \pgfmathresultim . Here
416 % 'j = sqrt{-1}' is the imaginary unit.
417 %
418 % #1 : A
419 % #2 : B
420 % #3 : C
421 % #4 : D
422 %
423 % The arithmetics is performed in \pgfplotscoordmath{default} (which
424 % uses the floating point unit in the initial configuration)
425 %
426 % Numbers are expected to be already parsed (i.e. you need to invoke
427 % \pgfplotscoordmath{default}{parsenumber}{#1}%
428 % \let\A=\pgfmathresult
429 % before)
430 \def\pgfplotscoordmathcomplexdivision#1#2#3#4{%
431 \begingroup
432 \edef\pgfplots@A{#1}%
433 \edef\pgfplots@B{#2}%
434 \edef\pgfplots@C{#3}%
435 \edef\pgfplots@D{#4}%
436 %
437 %
438 % ok, compute it:
439 \pgfplotscoordmath{default}{op}{multiply}{{\pgfplots@A}{\pgfplots@C}}%
440 \let\pgfplots@AC=\pgfmathresult
441 \pgfplotscoordmath{default}{op}{multiply}{{\pgfplots@A}{\pgfplots@D}}%
442 \let\pgfplots@AD=\pgfmathresult
443 \pgfplotscoordmath{default}{op}{multiply}{{\pgfplots@B}{\pgfplots@D}}%
444 \let\pgfplots@BD=\pgfmathresult
445 \pgfplotscoordmath{default}{op}{multiply}{{\pgfplots@B}{\pgfplots@C}}%
446 \let\pgfplots@BC=\pgfmathresult
447 %
448 \pgfplotscoordmath{default}{op}{multiply}{{\pgfplots@C}{\pgfplots@C}}%
449 \let\pgfplots@CC=\pgfmathresult
450 \pgfplotscoordmath{default}{op}{multiply}{{\pgfplots@D}{\pgfplots@D}}%
451 \let\pgfplots@DD=\pgfmathresult
452 \pgfplotscoordmath{default}{op}{add}{{\pgfplots@CC}{\pgfplots@DD}}%
453 \pgfplotscoordmath{default}{op}{reciprocal}{{\pgfmathresult}}%
454 \let\pgfplots@scale=\pgfmathresult
455 %
456 %
457 \pgfplotscoordmath{default}{op}{add}{{\pgfplots@AC}{\pgfplots@BD}}%
458 \pgfplotscoordmath{default}{op}{multiply}{{\pgfmathresult}{\pgfplots@scale}}%
459 \let\pgfplots@x=\pgfmathresult
460 %
461 \pgfplotscoordmath{default}{op}{subtract}{{\pgfplots@BC}{\pgfplots@AD}}%
462 \pgfplotscoordmath{default}{op}{multiply}{{\pgfmathresult}{\pgfplots@scale}}%
463 \let\pgfplots@y=\pgfmathresult
464 %
465 \xdef\pgfplots@glob@TMPa{%
466 \noexpand\def\noexpand\pgfmathresult{\pgfplots@x}%
467 \noexpand\def\noexpand\pgfmathresultim{\pgfplots@y}%
468 }%
469 \endgroup
470 \pgfplots@glob@TMPa
471 }%
472
473 \def\pgfplotsqpointxy@smithchartaxis#1#2{%
474 \pgf@process{%
475 \ifpgfplotspointisinsmithchartCS
476 \def\pgfplots@x{#1}%
477 \def\pgfplots@y{#2}%
478 \else
479 % compute rx + j* ry = (#1 + j * #2 -1) / (#1 + j*#2 + 1)
480 %
481 % I write
482 % #1 - 1 + j * #2 = A + j * B
483 % 1 + #1 + j * #2 = C + j * D
484 %
485 % -> rx + j * ry = (A + j B) / (C + j D) = (A C + B D + j (B C - A D) ) / (C^2 + D^2)
486 \pgfplotscoordmath{default}{parsenumber}{#1}%
487 \let\pgfplots@x=\pgfmathresult
488 %
489 \pgfplotscoordmath{default}{parsenumber}{#2}%
490 \let\pgfplots@D=\pgfmathresult
491 %
492 \pgfplotscoordmath{default}{one}%
493 \let\pgfplots@one=\pgfmathresult
494 %
495 \pgfplotscoordmath{default}{op}{add}{{\pgfplots@one}{\pgfplots@x}}%
496 \let\pgfplots@C=\pgfmathresult
497 %
498 \pgfplotscoordmath{default}{op}{subtract}{{\pgfplots@x}{\pgfplots@one}}%
499 \let\pgfplots@A=\pgfmathresult
500 %
501 \let\pgfplots@B=\pgfplots@D
502 %
503 \pgfplotscoordmathcomplexdivision\pgfplots@A\pgfplots@B\pgfplots@C\pgfplots@D
504 \pgfplotscoordmath{default}{tofixed}{\pgfmathresult}%
505 \let\pgfplots@x=\pgfmathresult
506 \pgfplotscoordmath{default}{tofixed}{\pgfmathresultim}%
507 \let\pgfplots@y=\pgfmathresult
508 \fi
509 %
510 \pgfplotsqpointxy@smithchart@canvas\pgfplots@x\pgfplots@y
511 %\message{pgfplotsqpointxy{#1}{#2} ---> (\pgfplots@x,\pgfplots@y) ---> (\the\pgf@x,\the\pgf@y)}%
512 }%
513 }%
514
515 \def\pgfplotsqpointxy@smithchart@canvas#1#2{%
516 \ifpgfplots@smithchart@mirrored
517 \pgfqpointxy@orig{-#1}{#2}%
518 \else
519 \pgfqpointxy@orig{#1}{#2}%
520 \fi
521 }%
522
523 \def\pgfplots@clippath@prepare@for@axistype@smithchartaxis{%
524 \def\pgfplots@clippath@install##1{%
525 \pgfpathellipse
526 {\pgfplotsqpointxy@smithchart@canvas{0}{0}}
527 {\pgfplotsqpointxy@smithchart@canvas{1}{0}}
528 {\pgfplotsqpointxy@smithchart@canvas{0}{1}}%
529 \pgfplots@clippath@use@{##1}%
530 }%
531 }%
532
533 \def\pgfplotspointouternormalvectorofaxis@smithchartaxis#1#2#3\relax{%
534 \if v#1%
535 \pgfqpoint{0pt}{1pt}%
536 \else
537 \if v#2%
538 \pgfplotspointouternormalvectorofaxisgetv{#1#2#3}%
539 \ifx\pgfplotsretval\pgfutil@empty
540 \def\pgfplotsretval{0}%
541 \fi
542 \pgfpointdiff
543 {\pgfplotsqpointxy@smithchart@canvas{0}{0}}%
544 {\pgfplotsqpointxy{0}{\pgfplotsretval}}%
545 \pgfpointnormalised{}%
546 \else
547 \pgfqpoint{0pt}{1pt}%
548 \fi
549 \fi
550 \pgf@process{}%
551 \endgroup
552 }%
553
554 \def\pgfplotspoint@initialisation@axes@smithchart{%
555 \begingroup
556 %\pgfplotsqpointxy{\pgfplots@xmin}{\pgfplots@ymin}%
557 \gdef\pgfplotspointminminmin{\pgfplotsqpointxy@smithchart@canvas{0}{0}}%
558 %
559 % the "x" axis is the diameter of the circle (for fixed y=0)
560 \pgf@x=2\pgf@xx
561 \pgf@y=0pt
562 \xdef\pgfplotspointxaxis{\noexpand\pgf@x=\the\pgf@x\space\noexpand\pgf@y=\the\pgf@y\space}%
563 \pgfmathveclen{\pgf@x}{\pgf@y}%
564 \xdef\pgfplotspointxaxislength{\pgfmathresult pt}%
565 %
566 \pgfplotsqpointxy{\pgfplots@xmax}{\pgfplots@ymax}%
567 \xdef\pgfplotspointyaxis{\noexpand\pgf@x=\the\pgf@x\space\noexpand\pgf@y=\the\pgf@y\space}%
568 %
569 % the length of the "y" axis is 2*pi*r (for fixed x=0, the outer
570 % circle).
571 % The radius is the length of (0,1) which is (0pt,\pgf@xx1):
572 \pgfmath@basic@multiply@{\pgf@sys@tonumber\pgf@xx}{1}%
573 \pgfmathmultiply@{\pgfmathresult}{6.28318530717959}% 2*pi * r
574 \xdef\pgfplotspointyaxislength{\pgfmathresult pt}%
575 %
576 \global\let\pgfplotspointzaxis=\pgfpointorigin
577 \gdef\pgfplotspointzaxislength{0pt}%
578 \endgroup
579 %
580 \edef\pgfplots@loc@TMPa{\pgf@sys@tonumber\pgf@xx}%
581 \pgfmathdivide@{16000}{\pgfplots@loc@TMPa}%
582 \let\pgfplots@smithchart@axis@max@xradius@for@ycircle=\pgfmathresult
583 %
584 \ifdim\pgf@xx=\pgf@yy
585 \def\pgfplots@smithchart@axis@ratioxy{1}%
586 \def\pgfplots@smithchart@axis@ratioyx{1}%
587 \let\pgfplots@smithchart@axis@max@yradius@for@ycircle=\pgfplots@smithchart@axis@max@xradius@for@ycircle
588 \else
589 \edef\pgfplots@loc@TMPb{\pgf@sys@tonumber\pgf@yy}%
590 \pgfmathdivide@\pgfplots@loc@TMPa\pgfplots@loc@TMPb
591 \let\pgfplots@smithchart@axis@ratioxy=\pgfmathresult
592 \pgfmathdivide@\pgfplots@loc@TMPb\pgfplots@loc@TMPa
593 \let\pgfplots@smithchart@axis@ratioyx=\pgfmathresult
594 %
595 \pgfmathdivide@{16000}{\pgfplots@loc@TMPb}%
596 \let\pgfplots@smithchart@axis@max@yradius@for@ycircle=\pgfmathresult
597 \fi
598 }
599 \let\pgfplotspoint@initialisation@units@orig=\pgfplotspoint@initialisation@units
600 \def\pgfplotspoint@initialisation@units@smithchart{%
601 \ifpgfplots@smithchart@mirrored
602 \pgfplots@warning{The key 'smithchart mirrored' is based on a mistake of the author. It does NOT resemble Admittance Smith charts!}%
603 \fi
604 \pgfplotspoint@initialisation@units@orig
605 \def\pgfplotspointunity{%
606 \pgfplotspointouternormalvectorofaxisgetv{0v0}% x=0 (outer circle) and v varies (the yticks)
607 \ifx\pgfplotsretval\pgfutil@empty
608 \def\pgfplotsretval{0}%
609 \fi
610 \pgfpointnormalised{\pgfplotsqpointxy{0}{\ifx\pgfplotsretval\pgfutil@empty 0\else\pgfplotsretval\fi}}%
611 \pgf@xa=-\pgf@y
612 \global\pgf@y=\pgf@x
613 \global\pgf@x=\pgf@xa
614 }%
615 \def\pgfplotsunitylength{1}%
616 \def\pgfplotsunityinvlength{1}%
617 }%
618
619 \def\pgfplots@drawgridlines@INSTALLCLIP@onorientedsurf@smithchartaxis#1{%
620 %\pgfplots@clippath@install{\pgfusepath{clip}}%
621 }%
622
623 % At this time, the minor/major tick lists are initialised.
624 \def\pgfplots@draw@axis@is@prepared@smithchartaxis{%
625 \pgfplots@gridlines@init@grid@stop@points@for xy%
626 \pgfplots@gridlines@init@grid@stop@points@for yx%
627 %
628 % and finalize x:
629 \def\pgfplots@finalize@constraints{1}%
630 \pgfplots@gridlines@init@grid@stop@points@for@computethem{x}{y}{\pgfplots@finalize@constraints}%
631 }%
632
633
634 % Initialises the '#1grid each nth passes #2' and '#1grid stop at #2'
635 % features. All it does is to prepare the
636 % method \pgfplots@get@current@grid@stop@point.
637 %
638 % The method is quite involved. Please refer to the manual for what it
639 % is supposed to do, and refer to the code comments below for
640 % implementational details.
641 %
642 % #1 either x or y
643 % #2 either x or y
644 \def\pgfplots@gridlines@init@grid@stop@points@for#1#2{%
645 %
646 \expandafter\let\csname pgfplots@#1grid@stop@points\endcsname=\relax
647 %
648 \pgfkeysgetvalue{/pgfplots/#1grid each nth passes #2}\pgfplots@loc@TMPa
649 \ifx\pgfplots@loc@TMPa\pgfutil@empty
650 \else
651 % we have no "xticknum -> xtickpos" lookup table yet.
652 \expandafter\def\csname b@pgfplots@#2ticknum@to@pos@lookup\endcsname{0}%
653 %
654 \pgfplotslistnewempty\pgfplots@loc@TMPd
655 % normalise the argument for 'ygrid each nth passes x': each list element
656 % should be of the form '<xtickpos>:<n>' where <n> means that each
657 % <n>th arc can pass.
658 \expandafter\pgfplotsutilforeachcommasep\pgfplots@loc@TMPa\as\entry{%
659 \expandafter\pgfplots@gridlines@init@grid@stop@points@for@normalise\entry\relax#1#2%
660 \expandafter\pgfplotslistpushback\entry\to\pgfplots@loc@TMPd
661 }%
662 \expandafter\let\csname pgfplots@#1grid@stop@points\endcsname=\pgfplots@loc@TMPd
663 %
664 % Ok.
665 %
666 % Now, the 'ygrid each nth passes x' feature relies *crucially* on grid line
667 % indices (for the 'each nth' feature).
668 %
669 % I sort the arcs according to their absolute magnitude and assign
670 % indices into the resulting arrays to normalize that stuff.
671 %
672 % The array is of the form
673 % A[i] = entry of \pgfplots@prepared@tick@positions@*
674 % and contains *both*, major and minor grid lines.
675 \pgfplotsarraynewempty\pgfplots@gridlines
676 \pgfplotscoordmath{default}{zero}%
677 \edef\elem{{-1}{\pgfmathresult}}% require 0 to be zero for symmetry even if there is no such tick pos
678 \expandafter\pgfplotsarraypushback\elem\to\pgfplots@gridlines
679 \pgfplots@if{pgfplots@#1majorgrids}{%
680 % insert all major tick positions, using their absolute value.
681 \expandafter
682 \pgfplotslistforeachungrouped\csname pgfplots@prepared@tick@positions@major@#1\endcsname\as\elem{%
683 \expandafter\pgfplots@prepared@tick@pos@unpack\elem
684 \pgfplotscoordmath{default}{parsenumber}{\pgfplots@tick}%
685 \pgfplotscoordmath{default}{op}{abs}{{\pgfmathresult}}%
686 \edef\elem{{\pgfplots@ticknum}{\pgfmathresult}}%
687 \expandafter\pgfplotsarraypushback\elem\to\pgfplots@gridlines
688 }%
689 }{}%
690 \pgfplots@if{pgfplots@#1minorgrids}{%
691 % now the same for minor grid positions:
692 \expandafter
693 \pgfplotslistforeachungrouped\csname pgfplots@prepared@tick@positions@minor@#1\endcsname\as\elem{%
694 \expandafter\pgfplots@prepared@tick@pos@unpack\elem
695 \pgfplotscoordmath{default}{parsenumber}{\pgfplots@tick}%
696 \pgfplotscoordmath{default}{op}{abs}{{\pgfmathresult}}%
697 \edef\elem{{\pgfplots@ticknum}{\pgfmathresult}}%
698 \expandafter\pgfplotsarraypushback\elem\to\pgfplots@gridlines
699 }%
700 }{}%
701 % sort the array!
702 \pgfkeysgetvalue{/pgfplots/smithchart@sortlt/.@cmd}\pgfplots@loc@TMPa
703 \pgfkeyslet{/pgfplots/iflessthan/.@cmd}\pgfplots@loc@TMPa
704 \pgfplotsarraysort\pgfplots@gridlines
705 %
706 % ok. Now it is sorted.
707 %
708 % I finally need a lookup
709 % \pgfplots@ticknum --> sort index.
710 % If the associated values have the same absolute value, the same
711 % sort index should be assigned.
712 %
713 % For example, the array might be associated to the following tick
714 % positions, sorted by absolute value:
715 % 0.0, 1.0, -1.0, 3.0, -3.0, 4.0, -4.0, 5.0, -5.0
716 % What I want is that
717 % 0.0 gets sort index 0
718 % 1.0 and -1.0 get sort index 1
719 % 3.0 and -3.0 get sort index 2
720 % 4.0 and -4.0 get sort index 3
721 % and so on. The array contains only absolute values, so that's
722 % not too difficult to check.
723 %
724 % Since each of the tick positions can be (uniquely) identified by
725 % its associated \pgfplots@ticknum value, I map \pgfplots@ticknum
726 % to the sort index.
727 \countdef\c@sortindex=\c@pgf@counta
728 \c@sortindex=\pgfkeysvalueof{/pgfplots/#1grid each nth passes #2 start} % this is assigned to the '0.0' gridline (if any)
729 \def\pgfplots@lasttickpos{}%
730 \pgfplotsarrayforeachungrouped\pgfplots@gridlines\as\elem{%
731 \expandafter\pgfplots@prepared@tick@pos@unpack\elem
732 \ifx\pgfplots@lasttickpos\pgfutil@empty
733 \else
734 \ifx\pgfplots@lasttickpos\pgfplots@tick
735 \else
736 \advance\c@sortindex by1
737 \fi
738 \fi
739 \expandafter\edef\csname pgfplots@#1tickpos@to@sortidx@\pgfplots@ticknum\endcsname{\the\c@sortindex}%
740 %\message{\pgfplots@ticknum\space(abs(tickpos) = \pgfplots@tick)---> sort index \csname pgfplots@#1tickpos@to@sortidx@\pgfplots@ticknum\endcsname^^J}%
741 \let\pgfplots@lasttickpos=\pgfplots@tick
742 }%
743 %
744 % unfortunately, I can't free the \pgfplots@gridlines array
745 % without extensive overhead :-(
746 \fi
747 %
748 \expandafter\let\csname b@pgfplots@#1gridline@stopmap\endcsname\relax
749 \pgfkeysgetvalue{/pgfplots/#1grid stop at #2}\pgfplots@loc@TMPa
750 \ifx\pgfplots@loc@TMPa\pgfutil@empty
751 \else
752 \edef\pgfplots@loc@TMPa{\pgfplots@loc@TMPa,}% this inserts the final comma and handles any active ':' sign (for french babel)
753 \def\pgfplots@loc@TMPb{\pgfplots@gridlines@init@stop@maps #1#2}%
754 \expandafter\pgfplots@loc@TMPb\pgfplots@loc@TMPa\pgfplots@EOI%
755 \fi
756 %
757 %
758 % Now, compute all final stop positions. Also prepare the cross
759 % dependencies between x grids and y grids here (such that there
760 % is no grid line stopping in white space)
761 %
762 \if#1x%
763 \def\pgfplots@finalize@constraints{0}% we have to wait until y stop points are known.
764 \else
765 \def\pgfplots@finalize@constraints{1}%
766 \fi
767 \pgfplots@gridlines@init@grid@stop@points@for@computethem{#1}{#2}{\pgfplots@finalize@constraints}%
768 }%
769 % #1,#2,#3 the arguments for
770 % \pgfplots@gridlines@preparation@get@current@grid@stop@point
771 \def\pgfplots@gridlines@init@grid@stop@points@for@computethem#1#2#3{%
772 %
773 \expandafter\pgfplotslistforeachungrouped\csname pgfplots@prepared@tick@positions@major@#1\endcsname\as\elem{%
774 \expandafter\pgfplots@prepared@tick@pos@unpack\elem
775 \pgfplotscoordmath{default}{parsenumber}{\pgfplots@tick}\let\pgfplots@tick=\pgfmathresult
776 \pgfplots@gridlines@preparation@get@current@grid@stop@point{#1}{#2}{\pgfplots@tick}{#3}%
777 \if1#3%
778 \pgfplots@gridlines@let{#1}{\pgfplots@tick@prepared}=\pgfplotsretval
779 \fi
780 }%
781 \expandafter\pgfplotslistforeachungrouped\csname pgfplots@prepared@tick@positions@minor@#1\endcsname\as\elem{%
782 \expandafter\pgfplots@prepared@tick@pos@unpack\elem
783 \pgfplotscoordmath{default}{parsenumber}{\pgfplots@tick}\let\pgfplots@tick=\pgfmathresult
784 \pgfplots@gridlines@preparation@get@current@grid@stop@point{#1}{#2}{\pgfplots@tick}{#3}%
785 \if1#3%
786 \pgfplots@gridlines@let{#1}{\pgfplots@tick@prepared}=\pgfplotsretval
787 \fi
788 }%
789 \expandafter\def\csname b@pgfplots@#1gridline@stopmap\endcsname{1}%
790 }
791
792 \def\pgfplots@gridlines@init@stop@maps#1#2{%
793 \pgfutil@ifnextchar\pgfplots@EOI{%
794 \pgfutil@gobble
795 }{%
796 \pgfutil@ifnextchar,{%
797 \pgfplots@gridlines@init@stop@maps@next@@#1#2%
798 }{%
799 \pgfplots@gridlines@init@stop@maps@next#1#2%
800 }%
801 }%
802 }%
803 \def\pgfplots@gridlines@init@stop@maps@next#1#2#3:#4,{%
804 \pgfplotscoordmath{default}{parsenumber}{#4}%
805 \let\pgfplots@loc@TMPa=\pgfmathresult
806 \pgfplots@gridlines@stopmap@prepare{#3}%
807 \pgfplots@gridlines@let{#1}{\pgfmathresult}=\pgfplots@loc@TMPa
808 \expandafter\def\csname b@pgfplots@#1gridline@stopmap\endcsname{1}%
809 %
810 \pgfplots@gridlines@init@stop@maps #1#2%
811 }
812 % just eat one empty comma:
813 \def\pgfplots@gridlines@init@stop@maps@next@@#1#2,{\pgfplots@gridlines@init@stop@maps #1#2}%
814 \def\pgfplots@gridlines@let#1#2=#3{%
815 \expandafter\let\csname pgfplots@#1gridline@stopmap@#2\endcsname=#3%
816 \if#1y%
817 % support symmetry:
818 % add -\pgfmathresult to the map.
819 % To disable this symmetry, use 'ygrid stop at x={0.2:4 -0.2:5}
820 % you can also use an empty value '-0.2:{}', that's also ok.
821 \expandafter\let\csname pgfplots@#1gridline@stopmap@-#2\endcsname=#3%
822 \fi
823 }%
824
825 \def\pgfplots@gridlines@stopmap@prepare@digits{2}%
826 \def\pgfplots@gridlines@stopmap@prepare#1{%
827 \begingroup
828 \pgfmathfloatparsenumber{#1}%
829 \let\pgfmathfloat@round@precision=\pgfplots@gridlines@stopmap@prepare@digits%
830 \pgfmathfloatroundzerofill\pgfmathresult
831 \pgfmath@smuggleone\pgfmathresult
832 \endgroup
833 }%
834 \def\pgfplots@gridlines@stopmap@trunc@#1.#2#3#4\relax{%
835 \def\pgfmathresult{#1.#2#3}%
836 }%
837
838 \pgfkeysdefargs{/pgfplots/smithchart@sortlt}{#1#2#3#4}{%
839 \expandafter\pgfplots@prepared@tick@pos@unpack#1%
840 \let\pgfplots@A=\pgfplots@tick
841 \expandafter\pgfplots@prepared@tick@pos@unpack#2%
842 \let\pgfplots@B=\pgfplots@tick
843 \pgfplotscoordmath{default}{if less than}{\pgfplots@A}{\pgfplots@B}{#3}{#4}%
844 }%
845
846 % initialise a lookuptable from ticknumber -> tick position (sort
847 % of an array)
848 %
849 % This is only invoked if it is needed (if 'arc
850 % limits={[index]4,[index]2}' or something like that is used, see the
851 % manual).
852 %
853 % #1 either x or y
854 % #2 either x or y
855 \def\pgfplots@gridlines@init@grid@stop@points@for@init@ticknum@lookup#1#2{%
856 \c@pgf@counta=0
857 \pgfplots@if{pgfplots@#1majorgrids}{%
858 \expandafter
859 \pgfplotslistforeachungrouped\csname pgfplots@prepared@tick@positions@major@#2\endcsname\as\elem{%
860 \expandafter\pgfplots@prepared@tick@pos@unpack\elem
861 \expandafter\let\csname pgfplots@#2tick@num@to@pos@\the\c@pgf@counta\endcsname=\pgfplots@tick
862 \advance\c@pgf@counta by1
863 }%
864 }{}%
865 \pgfplots@if{pgfplots@#1minorgrids}{%
866 \expandafter
867 \pgfplotslistforeachungrouped\csname pgfplots@prepared@tick@positions@minor@#2\endcsname\as\elem{%
868 \expandafter\pgfplots@prepared@tick@pos@unpack\elem
869 \expandafter\let\csname pgfplots@#2tick@num@to@pos@\the\c@pgf@counta\endcsname=\pgfplots@tick
870 \advance\c@pgf@counta by1
871 }%
872 }{}%
873 \expandafter\def\csname b@pgfplots@#2ticknum@to@pos@lookup\endcsname{1}%
874 }%
875 \def\pgfplots@gridlines@init@grid@stop@points@for@normalise#1\relax#2#3{%
876 \def\b@pgfplots@haslt{0}%
877 %
878 \pgfutil@in@{if <}{#1}%
879 \ifpgfutil@in@
880 % strip the white space between 'if' and '<':
881 \def\pgfplots@loc@TMPa##1if <##2\relax{\edef\entry{##1if<##2}}%
882 \expandafter\pgfplots@loc@TMPa\entry\relax
883 \def\b@pgfplots@haslt{1}%
884 \fi
885 %
886 \pgfutil@in@{if<}{#1}%
887 \ifpgfutil@in@
888 \def\b@pgfplots@haslt{1}%
889 \fi
890 %
891 \pgfutil@in@:{#1}%
892 \ifpgfutil@in@
893 \def\b@pgfplots@hascolon{1}%
894 \else
895 \def\b@pgfplots@hascolon{0}%
896 \fi
897 %
898 \if1\b@pgfplots@hascolon
899 \edef\entry{\entry\if0\b@pgfplots@haslt if<\fi}%
900 \else
901 \if1\b@pgfplots@haslt
902 \expandafter\pgfplots@gridlines@stop@at@unpack@@@\entry\relax
903 \edef\entry{\pgfplots@grid@stop@at:2if<\pgfplots@grid@stop@at@iflt}%
904 \else
905 \edef\entry{\entry:2if<}%
906 \fi%
907 \fi%
908 %
909 \pgfutil@in@{[index]}{#1}%
910 \ifpgfutil@in@
911 \if0\csname b@pgfplots@#3ticknum@to@pos@lookup\endcsname
912 \pgfplots@gridlines@init@grid@stop@points@for@init@ticknum@lookup#2#3%
913 \fi
914 \expandafter\pgfplots@gridlines@stop@at@unpack\entry\relax
915 \pgfutil@ifundefined{pgfplots@#3tick@num@to@pos@\pgfplots@grid@stop@at}{%
916 \pgfplotswarning{smithchart/no such tick}{#3}{\pgfplots@grid@stop@at}\pgfeov
917 \let\entry=\pgfutil@empty
918 }{%
919 \edef\entry{\csname pgfplots@#3tick@num@to@pos@\pgfplots@grid@stop@at\endcsname:\pgfplots@grid@stop@at@eachnth}%
920 }%
921 \fi
922 %
923 \expandafter\pgfplots@gridlines@stop@at@unpack\entry\relax
924 \pgfplotscoordmath{default}{parsenumber}\pgfplots@grid@stop@at
925 \let\pgfplots@grid@stop@at=\pgfmathresult
926 \ifx\pgfplots@grid@stop@at@iflt\pgfutil@empty
927 \else
928 \pgfplotscoordmath{default}{parsenumber}\pgfplots@grid@stop@at@iflt
929 \let\pgfplots@grid@stop@at@iflt=\pgfmathresult
930 \fi
931 \edef\entry{\pgfplots@grid@stop@at:\pgfplots@grid@stop@at@eachnth if<\pgfplots@grid@stop@at@iflt}%
932 }%
933 \def\pgfplots@gridlines@stop@at@unpack@@@#1if<#2\relax{%
934 \def\pgfplots@grid@stop@at{#1}%
935 \def\pgfplots@grid@stop@at@iflt{#2}%
936 }%
937 \def\pgfplots@gridlines@stop@at@unpack#1:#2if<#3\relax{%
938 \def\pgfplots@grid@stop@at{#1}%
939 \def\pgfplots@grid@stop@at@eachnth{#2}%
940 \def\pgfplots@grid@stop@at@iflt{#3}%
941 }%
942
943 % Returns the xtick position which should end the current arc.
944 %
945 % This is an INTERNAL preparation method. See
946 % \pgfplots@get@current@grid@stop@point for the final one.
947 %
948 % Note that arcs correspond to ygrid lines.
949 %
950 % #1 either x or y
951 % #2 either x or y
952 % #3 the value of the current grid line
953 % #4 a boolean which expands either to 0 or to 1.
954 % The \pgfplots@get@current@grid@stop@point@handle@constraints method
955 % will be invoked if and only if #4=1
956 %
957 % @POSTCONDITION On output,
958 % - \pgfplotsretval will be filled with the
959 % result. If the result is empty, no restriction is imposed.
960 % Otherwise, it contains the #2tick value at which the current #1grid shall end.
961 % The result is already processed with
962 % \pgfplotscoordmath{default}{parsenumber}{<value>}
963 % - \pgfplots@tick@prepared contains a rounded representation of #3.
964 %
965 % The method relies on the 'ygrid each nth passes x' feature, more specifically the
966 % stuff prepared by \pgfplots@gridlines@init@grid@stop@points@for
967 \def\pgfplots@gridlines@preparation@get@current@grid@stop@point#1#2#3#4{%
968 \def\pgfplotsretval{}%
969 %
970 \pgfplots@gridlines@stopmap@prepare{#3}%
971 \let\pgfplots@tick@prepared=\pgfmathresult
972 \pgfmathfloatabs@\pgfplots@tick@prepared
973 \let\pgfplots@tick@prepared@abs=\pgfmathresult
974 %
975 \pgfplotscoordmath{default}{op}{abs}{{#3}}%
976 \let\pgfplots@tick@abs=\pgfmathresult
977 %
978 % first: check the '#1grid stop at #2':
979 \expandafter\ifx\csname b@pgfplots@#1gridline@stopmap\endcsname\relax%
980 % ok. there is no such thing.
981 \else
982 % ah - process it!
983 \pgfutil@ifundefined{pgfplots@#1gridline@stopmap@\pgfplots@tick@prepared}{%
984 }{%
985 \edef\pgfplotsretval{\csname pgfplots@#1gridline@stopmap@\pgfplots@tick@prepared\endcsname}%
986 }%
987 \fi
988 %
989 \ifx\pgfplotsretval\pgfutil@empty
990 % the individual map failed. Ok, then check for the '#1grid each nth passes #2'
991 \expandafter\ifx\csname pgfplots@#1grid@stop@points\endcsname\relax
992 \else
993 % \pgfplots@ticknum is defined in this context here.
994 \pgfutil@ifundefined{pgfplots@#1tickpos@to@sortidx@\pgfplots@ticknum}{%
995 \pgfplots@warning{Sorry, I can't get the current arc limit for #1grid no \#\pgfplots@ticknum\space(value \pgfplots@tick). This seems like an internal error!?}%
996 }{%
997 % get the sort index for the current tick (which is
998 % uniquely identified by its \pgfplots@ticknum)
999 \expandafter\let\expandafter\pgfplots@k\csname pgfplots@#1tickpos@to@sortidx@\pgfplots@ticknum\endcsname
1000 %
1001 \expandafter\pgfplotslistforeachungrouped\csname pgfplots@#1grid@stop@points\endcsname\as\pgfplots@loc@TMPa{%
1002 \ifx\pgfplotsretval\pgfutil@empty
1003 % we found no final limit so far. proceed.
1004 \expandafter\pgfplots@gridlines@stop@at@unpack\pgfplots@loc@TMPa\relax
1005 \ifx\pgfplots@grid@stop@at@iflt\pgfutil@empty
1006 \pgfplots@loop@CONTINUEtrue
1007 \else
1008 \pgfplotscoordmath{default}{if less than}{\pgfplots@tick@abs}{\pgfplots@grid@stop@at@iflt}{%
1009 \pgfplots@loop@CONTINUEtrue
1010 }{%
1011 \pgfplots@loop@CONTINUEfalse
1012 }%
1013 \fi
1014 %
1015 \ifpgfplots@loop@CONTINUE
1016 \pgfplotsmathmodint\pgfplots@k\pgfplots@grid@stop@at@eachnth
1017 \ifnum\pgfmathresult=0
1018 \c@pgf@counta=\pgfplots@k
1019 \divide\c@pgf@counta by\pgfplots@grid@stop@at@eachnth\relax
1020 \edef\pgfplots@k{\the\c@pgf@counta}%
1021 \else
1022 % found the final limit.
1023 %
1024 % Now, check the constraints which couple
1025 % X and Y.
1026 \let\pgfplotsretval=\pgfplots@grid@stop@at
1027 \if1#4%
1028 \pgfplots@get@current@grid@stop@point@handle@constraints #1#2{#3}%
1029 \fi
1030 \fi
1031 \fi
1032 \fi
1033 }%
1034 }%
1035 \fi
1036 \fi
1037 \ifx\pgfplotsretval\pgfutil@empty
1038 \else
1039 \expandafter\let\csname pgfplots@final@stop@point@for@#1tick@\pgfplots@tick@prepared\endcsname=\pgfplotsretval
1040 %\message{#1 grid line: storing end value for '#3' END[\pgfplots@tick@prepared] = \pgfplotsretval.^^J}%
1041 \fi
1042 }%
1043
1044 % PRECONDITION
1045 % \pgfplotsretval contains a non-zero constraint for the ygrid at #1.
1046 %
1047 % POSTCONDITION
1048 % either \pgfplotsretval is unchanged, or it is reset to
1049 % \pgfutil@empty if constraints are violated.
1050 %
1051 % The constraints are ONLY effective if BOTH, incomplete x- and y grid
1052 % lines are in effect. In that case, it should never happen that a
1053 % single grid line ends in a dead-end somewhere in white space.
1054 %
1055 % I enforce two constraints which apply only to ygrid to fix this
1056 % issue (this may be improved later).
1057 %
1058 % The idea is simple:
1059 % 1. suppose the grid line 'x=1' stops at 'y=5'.
1060 % Suppose further that the y grid line 'y=0.95' should stop at 'x=1'.
1061 % Is that acceptable? Yes, because |y| < 5.
1062 % Now, suppose an y grid line with |y| > 5 should stop at 'x=1'.
1063 % Is this allowed? NO! Because it would become a dead end since
1064 % the 'x=1' line ends at 'y=5'!
1065 %
1066 % So, whenever we consider ygrids and stop point candidates "x=X",
1067 % acquire the value Q where the x (!) grid line "x=X" stops.
1068 % If |y| > Q, the candidate "x=X" is rejected.
1069 %
1070 % 2. There might still be the case that x grid lines have dead-ends.
1071 % The current solution applies the idea first to all y grid lines,
1072 % and once the y grid lines are ready, it applies the same idea to
1073 % x grid lines.
1074 %
1075 % Uncomment the routine(s) and run the test cases to see what happens.
1076 \def\pgfplots@get@current@grid@stop@point@handle@constraints#1#2#3{%
1077 \ifx\pgfplotsretval\pgfutil@empty
1078 \else
1079 \pgfplots@gridlines@stopmap@prepare{\pgfplotsretval}%
1080 \let\pgfplots@loc@TMPa=\pgfmathresult
1081 %
1082 %\message{checking ending '#1=#3' at '#2=\pgfplotsretval'. '#2=\pgfplots@loc@TMPa' stops}%
1083 \pgfutil@ifundefined{pgfplots@final@stop@point@for@#2tick@\pgfplots@loc@TMPa}{%
1084 % no constraint. Ok.
1085 %\message{ nowhere. No constraint.^^J}%
1086 }{%
1087 %\message{ at \pgfplots@loc@TMPa. Feasible: }%
1088 % Oh, a constraint. That means
1089 % further work.
1090 \expandafter\let\expandafter\pgfplots@loc@TMPa\csname pgfplots@final@stop@point@for@#2tick@\pgfmathresult\endcsname
1091 \pgfplotscoordmath{default}{op}{abs}{{#3}}%
1092 \pgfplotscoordmath{default}{if less than}{\pgfmathresult}{\pgfplots@loc@TMPa}{%
1093 % ok, we can use the found
1094 % stop value.
1095 %\message{YES.^^J}%
1096 }{%
1097 %\message{NO.^^J}%
1098 % no, the stop value is
1099 % invalid; it would stop in
1100 % white space!
1101 \let\pgfplotsretval=\pgfutil@empty
1102 }%
1103 }%
1104 \fi
1105 }%
1106
1107 % Returns the xtick position which should end the current arc.
1108 %
1109 % Note that arcs correspond to ygrid lines.
1110 %
1111 % #1 either x or y
1112 % #2 either x or y
1113 % #3 the value of the current grid line
1114 %
1115 % @POSTCONDITION On output, \pgfplotsretval will be filled with the
1116 % result. If the result is empty, no restriction is imposed.
1117 % Otherwise, it contains the #2tick value at which the current #1grid shall end.
1118 % The result is already processed with
1119 % \pgfplotscoordmath{default}{parsenumber}{<value>}
1120 %
1121 % The method relies on the 'ygrid each nth passes x' feature, more specifically the
1122 % stuff prepared by \pgfplots@gridlines@init@grid@stop@points@for
1123 %
1124 % Note that all work has already been done by
1125 % \pgfplots@gridlines@init@grid@stop@points@for. We only need to query
1126 % the result at this point.
1127 % @see \pgfplots@gridlines@init@grid@stop@points@for
1128 % @see \pgfplots@gridlines@preparation@get@current@grid@stop@point
1129 \def\pgfplots@get@current@grid@stop@point#1#2#3{%
1130 \def\pgfplotsretval{}%
1131 %
1132 % check the '#1grid stop at #2':
1133 \expandafter\ifx\csname b@pgfplots@#1gridline@stopmap\endcsname\relax%
1134 % ok. there is no such thing.
1135 \else
1136 %
1137 \pgfplots@gridlines@stopmap@prepare{#3}%
1138 \let\pgfplots@tick@prepared=\pgfmathresult
1139 \pgfmathfloatabs@\pgfplots@tick@prepared
1140 \let\pgfplots@tick@prepared@abs=\pgfmathresult
1141 %
1142 % ah - process it!
1143 \pgfutil@ifundefined{pgfplots@#1gridline@stopmap@\pgfplots@tick@prepared}{%
1144 \let\pgfplotsretval\pgfutil@empty
1145 }{%
1146 \edef\pgfplotsretval{\csname pgfplots@#1gridline@stopmap@\pgfplots@tick@prepared\endcsname}%
1147 }%
1148 \fi
1149 %
1150 }%
1151
1152
1153 \def\pgfplots@smithchart@draw@xcircle#1{%
1154 \pgfplotscoordmath{default}{one}%
1155 \let\pgfplots@loc@TMPa=\pgfmathresult
1156 %
1157 \pgfplotscoordmath{default}{parsenumber}{#1}%
1158 \let\pgfplots@x=\pgfmathresult
1159 %
1160 \pgfplotscoordmath{default}{op}{add}{{\pgfplots@loc@TMPa}{\pgfplots@x}}%
1161 \let\pgfplots@radius@inverse=\pgfmathresult
1162 \pgfplotscoordmath{default}{op}{reciprocal}{{\pgfmathresult}}%
1163 \let\pgfplots@radius=\pgfmathresult
1164 \pgfplotscoordmath{default}{op}{multiply}{{\pgfmathresult}{\pgfplots@x}}%
1165 \pgfplotscoordmath{default}{tofixed}{\pgfmathresult}%
1166 \let\pgfplots@center=\pgfmathresult
1167 %
1168 \pgfplotscoordmath{default}{tofixed}{\pgfplots@radius}%
1169 \let\pgfplots@radius=\pgfmathresult
1170 %
1171 \pgfplotscoordmath{default}{tofixed}{\pgfplots@radius@inverse}%
1172 \let\pgfplots@radius@inverse=\pgfmathresult
1173 %
1174 % This here would suffice in case 'xgrid each nth passes y={}':
1175 % \pgfpathellipse
1176 % {\pgfplotsqpointxy@smithchart@canvas{\pgfplots@center}{0}}
1177 % {\pgfplotsqpointxy@smithchart@canvas{\pgfplots@radius}{0}}
1178 % {\pgfplotsqpointxy@smithchart@canvas{0}{\pgfplots@radius}}%
1179 %
1180 % but we also check for the 'xgrid each nth passes y' feature:
1181 \pgfplots@get@current@grid@stop@point xy{\pgfplots@x}%
1182 \let\pgfplots@arc@ends@at@y@arc@value\pgfplotsretval%
1183 %
1184 \ifx\pgfplots@arc@ends@at@y@arc@value\pgfutil@empty
1185 % Ok. There is no specific end point -- simply use the
1186 % (1,0) point (i.e. draw the full circle).
1187 %
1188 \pgfmathadd@{\pgfplots@center}{\pgfplots@radius}%
1189 \let\pgfplots@start=\pgfmathresult%
1190 \def\pgfplots@startim{0}%
1191 \def\pgfplots@startangle{0}%
1192 \let\pgfplots@end=\pgfplots@start
1193 \let\pgfplots@endim=\pgfplots@startim
1194 \def\pgfplots@endangle{360}%
1195 \else
1196 % Ok. The arc should end before it reaches the (1,0)
1197 % point. Determine the exact position and the
1198 % corresponding arc end angle.
1199 %
1200 % In general, the intersection between the circle for
1201 % fixed x=A and fixed y=B is given by
1202 %
1203 % p + j * q = (A + j * B -1 ) / ( A + j*B +1)
1204 % see http://www.siart.de/lehre/tutorien.xhtml#smishort
1205 \pgfplotscoordmath{default}{one}%
1206 \let\pgfplots@one=\pgfmathresult
1207 \pgfplotscoordmath{default}{parsenumber}{-1}%
1208 \let\pgfplots@mone=\pgfmathresult
1209 \pgfplotscoordmath{default}{op}{add}{{\pgfplots@x}{\pgfplots@mone}}%
1210 \let\pgfplots@A@mone=\pgfmathresult
1211 \pgfplotscoordmath{default}{op}{add}{{\pgfplots@x}{\pgfplots@one}}%
1212 \let\pgfplots@A@one=\pgfmathresult
1213 % oh - we should only draw a partial arc.
1214 % Well, then compute its end point and the
1215 % corresponding end angle.
1216 \pgfplotscoordmathcomplexdivision
1217 {\pgfplots@A@mone}{\pgfplots@arc@ends@at@y@arc@value}%
1218 {\pgfplots@A@one}{\pgfplots@arc@ends@at@y@arc@value}%
1219 \let\pgfplots@start=\pgfmathresult
1220 \let\pgfplots@startim=\pgfmathresultim
1221 \pgfplotscoordmath{default}{tofixed}{\pgfplots@start}%
1222 \let\pgfplots@start=\pgfmathresult
1223 \pgfplotscoordmath{default}{tofixed}{\pgfplots@startim}%
1224 \let\pgfplots@startim=\pgfmathresult
1225 %
1226 \pgfplots@compute@angle@of@point@in@circle\pgfplots@start\pgfplots@startim{\pgfplots@center}{\pgfplots@radius}{\pgfplots@radius@inverse}%
1227 \let\pgfplots@startangle=\pgfmathresult
1228 \pgfmathsubtract@{360}{\pgfplots@startangle}%
1229 \let\pgfplots@endangle=\pgfmathresult
1230 \let\pgfplots@end=\pgfplots@start
1231 \edef\pgfplots@endim{-\pgfplots@startim}%
1232 \ifdim\pgfplots@startangle pt>\pgfplots@endangle pt
1233 \let\pgfplots@loc@TMPa=\pgfplots@startangle
1234 \let\pgfplots@startangle=\pgfplots@endangle
1235 \let\pgfplots@endangle=\pgfplots@loc@TMPa
1236 \fi
1237 \fi
1238 %
1239 %\message{X grid line \#\csname pgfplots@ticknum\endcsname \space at '#1': center = (\pgfplots@center,0); radius = \pgfplots@radius\space(start angle \pgfplots@startangle, end angle = \pgfplots@endangle; stops at y = \pgfplots@arc@ends@at@y@arc@value).^^J}%
1240 %
1241 % Now, compute the arc.
1242 %
1243 % first, compute the absolute x/y radii:
1244 \pgf@xa=\pgfplots@radius\pgf@xx
1245 \pgf@xb=\pgfplots@radius\pgf@yy
1246 \edef\pgfplots@mirror@sign{\ifpgfplots@smithchart@mirrored -\fi}%
1247 \pgfpathmoveto{\pgfplotsqpointxy@smithchart@canvas{\pgfplots@start}{\pgfplots@startim}}%
1248 % note that the case startangle > endangle is
1249 % automatically correct; patharc handles that.
1250 %\edef\pgfplots@loc@TMPa{{\pgfplots@startangle}{\pgfplots@endangle}{\pgfplots@mirror@sign\the\pgf@xa\space and \the\pgf@xb}}%
1251 %\expandafter\pgfpatharc\pgfplots@loc@TMPa
1252 %
1253 % prefer \pgfpatharctoprecomputed. It is faster and more accurate
1254 \edef\pgfplots@loc@TMPa{%
1255 {\noexpand\pgfplotsqpointxy@smithchart@canvas{\pgfplots@center}{0}}%
1256 {\pgfplots@startangle}%
1257 {\pgfplots@endangle}%
1258 {\noexpand\pgfplotsqpointxy@smithchart@canvas{\pgfplots@end}{\pgfplots@endim}}%
1259 {\pgfplots@mirror@sign\the\pgf@xa}%
1260 {\the\pgf@xb}%
1261 {\pgfplots@mirror@sign\pgfplots@smithchart@axis@ratioxy}%
1262 {\pgfplots@mirror@sign\pgfplots@smithchart@axis@ratioyx}%
1263 }%
1264 \expandafter\pgfpatharctoprecomputed\pgfplots@loc@TMPa
1265 }
1266
1267 \def\pgfplots@smithchart@draw@yarc#1{%
1268 \pgfplotscoordmath{default}{parsenumber}{#1}%
1269 \let\pgfplots@y\pgfmathresult
1270 \pgfplotscoordmath{default}{op}{abs}{{\pgfplots@y}}%
1271 \pgfplotscoordmath{default}{if less than}{\pgfmathresult}{\pgfplots@almost@zero@thresh}{%
1272 \pgfpathmoveto{\pgfplotsqpointxy@smithchart@canvas{-1}{0}}%
1273 \pgfpathlineto{\pgfplotsqpointxy@smithchart@canvas{1}{0}}%
1274 }{%
1275 \pgfplotscoordmath{default}{op}{reciprocal}{{\pgfplots@y}}%
1276 \pgfplotscoordmath{default}{tofixed}{\pgfmathresult}%
1277 \let\pgfplots@signedradius=\pgfmathresult
1278 %
1279 \pgfplotscoordmath{default}{tofixed}{\pgfplots@y}%
1280 \ifdim\pgfplots@signedradius pt<0pt
1281 \def\pgfplots@radius@sign{-}%
1282 \edef\pgfplots@radius@inverse{-\pgfmathresult}%
1283 \edef\pgfplots@radius{-\pgfplots@signedradius}%
1284 \else
1285 \def\pgfplots@radius@sign{}%
1286 \edef\pgfplots@radius@inverse{\pgfmathresult}%
1287 \let\pgfplots@radius=\pgfplots@signedradius
1288 \fi
1289 % this here is the correct, complete circle -- together
1290 % with a clip path, you get what you want:
1291 %\pgfpathellipse
1292 % {\pgfplotsqpointxy@smithchart@canvas{1}{\pgfplots@signedradius}}
1293 % {\pgfplotsqpointxy@smithchart@canvas{\pgfplots@signedradius}{0}}
1294 % {\pgfplotsqpointxy@smithchart@canvas{0}{\pgfplots@signedradius}}%
1295 % But I only want the arc (probably stopped earlier to
1296 % improve qualtity of the chart)
1297 %
1298 % compute start point for the arc.
1299 %
1300 % To do so, we need to compute the intersection between
1301 % the circle for fixed x=0 and the circle for y=#1.
1302 %
1303 % In general, the intersection between the circle for
1304 % fixed x=A and fixed y=B is given by
1305 %
1306 % p + j * q = (A + j * B -1 ) / ( A + j*B +1)
1307 % see http://www.siart.de/lehre/tutorien.xhtml#smishort
1308 %
1309 % inserting A = 0 and B = #1 yields the result
1310 % p=\pgfplots@start
1311 % q=\pgfplots@startim
1312 % as follows:
1313 \pgfplotscoordmath{default}{one}%
1314 \let\pgfplots@one=\pgfmathresult
1315 \pgfplotscoordmath{default}{parsenumber}{-1}%
1316 \let\pgfplots@mone=\pgfmathresult
1317 \pgfplotscoordmathcomplexdivision{\pgfplots@mone}{\pgfplots@y}{\pgfplots@one}{\pgfplots@y}%
1318 \let\pgfplots@start=\pgfmathresult
1319 \let\pgfplots@startim=\pgfmathresultim
1320 \pgfplotscoordmath{default}{tofixed}{\pgfplots@start}%
1321 \let\pgfplots@start=\pgfmathresult
1322 \pgfplotscoordmath{default}{tofixed}{\pgfplots@startim}%
1323 \let\pgfplots@startim=\pgfmathresult
1324 %
1325 \pgfplots@compute@angle@of@point@in@circle\pgfplots@start\pgfplots@startim{1}{\pgfplots@signedradius}{\pgfplots@radius@inverse}%
1326 \let\pgfplots@startangle=\pgfmathresult
1327 %
1328 %
1329 % compute end angle.
1330 \pgfplots@get@current@grid@stop@point yx{\pgfplots@y}%
1331 \let\pgfplots@arc@ends@at@x@circle@value\pgfplotsretval%
1332 %
1333 \ifx\pgfplots@arc@ends@at@x@circle@value\pgfutil@empty
1334 % Ok. There is no specific end point -- simply use the
1335 % (1,0) point (i.e. draw the full arc).
1336 %
1337 % The "0 degree" angle in my circles is in the direction
1338 % of (1,0) .
1339 \ifdim\pgfplots@startim pt>0pt
1340 % ok; this arc belongs to the upper hemisphere.
1341 \def\pgfplots@endangle{270}%
1342 \else
1343 % ok; this arc belongs to the lower hemisphere.
1344 \def\pgfplots@endangle{90}%
1345 \fi
1346 \def\pgfplots@end{1}%
1347 \def\pgfplots@endim{0}%
1348 \else
1349 % Ok. The arc should end before it reaches the (1,0)
1350 % point. Determine the exact position and the
1351 % corresponding arc end angle.
1352 \pgfplotscoordmath{default}{op}{add}{{\pgfplots@arc@ends@at@x@circle@value}{\pgfplots@mone}}%
1353 \let\pgfplots@A@mone=\pgfmathresult
1354 \pgfplotscoordmath{default}{op}{add}{{\pgfplots@arc@ends@at@x@circle@value}{\pgfplots@one}}%
1355 \let\pgfplots@A@one=\pgfmathresult
1356 % oh - we should only draw a partial arc.
1357 % Well, then compute its end point and the
1358 % corresponding end angle.
1359 \pgfplotscoordmathcomplexdivision{\pgfplots@A@mone}{\pgfplots@y}{\pgfplots@A@one}{\pgfplots@y}%
1360 \let\pgfplots@end=\pgfmathresult
1361 \let\pgfplots@endim=\pgfmathresultim
1362 \pgfplotscoordmath{default}{tofixed}{\pgfplots@end}%
1363 \let\pgfplots@end=\pgfmathresult
1364 \pgfplotscoordmath{default}{tofixed}{\pgfplots@endim}%
1365 \let\pgfplots@endim=\pgfmathresult
1366 %
1367 \pgfplots@compute@angle@of@point@in@circle\pgfplots@end\pgfplots@endim{1}{\pgfplots@signedradius}{\pgfplots@radius@inverse}%
1368 \let\pgfplots@endangle=\pgfmathresult
1369 \fi
1370 %
1371 %
1372 %
1373 % Now, compute the arc.
1374 %
1375 % first, compute the absolute x/y radii:
1376 %
1377 % Note that for small y (like y=0.01), the arc is almost a
1378 % straight line. Consequently, the ellipsis radius will be much larger
1379 % than 16000, violating TeX's number range.
1380 %
1381 % To avoid that, I clip it to the highest allowed value.
1382 % The final radius is
1383 % \pgfplots@radius * \pgf@xx and \pgfplots@radius * \pgf@yy.
1384 % the clipped value thus needs to respect the magnitude of \pgf@xx and \pgf@yy.
1385 \ifdim\pgfplots@radius pt<\pgfplots@smithchart@axis@max@xradius@for@ycircle pt
1386 \let\pgfplots@radius@x\pgfplots@radius
1387 \else
1388 \let\pgfplots@radius@x=\pgfplots@smithchart@axis@max@xradius@for@ycircle
1389 \fi
1390 \ifdim\pgfplots@radius pt<\pgfplots@smithchart@axis@max@yradius@for@ycircle pt
1391 \let\pgfplots@radius@y\pgfplots@radius
1392 \else
1393 \let\pgfplots@radius@y=\pgfplots@smithchart@axis@max@yradius@for@ycircle
1394 \fi
1395 %\message{Y grid line \#\csname pgfplots@ticknum\endcsname\space at '#1': center = (1,\pgfplots@signedradius); signedradius = \pgfplots@signedradius\space clipped radii = \pgfplots@radius@x*\the\pgf@xx\space and \pgfplots@radius@y*\the\pgf@yy\space ( start angle \pgfplots@startangle, end angle \pgfplots@endangle, arc limit: \ifx\pgfplots@arc@ends@at@x@circle@value\pgfutil@empty NONE\else \pgfplots@arc@ends@at@x@circle@value\fi)^^J}%
1396 \pgf@xa=\pgfplots@radius@x\pgf@xx
1397 \pgf@xb=\pgfplots@radius@y\pgf@yy
1398 \edef\pgfplots@mirror@sign{\ifpgfplots@smithchart@mirrored -\fi}%
1399 \pgfpathmoveto{\pgfplotsqpointxy@smithchart@canvas{\pgfplots@start}{\pgfplots@startim}}%
1400 % note that the case startangle > endangle is
1401 % automatically correct; patharc handles that.
1402 %\edef\pgfplots@loc@TMPa{{\pgfplots@startangle}{\pgfplots@endangle}{\pgfplots@mirror@sign\the\pgf@xa\space and \the\pgf@xb}}%
1403 %\expandafter\pgfpatharc\pgfplots@loc@TMPa
1404 %
1405 % prefer \pgfpatharctoprecomputed. It is faster and more accurate
1406 \ifdim\pgfplots@startangle pt>\pgfplots@endangle pt
1407 \let\pgfplots@loc@TMPa=\pgfplots@startangle
1408 % \let\pgfplots@startangle=\pgfplots@endangle
1409 % \let\pgfplots@endangle=\pgfplots@loc@TMPa
1410 \fi
1411 \edef\pgfplots@loc@TMPa{%
1412 {\noexpand\pgfplotsqpointxy@smithchart@canvas{1}{\pgfplots@radius@sign\pgfplots@radius@y}}%
1413 {\pgfplots@startangle}%
1414 {\pgfplots@endangle}%
1415 {\noexpand\pgfplotsqpointxy@smithchart@canvas{\pgfplots@end}{\pgfplots@endim}}%
1416 {\pgfplots@mirror@sign\the\pgf@xa}%
1417 {\the\pgf@xb}%
1418 {\pgfplots@mirror@sign\pgfplots@smithchart@axis@ratioxy}%
1419 {\pgfplots@mirror@sign\pgfplots@smithchart@axis@ratioyx}%
1420 }%
1421 \expandafter\pgfpatharctoprecomputed\pgfplots@loc@TMPa
1422 }%
1423 }
1424
1425 \def\pgfplots@drawgridlines@onorientedsurf@fromto@smithchart#1{%
1426 \if x\pgfplotspointonorientedsurfaceA
1427 \pgfplots@smithchart@draw@xcircle{#1}%
1428 \else
1429 \pgfplots@smithchart@draw@yarc{#1}%
1430 \fi
1431 }%
1432
1433 % Given a circle with center point (#3,#4), we search for the angle
1434 % of the point (#1,#2). The point is expected to be on the circle.
1435 % The resulting angle is returned in \pgfmathresult
1436 %
1437 % #1 x coordinate of the point for which an angle is searched
1438 % #2 y coordinate of the point for which an angle is searched
1439 % #3 x coordinate of the circle's center point
1440 % #4 y coordinate of the circle's center point
1441 % #5 is either empty or it is expected to contain the inverse radius, 1/r
1442 % this information is available in my context, so I don't recompute
1443 % it.
1444 %
1445 % All coordinates are expected in standard TeX precision (numbers
1446 % without unit)
1447 \def\pgfplots@compute@angle@of@point@in@circle#1#2#3#4#5{%
1448 %
1449 % 1. compute diff vector from center=(1,\pgfplots@signedradius) to start:
1450 \pgfmathsubtract@{#1}{#3}%
1451 \let\pgfplots@D\pgfmathresult
1452 \pgfmathsubtract@{#2}{#4}%
1453 \let\pgfplots@Dim\pgfmathresult
1454 %
1455 % 2. compute the start angle.
1456 % It is related to the angle between the point (1,0) and
1457 % diff, which, in turn is given by
1458 % < (1,0), (D,Dim) > = cos(alpha) ||(D,Dim)||
1459 % < (1,0), (D,Dim) > = D
1460 %
1461 % Note that ||(D,Dim)|| = r, the radius of the involved circle
1462 % around (#3,#4). If 1/r is already available, use it! Saves a lot
1463 % of time.
1464 %
1465 \def\pgfplots@loc@TMPa{#5}%
1466 \ifx\pgfplots@loc@TMPa\pgfutil@empty
1467 \pgfmathveclen\pgfplots@D\pgfplots@Dim
1468 \let\pgfplots@veclen=\pgfmathresult
1469 \pgfmathreciprocal@\pgfplots@veclen
1470 \let\pgfplots@inverseveclen=\pgfmathresult
1471 \else
1472 % oh, good -- we already have 1/||(D,Dim)||. Use it.
1473 \def\pgfplots@inverseveclen{#5}%
1474 %\message{using already available inverseveclen '#5' }%
1475 \fi
1476 \pgfmathmultiply@{\pgfplots@D}{\pgfplots@inverseveclen}%
1477 %\message{D= (\pgfplots@D,\pgfplots@Dim).. acos(\pgfplots@D * \pgfplots@inverseveclen) = acos(\pgfmathresult)}%
1478 \pgfmathacos@{\pgfmathresult}% the '-' comes from D<0 .
1479 %\message{= \pgfmathresult^^J}%
1480 \let\pgfplots@tmpangle\pgfmathresult%
1481 % ok. tmpangle is per definition less than 180; it is the
1482 % smaller angle between (1,0) and (D,Dim).
1483 %
1484 % compute the angle relative to (1,0):
1485 \ifdim\pgfplots@Dim pt<0pt
1486 \pgfmathiftrigonometricusesdeg{%
1487 \pgfmathsubtract@{360}{\pgfplots@tmpangle}%
1488 }{%
1489 \pgfmathsubtract@{6.28318530717959}{\pgfplots@tmpangle}%
1490 }%
1491 \fi
1492 }%
1493
1494 \def\pgfplots@drawaxis@innerlines@onorientedsurf@smithchart#1#2#3{%
1495 \if2\csname pgfplots@#1axislinesnum\endcsname
1496 \draw[/pgfplots/every inner #1 axis line,%
1497 decorate,%
1498 #1discont,%
1499 decoration={pre length=\csname #1disstart\endcsname, post length=\csname #1disend\endcsname}]
1500 \pgfextra
1501 \csname pgfplotspointonorientedsurfaceabsetupforset#3\endcsname{\csname pgfplots@logical@ZERO@#3\endcsname}{2}%
1502 \if#1x%
1503 \pgfplotspointonorientedsurfaceabsetupfor{#2}{#1}{\pgfplotspointonorientedsurfaceN}%
1504 \pgfplots@drawgridlines@onorientedsurf@fromto{0}%
1505 \else
1506 \pgfpathmoveto{\pgfplotspointonorientedsurfaceab{\csname pgfplots@#1min\endcsname}{\csname pgfplots@logical@ZERO@#2\endcsname}}%
1507 \pgfpathlineto{\pgfplotspointonorientedsurfaceab{\csname pgfplots@#1max\endcsname}{\csname pgfplots@logical@ZERO@#2\endcsname}}%
1508 \fi
1509 \endpgfextra
1510 ;
1511 \fi
1512 }%
1513 \def\pgfplots@drawaxis@outerlines@separate@onorientedsurf@smithchartaxis#1#2{%
1514 \if2\csname pgfplots@#1axislinesnum\endcsname
1515 % centered axis lines handled elsewhere.
1516 \else
1517 \scope[/pgfplots/every outer #1 axis line,
1518 #1discont,decoration={pre length=\csname #1disstart\endcsname, post length=\csname #1disend\endcsname}]
1519 \if#1x
1520 \draw decorate {
1521 \pgfextra
1522 % exchange roles of A <-> B axes:
1523 \pgfplotspointonorientedsurfaceabsetupfor{#2}{#1}{\pgfplotspointonorientedsurfaceN}%
1524 \pgfplots@drawgridlines@onorientedsurf@fromto{0}%
1525 \endpgfextra
1526 };
1527 \else
1528 \pgfplots@ifaxisline@B@onorientedsurf@should@be@drawn{0}{%
1529 \draw decorate {
1530 \pgfextra
1531 % exchange roles of A <-> B axes:
1532 \pgfplotspointonorientedsurfaceabsetupfor{#2}{#1}{\pgfplotspointonorientedsurfaceN}%
1533 \pgfplots@drawgridlines@onorientedsurf@fromto{\csname pgfplots@#2min\endcsname}%
1534 \endpgfextra
1535 };
1536 }{}%
1537 %--------------------------------------------------
1538 % \pgfplots@ifaxisline@B@onorientedsurf@should@be@drawn{1}{%
1539 % \draw decorate {
1540 % \pgfextra
1541 % % exchange roles of A <-> B axes:
1542 % \pgfplotspointonorientedsurfaceabsetupfor{#2}{#1}{\pgfplotspointonorientedsurfaceN}%
1543 % \pgfplots@drawgridlines@onorientedsurf@fromto{\csname pgfplots@#2max\endcsname}%
1544 % \endpgfextra
1545 % };
1546 % }{}%
1547 %--------------------------------------------------
1548 \fi
1549 \endscope
1550 \fi
1551 }%
1552
1553 \def\pgfplots@BB@for@plotbox@get@unit@scales@for@limits@smithchart#1#2#3{%
1554 % In a smith chart, the size of the image is unrelated to the
1555 % involved data limits.
1556 %
1557 % The factor 2 is because we want to fit the DIAMETER into the
1558 % prescribed dimensions, not just the radius.
1559 \def\pgfmathresult{2}%
1560 \let#1=\pgfmathresult
1561 \let#2=\pgfmathresult
1562 \def#3{1}%
1563 }%
1564
1565 \def\pgfplots@handle@invalid@range@defaultlimits@smithchart{%
1566 \pgfplotscoordmath{x}{parsenumber}{0}%
1567 \global\let\pgfplots@xmin=\pgfmathresult
1568 \pgfplotscoordmath{x}{parsenumber}{16000}%
1569 \global\let\pgfplots@xmax=\pgfmathresult
1570 \global\let\pgfplots@data@xmin=\pgfplots@xmin
1571 \global\let\pgfplots@data@xmax=\pgfplots@xmax
1572 %
1573 \pgfplotscoordmath{y}{parsenumber}{0}%
1574 \global\let\pgfplots@ymin=\pgfmathresult
1575 \pgfplotscoordmath{y}{parsenumber}{16000}%
1576 \global\let\pgfplots@ymax=\pgfmathresult
1577 \global\let\pgfplots@data@ymin=\pgfplots@ymin
1578 \global\let\pgfplots@data@ymax=\pgfplots@ymax
1579 \pgfplotsset{enlargelimits=false}%
1580 }
1581
1582 \let\pgfplots@set@default@size@options@standard=\pgfplots@set@default@size@options
1583 \def\pgfplots@set@default@size@options@smithchart{%
1584 \pgfplots@set@default@size@options@standard
1585 \pgfplotsset{smithchart ticks by size={\pgfkeysvalueof{/pgfplots/width}}{\pgfkeysvalueof{/pgfplots/height}}}%
1586 %
1587 \if1\b@pgfplots@smithchart@defaultticks@x
1588 \if1\b@pgfplots@smithchart@defaultticks@y
1589 \pgfplotsset{default smithchart xytick}%
1590 \fi
1591 \fi
1592 }
1593 \def\pgfplots@assign@default@tick@foraxis@smithchart#1{%
1594 % do nothing here. I don't know the algorithm yet... but for
1595 % smithcharts, it may be sufficient to simply predefine several
1596 % sets of ticks, depending on the final size.
1597 %
1598 % This is realized in
1599 % \pgfplots@set@default@size@options@smithchart (which is invoked
1600 % before the ticks are processed).
1601 \pgfplots@determinedefaultvalues@needs@check@uniformtickfalse
1602 \expandafter\let\csname pgfplots@tick@distance@#1\endcsname=\pgfutil@empty
1603 %
1604 \pgfplotsset{default smithchart #1tick}%
1605 % ok, I expect the '#1tick' key to be set now. Process it.
1606 % Note that the earlier processing of pgfplots has been bypassed
1607 % at this point -- we need to preprocess the tick list *here*:
1608 \expandafter\let\expandafter\pgfplots@loc@TMPa\csname pgfplots@#1tick\endcsname
1609 \expandafter\pgfplots@assign@default@tick@foraxis@smithchart@\expandafter{\pgfplots@loc@TMPa}%
1610 \expandafter\let\csname pgfplots@#1tick\endcsname=\pgfplotsretval
1611 %
1612 \pgfkeysgetvalue{/pgfplots/minor #1tick}\pgfplots@loc@TMPa
1613 \ifx\pgfplots@loc@TMPa\pgfutil@empty
1614 \else
1615 \expandafter\pgfplots@assign@default@tick@foraxis@smithchart@\expandafter{\pgfplots@loc@TMPa}%
1616 \pgfkeyslet{/pgfplots/minor #1tick}\pgfplotsretval
1617 \fi
1618 %
1619 }%
1620 % #1: a \foreach list
1621 % on output, \pgfplotsretval contains a parsed list of positions
1622 \def\pgfplots@assign@default@tick@foraxis@smithchart@#1{%
1623 \pgfplotsapplistXXglobalnewempty
1624 \gdef\pgfplots@loc@TMPd{1}%
1625 \foreach \pgfplots@loc@TMPb in {#1} {%
1626 \ifx\pgfplots@loc@TMPb\pgfutil@empty
1627 \else
1628 \pgfplotscoordmath{default}{parsenumber}{\pgfplots@loc@TMPb}%
1629 \pgfplotscoordmath{default}{tofixed}{\pgfmathresult}% per convention...
1630 \edef\pgfmathresult{\if0\pgfplots@loc@TMPd,\fi\pgfmathresult}%
1631 \gdef\pgfplots@loc@TMPd{0}%
1632 \expandafter\pgfplotsapplistXXglobalpushback\expandafter{\pgfmathresult}%
1633 \fi
1634 }%
1635 \pgfplotsapplistXXgloballet\pgfplotsretval
1636 \pgfplotsapplistXXglobalclear
1637 }%
1638
1639 \let\pgfplots@show@ticklabel@@orig=\pgfplots@show@ticklabel@
1640 \def\pgfplots@show@ticklabel@@smithchart#1#2{%
1641 \def\pgfmathresult{#2}%
1642 \if#1x%
1643 \ifdim#2pt>360pt
1644 \pgfmath@basic@mod@{#2}{360}%
1645 \fi
1646 \fi
1647 \def\pgfplots@loc@TMPa{\pgfplots@show@ticklabel@@orig{#1}}%
1648 \expandafter\pgfplots@loc@TMPa\expandafter{\pgfmathresult}%
1649 }%
1650
1651 \def\pgfplots@xtick@check@tickshow@smithchart{%
1652 \pgfplots@tickshowtrue
1653 }
1654 \def\pgfplots@ytick@check@tickshow@smithchart{%
1655 \pgfplots@tickshowtrue
1656 }
1657
1658 \let\pgfplots@limits@ready@orig=\pgfplots@limits@ready
1659 \def\pgfplots@limits@ready@smithchart{%
1660 \pgfplots@limits@ready@orig
1661 %
1662 % Avoid tick labels at upper *and* lower angle range if both are the
1663 % same:
1664 \pgfmath@basic@sin@{\pgfplots@xmin}%
1665 \let\pgfplots@loc@TMPa=\pgfmathresult
1666 \pgfmath@basic@sin@{\pgfplots@xmax}%
1667 \pgfplotsmath@ifapproxequal@dim
1668 {\pgfmathresult pt}{\pgfplots@loc@TMPa pt}%
1669 {0.002pt}
1670 {%
1671 \def\pgfplots@xtick@disable@last@tick{1}%
1672 }{%
1673 }%
1674 }%
1675
1676 \def\smithchart{\smithchartaxis}
1677 \def\endsmithchart{\endsmithchartaxis}
1678
1679 \def\startsmithchart{\smithchart}%
1680 \def\stopsmithchart{\endsmithchart}%
1681 \endinput