[Tex/LaTex] Recover scaling factor in TikZ

tikz-pgf

Does it exist some tikz register (let say \zoomfactor) that provides the curent scale factor.
For example can I do something like :

\begin{tikzpicture}[scale=2]
    \begin{scope}[scale=1.5]
        \draw (0,0) circle (\zoomfactor);
    \end{scope}
\end{tikzpicture}

and to obtain circle of size 3=2*1.5 ?

Best Answer

You can get the current transformation entries to extract the scale but if there are different x and y scalings(or combinations e.g. full matrix) in action, this would fail and retrieve only the x scaling. Also it uses 1cm as the unit vector.

\documentclass{article}
\usepackage{tikz}

\newcommand{\getzoomfactor}{%
\pgfgettransformentries{\myxscale}{\@tempa}{\@tempa}{\myyscale}{\@tempa}{\@tempa}
\gdef\zoomfactor{\myxscale*1cm}
}

\begin{document}

\begin{tikzpicture}[scale=2]
    \begin{scope}[scale=1.5]
        \getzoomfactor
        \draw (0,0) circle (\zoomfactor);
                \node {\zoomfactor};
    \end{scope}
\end{tikzpicture}

\end{document}

enter image description here