1

Is it possible to use the X and Y values of a coordinate as stand alone variables? I did put together a MWE, but it does not work... I've seen similar questions, but none really had a clear answer for what I am asking here, or at least I could not extract any working wisdom out of those answers.

\documentclass{minimal}
\usepackage{pgfplots}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}

\coordinate (OR) at (0.00, 0.00);
\filldraw [red] (OR) circle(2pt);

\coordinate (PT) at ( $\x{OR} + 1.0$, $\y{OR} + 2.0$ );
\filldraw [blue] (PT) circle(2pt);

\end{tikzpicture}

\end{document}
Diegis
  • 1,107

2 Answers2

3

I don't understand why you think the other answers did not give a clear answer for what you're asking. There are many ways, covered in various questions. Here is one way, using the let syntax:

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}
  \coordinate (OR) at (0.00, 0.00);
  \filldraw [red] (OR) circle(2pt);
  \path let \p1 = (OR) in coordinate (PT) at (\x1 + 1.0,\y1 + 2.0);
  \filldraw [blue] (PT) circle(2pt);
\end{tikzpicture}
\end{document}

enter image description here

Please see also Why should the minimal class be avoided?

Paul Gessler
  • 29,607
2

If you want a new point shifted 1cm right and 2cm up from another point you can use any of these expressions (and probably more).

Only first and fifth need calc library.

\documentclass[tikz, border=3mm]{standalone}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}
    \draw[help lines] (0,0) grid (1,2);
    \filldraw [red] (0,0) circle(2pt) coordinate (OR);
    \path let \p1 = (OR) in coordinate (PT) at (\x1 + 1cm,\y1 + 2cm);
    \path (OR)--++(1,2) coordinate (PT);
    \path ([shift={(1,2)}]OR) coordinate (PT);
    \path (OR)--++(0:1)--++(90:2) coordinate (PT);
    \coordinate (PT) at ($(OR)+(1,2)$);
    \filldraw [purple] (PT) circle(2pt);
\end{tikzpicture}
\end{document}

enter image description here

Ignasi
  • 136,588