In another question concerning Access to logic coordinates on
Accessing the logic values of a TikZ coordinate
I used these functions, until I came to a scaled tikzpicture and then it was off. I now have added a factor for the scaling, but I am looking for a method to make it universal. That would mean the xcoord/ycoord would take the picture's scaling into account through a tikz/pgf variable.
\makeatletter
\newcommand\xcoord[2][center]{{%
\pgfpointanchor{#2}{#1}%
\pgfmathparse{\pgf@x/\pgf@xx}%
\pgfmathprintnumber{\pgfmathresult}%
}}
\newcommand\ycoord[2][center]{{%
\pgfpointanchor{#2}{#1}%
\pgfmathparse{\pgf@y/\pgf@yy}%
\pgfmathprintnumber{\pgfmathresult}%
}}
\makeatother
Any suggestion to that effect?
An MWE is:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgffor}
\makeatletter
\newcommand\xcoorda[2][center]{{%
\pgfpointanchor{#2}{#1}%
\pgfmathparse{\pgf@x/\pgf@xx}%
\pgfmathprintnumber{\pgfmathresult}%
}}
\makeatletter
\newcommand\xcoord[2][center]{{%
\pgfpointanchor{#2}{#1}%
\pgfmathparse{\pgf@x/\pgf@xx/.17}%
\pgfmathprintnumber{\pgfmathresult}%
}}
\newcommand\ycoorda[2][center]{{%
\pgfpointanchor{#2}{#1}%
\pgfmathparse{\pgf@y/\pgf@yy}%
\pgfmathprintnumber{\pgfmathresult}%
}}
\makeatother
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}[domain=-0.01:0.55,xscale=17,yscale=0.01]
% the scaling is also in xcoord
\draw[-stealth,name path=xline] (0,0) -- (0.55,0);
\draw[stealth-stealth,name path=yline] (0,-220) -- (0,220);
\draw[color=blue,name path=func] (0,200) parabola bend (.25,-50) (.50,200);
\path[name intersections={of=func and xline,by={i1,i2}}];
\node[above=15pt] (i1label) at(i1) {\xcoord{i1}\%};
\draw[-stealth,green] (i1label.south) -- (i1);
\node[below=20pt,text width=2cm,align=center,draw,fill=red!25] (i1label_a)
at(i1) {\xcoorda{i1}\%\\ sans scaling \\ wrong!};
\draw[-stealth,red] (i1label_a.north) -- (i1);
\node[above=15pt] (i2label) at(i2) {\xcoord{i2}\%};
\draw[-stealth,green] (i2label.south) -- (i2);
\node[below=20pt,text width=2cm,draw,align=center,fill=red!25] (i2label_a)
at(i2) {\xcoorda{i2}\%\\ sans scaling \\ wrong!};
\draw[-stealth,red] (i2label_a.north) -- (i2);
\foreach \t in {10,20,...,50} {
\pgfmathparse{\t/100}\edef\v{\pgfmathresult}
\draw[thin] (\v,10) -- (\v,-10) node[below] {\t\%};
}
\foreach \t in {-200,-100,...,200} {
\draw[thin] (.010,\t) -- (-0.01,\t) node[left] {\small\t};
}
\end{tikzpicture}
\end{document}
I used a parabola in the MWE and marked the scaled and unscaled xcoord's in both cases.
(2,1)
is still(2,1)
just placed somewhere else when you usescale
.