0

I calculate some lengths of a path (without the use of the let operator!). To achieve that I use the \pgfgetlastxy{}{}; command (which works fine so far) but if I scale the picture, the calculations do not make sense anymore, as I cannot take the scaling factor into account.

The following code should demonstrate my problem.

\documentclass{article}
\usepackage{tikz}
\tikzset{dot/.style={circle, fill, inner sep=2pt}}

\begin{document} \begin{tikzpicture}[scale=1] \draw (0,0) node[below] {scale = 1} -- (20pt,60pt); \pgfgetlastxy{\myLastX}{\myLastY}; \node[dot, label={right:(\myLastX, \myLastY)}] at (\myLastX, \myLastY) {}; \end{tikzpicture} % \begin{tikzpicture}[scale=0.5] \draw (0,0) node[below] {scale = 0.5} -- (20pt,60pt); \pgfgetlastxy{\myLastX}{\myLastY}; \node[dot, label={right:(\myLastX, \myLastY)}] at (\myLastX, \myLastY) {}; \end{tikzpicture} % \begin{tikzpicture}[scale=0.5] \draw (0,0) node[below] {scale = 0.5 (what I want)} -- (20pt,60pt); \pgfgetlastxy{\myLastX}{\myLastY}; % \getglobalscale{\globalscale} <--- How to get the global value? \pgfmathsetmacro\globalscale{0.5} \node[dot, label={right:(\myLastX, \myLastY)}] at (\myLastX/\globalscale, \myLastY/\globalscale) {}; \end{tikzpicture} % % Does not work % \begin{tikzpicture}[scale=0.5] % \draw (0,0) node[below] {scale = 0.5 (what I want)} -- (20pt,60pt); % \pgfgetlastxy{\myLastX}{\myLastY}; % \pgfkeysgetvalue{/tikz/scale}{\globalscale} % \node[dot, label={right:(\myLastX, \myLastY)}] at (\myLastX/\globalscale, \myLastY/\globalscale) {}; % \end{tikzpicture} \end{document}

enter image description here

TL;DR: To solve my (initial) problem I need to get the value of the global picture scale. The way I tried to get it in the last code snippet did not work. Is there any other way to get it?

Wulle
  • 1,204
  • 1
  • 8
  • 16

1 Answers1

2

The best answer about this is @Circumscribe very nice post; you can also look at the solution proposed by @marmot (a user that unfortunately is not here anymore).

Summarizing, this code:

\pgfgettransformentries{\tmpa}{\tmpb}{\tmpc}{\tmpd}{\tmp}{\tmp}%
\pgfmathsetmacro{\myscale}{sqrt(abs(\tmpa*\tmpd-\tmpb*\tmpc))}%

should give you the global scale (even when there are rotations or different x- and y- scale).

The TikZ manual says: enter image description here

Rmano
  • 40,848
  • 3
  • 64
  • 125