크기가 조정된 그림의 노드 텍스트에 Tikz 표시 좌표

크기가 조정된 그림의 노드 텍스트에 Tikz 표시 좌표

좌표 값을 표시하려고 하는데 아래의 값을 사용하면 값이 정확하게 출력되지 않습니다.

스케일은 다음을 사용하여 검색하려고 시도됩니다.TikZ에서 배율 인수 복구그런 다음 다음과 같이 축척 비율 값을 사용하십시오.TikZ에서 임의 점의 x, y 좌표 추출. 그러나 @scalefactor는 Tikz 그림에 사용된 경우 실제 요소를 표시함에도 불구하고 \xcoord 및 \ycoord에서 항상 1을 반환합니다.

해결 방법에 대한 아이디어가 있습니까?

%!TeX program = lualatex
\documentclass[12pt]{article}

\usepackage{tikz}
\usetikzlibrary{math, calc}

%% https://tex.stackexchange.com/questions/86897/recover-scaling-factor-in-tikz
\newcommand*\getscale[1]{%
\begingroup
\pgfgettransformentries{\scaleA}{\scaleB}{\scaleC}{\scaleD}{\whatevs}{\whatevs}%
\pgfmathsetmacro{#1}{sqrt(abs(\scaleA*\scaleD-\scaleB*\scaleC))}%
\expandafter
\endgroup
\expandafter\def\expandafter#1\expandafter{#1}%
}

% for printing out coordinates in Tikz coordinate variable
\makeatletter
\newcommand\xcoord[1]{{%
    \getscale{\@scalefactor}%
    \pgfpointanchor{#1}{center}%
    \pgfmathparse{\pgf@x/\pgf@xx/\@scalefactor}%
    \pgfmathprintnumber{\pgfmathresult}%    
}}
\newcommand\ycoord[1]{{%
        \getscale{\@scalefactor}%
        \pgfpointanchor{#1}{center}%
        \pgfmathparse{\pgf@y/\pgf@yy/\@scalefactor}%
        \pgfmathprintnumber{\pgfmathresult}%
}}
\makeatother

\begin{document}

\begin{figure}
    \centering
    
    \begin{tikzpicture}[scale=1/10]
        % GRID - X
        \foreach \i in {0,24,...,120}{
            \draw[gray, thin] (\i,-12) -- (\i,184);
            \tikzmath{int \value; \value = \i;}; 
            \node[gray, below] at (\i,-12) {\value};
        }
        
        % GRID - Y
        \foreach \i in {0,24,...,168}{
            \draw[gray, thin] (-12,\i) -- (132,\i);
            \tikzmath{int \value; \value = \i;};
            \node[gray, left] at (-12,\i) {\value};
        }
    
        % Draw some lines with relative coordinates
        \draw[thick] (0,0) -- ++(12,0) coordinate (c);
        \draw[thick] (0,0) -- ++(0,60) coordinate (c);
        \draw[thick] (c) -- ++(0,36) coordinate (c);
        \draw[thick] (c) -- ++(0,76) coordinate (c);
        \draw[thick] (c) -- ++(120,0) coordinate (c);
        
        % Display coordinate
        \getscale{\scalefactor};
        \node[fill=white, text=blue] at (60,60) {Scale = \scalefactor};
        \node[fill=white, text=magenta, yshift=-15pt] at (c) {(\xcoord{c}, \ycoord{c})};            
    \end{tikzpicture}
\end{figure}
\end{document}

위의 내용은 컴파일되지만 마젠타색의 좌표는 검은색 선이 끝나는 위치(120, 172)와 일치하지 않습니다.

여기에 이미지 설명을 입력하세요

답변1

이것은 틱에 수동으로 레이블을 지정하는 문제입니다. x 레이블을 "계산"하고 있지만 \tikzmath{int \value; \value = \i;};이는 숫자일 뿐이고 "tikz 좌표"가 아니기 때문에 크기 조정에 대해 아무것도 알 수 없습니다.

해결책은 수동으로 크기 조정을 수행하는 것입니다.

\tikzmath{int \value; \value = \i * \scalefactor;}; 

\value정수로 사용하면 반올림 오류가 발생한다는 점을 고려해야 할 수도 있지만 이는 다른 문제입니다.

답변2

변환되지 않은 원본 좌표를 얻는 방법은 여기에서 찾을 수 있습니다.TikZ 좌표의 논리 값에 액세스.

사용자 정의 명령 사용

\makeatletter
\def\extractcoord#1#2#3{
  \path let \p1=(#3) in \pgfextra{
    \pgfmathsetmacro#1{\x{1}/\pgf@xx}
    \pgfmathsetmacro#2{\y{1}/\pgf@yy}
    \xdef#1{#1} \xdef#2{#2}
  };
}
\makeatother

다음과 같이 좌표를 표시할 수 있습니다.

\coordinate (A) at (120,172);
\extractcoord{\x}{\y}{A};
\node at (A) {Coordinates: \x, \y};

이는 스케일링, x 및 y 모두의 단위 변경, 범위 환경을 통해 테스트되었습니다.

관련 정보