TikZ-Koordinate, die sich auf die letzte „aktuelle Koordinate“ bezieht

Nov 29 2020

Ist es möglich, innerhalb eines TikZ-Pfads die "aktuelle Koordinate" als eine andere Koordinate zu bezeichnen?

Um klar zu machen, was ich will, nehmen Sie dieses Beispiel, das ich oft mache, weil ich es nicht besser weiß:

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

Was ich am Ende mache, ist:

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

weil ich (sagen wir) eine gerade Linie vom aktuellen Punkt zu einem Punkt ziehen möchte, der senkrecht zu einem anderen wäre. Aber es ist ein Schmerz , die coordinate (THIS)ganze Zeit zu tippen , und ich würde gerne wissen, ob es eine magische interne Koordinate gibt, die es mir ermöglichen würde:

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

und THISwürde wissen, dass es bedeutet 1,1.

Existiert THISoder was ich tue, ist das Beste, was ich bekommen kann?

Antworten

2 Noname Nov 29 2020 at 07:18

Wenn Sie bereit sind, toanstelle von zu verwenden --, wird die letzte Koordinate in gespeichert \tikztostartund kann auf die gleiche Weise wie Sie verwendet werden 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}

Natürlich können Sie auch verwenden \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}