和 PostScript(及其rmoveto
和rlineto
)一样,TikZ 使得生成当前点的相对运动变得非常简单。我没有在 PGF 中看到任何等效的东西。它缺失了吗?如果是,能说清楚原因吗?(PFG 中的预期替代品是什么?)即使相对运动对于系统层来说不够低级(难以置信?),但对于基础层来说它似乎足够低级了。
编辑(相关查询):已\pgfrelative
弃用(当前手册中没有)?并且,哪个 PGF 命令生成当前点?
答案1
以下示例中提供了两个新宏\pgfpathrlineto{<coord>}
和\pgfpathrmoveto{<coord>}
。它们尚未经过全面测试,因此请谨慎使用。
实际上,我们需要跟踪最后一个点的原始(未转换)坐标,但在这里\pgf@x
存储\pgf@y
转换后的坐标。
重点是,在 中(x, y) -- ++(2, 3)
,变换之前的预期线是(x, y) -- (x+2, y+3)
,而我在下面的例子中实现的是(x, y) -- ($ (x, y) + T'(2, 3) $)
,其中T'
是变换的反转。
\documentclass{article}
\usepackage{pgf}
\makeatletter
\def\pgf@path@last@point{%
\pgfpoint{\pgf@path@lastx}{\pgf@path@lasty}}
% rlineto
\def\pgfpathrlineto#1{%
\pgf@process{#1}%
\global\advance\pgf@x\pgf@path@lastx
\global\advance\pgf@y\pgf@path@lasty
% similar to \pgfpathlineto, but without applying transformation
\pgf@nlt@lineto{\pgf@x}{\pgf@y}%
\global\pgf@path@lastx=\pgf@x
\global\pgf@path@lasty=\pgf@y
}
% rmoveto
\def\pgfpathrmoveto#1{%
\pgf@process{#1}%
\global\advance\pgf@x\pgf@path@lastx
\global\advance\pgf@y\pgf@path@lasty
% similar to \pgfpathlineto, but without applying transformation
\pgf@nlt@moveto{\pgf@x}{\pgf@y}%
\global\pgf@path@lastx=\pgf@x
\global\pgf@path@lasty=\pgf@y
}
\makeatother
\begin{document}
\begin{pgfpicture}
\pgfpathmoveto{\pgfpointorigin}
\pgfpathlineto{\pgfpoint{20pt}{0pt}}
\pgfpathmoveto{\pgfpoint{40pt}{0pt}}
\pgfpathlineto{\pgfpoint{60pt}{0pt}}
\pgfusepath{draw}
\pgftransformshift{\pgfpoint{10pt}{10pt}}
\pgfsetcolor{red}
\pgfpathmoveto{\pgfpointorigin}
\pgfpathlineto{\pgfpoint{20pt}{0pt}}
\pgfpathmoveto{\pgfpoint{40pt}{0pt}}
\pgfpathlineto{\pgfpoint{60pt}{0pt}}
\pgfusepath{draw}
\end{pgfpicture}
\qquad
% use r(line|move)to
\begin{pgfpicture}
\pgfpathmoveto{\pgfpointorigin}
\pgfpathrlineto{\pgfpoint{20pt}{0pt}}
\pgfpathrmoveto{\pgfpoint{20pt}{0pt}}
\pgfpathrlineto{\pgfpoint{20pt}{0pt}}
\pgfusepath{draw}
\pgftransformshift{\pgfpoint{10pt}{10pt}}
\pgfsetcolor{red}
\pgfpathmoveto{\pgfpointorigin}
\pgfpathrlineto{\pgfpoint{20pt}{0pt}}
\pgfpathrmoveto{\pgfpoint{20pt}{0pt}}
\pgfpathrlineto{\pgfpoint{20pt}{0pt}}
\pgfusepath{draw}
\end{pgfpicture}
\end{document}