引用最后一个“当前坐标”的 TikZ 坐标

引用最后一个“当前坐标”的 TikZ 坐标

在 TikZ 路径中,是否可以将“当前坐标”引用为另一个坐标?

为了更清楚地说明我想要什么,请看这个例子,由于我不知道更好的方法,我经常这样做:

\documentclass[tikz,margin=1cm]{standalone}
\begin{document}
\begin{tikzpicture}
\coordinate (origin) at (0,0);
% suppose the "1,1" is a very complicate (possibly unknown) coordinate
% that I would love not to repeat in the code:
\draw (origin) -| (1,1) coordinate (THIS) -- (THIS-|origin);
% This is what I would like to do:
% \draw (origin) -| (1,1) -- (THIS-|origin);
\end{tikzpicture}
\end{document}

我最终做的是:

\draw (origin) -| (1,1) coordinate (THIS) -- (THIS-|origin);

因为我想从当前点画一条直线到与另一个点垂直的点。但这是疼痛一直打字coordinate (THIS),我想知道是否存在一个神奇的内部坐标可以让我做到:

\draw (origin) -| (1,1) -- (THIS-|origin);

并且THIS知道它的意思1,1

是否THIS存在,或者我所做的就是我能做到的最好的?

答案1

如果您愿意使用to而不是--,那么最后一个坐标将存储在 中\tikztostart,并且可以按照与使用 相同的方式使用THIS

\documentclass[tikz,margin=1cm]{standalone}
\begin{document}
\begin{tikzpicture}
\coordinate (origin) at (0,0);
% suppose the "1,1" is a very complicate (possibly unknown) coordinate
% that I would love not to repeat in the code:
% This is what I would like to do:
% \draw (origin) -| (1,1) -- (THIS-|origin);
 \draw (origin) -| (1,1)  to (\tikztostart-|origin);
\end{tikzpicture}
\end{document}

在此处输入图片描述

当然你也可以使用\THIS

\documentclass[tikz,margin=1cm]{standalone}
\begin{document}
\begin{tikzpicture}
\coordinate (origin) at (0,0);
\def\THIS{\tikztostart}
% suppose the "1,1" is a very complicate (possibly unknown) coordinate
% that I would love not to repeat in the code:
 \draw (origin) -| (1,1)  to (\THIS-|origin);
% This is what I would like to do:
% \draw (origin) -| (1,1) -- (THIS-|origin);
\end{tikzpicture}
\end{document}

相关内容