5

i have a tikz question. Is it possible to use relative coordinates in a \coordinate definition? I have to define a lot of coordinates and it would be much easier if i could define those relative to already defined coordinates like this:

\coordinate (A) at (0.0, 0.0);
\coordinate (B) at (A)+(120:1);

As you can see, i want to especially use the angle:length notation here. But in general i want to define the coordinate B relative to A. Is this possible?

  • 5
    Use the tikz calc library, ($(A) +(120:1)$) – daleif Aug 7 '16 at 13:45
  • 1
    Another solution without calc library: \coordinate (B) at ([shift={(120:1)}]A);. Be careful with syntax, as (120:1) uses parenthesis, it must be included into a pair of braces { (120:1)}. – Ignasi Aug 8 '16 at 11:23
  • 1
    @JohnKormylo No, it wouldn't. I checked just to be sure. – cfr Aug 8 '16 at 15:26
  • Also \path (A) +(120:1) coordinate (B); (@cfr - I assume the ++ was what you were referring to.) – John Kormylo Aug 8 '16 at 18:07
6

\coordinate is only a shorthand for \path coordinate. You may thus place coordinates along an arbitrary path which supports relative coordinates without a hassle.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
  \coordinate (A) at (0,0);
  \path (A) +(120:1) coordinate (B);
  % or \path (A) -- +(120:1) coordinate (B);

  \draw (A) circle (2pt);
  \draw (B) circle (2pt);
\end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.