3

How to define / save a point for later usage with x/y-coordinates of other points? I tried to use the perpendicular coordinate system shortform |- and -| but could not define points that way.

In bigger pictures I would prefer using a node instead of expressions like (A -| B) all the time. Especially with more complicated "calculations" for relative positions of points this could get tedious.

\begin{tikzpicture}
    \draw [help lines, step=0.5cm] (-2.5,0) grid (0,2.5);
    \node (A) at (-0.5,0.5) {A};
    \node (B) at (-2,2) {B};

    % \node (someName) at (A -| B);

    \draw (A |- B) node {C};
    \draw (A -| B) node {D};
    \draw (A |- B) edge (A -| B);
\end{tikzpicture}

Example

BadAtLaTeX
  • 1,139

1 Answers1

4

You can do exactly what you're trying, you just have to specify a node text:

\node (someName) at (A -| B) {SomeName};

or use a coordinate:

\coordinate (someName) at (A -| B);

An additional option is to use the let path operation from the calc library, described on page 161 of the 3.0.0 manual:

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
    \draw [help lines, step=0.5cm] (-2.5,0) grid (0,2.5);
    \node (A) at (-0.5,0.5) {A};
    \node (B) at (-2,2) {B};
    \path let \p1 = (A), \p2 = (B) in node (C) at (\x1,\y2) {C} node (D) at (\x2,\y1) {D};
    \draw (C.center) -- (D.center);
\end{tikzpicture}
\end{document}

output

You can also do other calculations on the points, using the other facilities of the calc library; I suggest you check out that chapter in the manual! :-)

darthbith
  • 7,384
  • How would you combine that with$ ... $ expressions as done here : \path ($(A)!0.5!(B)$) |- node[red] {X} ($(C)!0.5!(D)$); ? – BadAtLaTeX Mar 27 '15 at 14:28
  • @hillbilly Can you clarify your question? Combine what with what? – darthbith Mar 27 '15 at 15:26
  • 1
    Definitions of nodes with $ ... $. So combining with all kinds of calc expressions. Something like \node (someName) at (($A - (0,1)$) -| B) {}; or (since this is equal to $(A -| B) - (0,1)$ - which works) expresions using (A)!0.5!(B) like in that other question linked above. – BadAtLaTeX Mar 27 '15 at 15:34
  • 1
    @hillbilly Do you mean something like \path ($(A)!0.5!(B)$) -| node[red] (X) {X} (C);? – darthbith Mar 27 '15 at 16:19