在 TikZ 图片中获取全局比例的值

在 TikZ 图片中获取全局比例的值

我计算了路径的一些长度(不使用运算let符!)。为了实现这一点,我使用了命令\pgfgetlastxy{}{};(到目前为止运行良好),但如果我缩放图片,计算就不再有意义了,因为我无法考虑缩放因子。

下面的代码可以演示我的问题。

\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}

在此处输入图片描述

总结:为了解决我的(初始)问题,我需要获取全局图片比例的值。我在上一个代码片段中尝试获取它的方法不起作用。还有其他方法可以获取它吗?

答案1

关于这个问题的最佳答案是@Circumscribe 非常好的帖子;你也可以看看解决方案由 @marmot 提议(不幸的是,该用户不再在这里)。

总结一下,此代码:

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

应该为您提供全球尺度(即使有旋转或不同的x-尺度y-)。

Z 手册说: 在此处输入图片描述

相关内容