15

I can't seem to figure out the difference between + and ++ relative coordinates in TikZ.

I understand ++. ++ specifies delta coordinates that are added to the last current point, the current point is then set to the new absolute current point (correct?):

\draw (0,0) -- ++(1,0) -- ++(0,1) means:

set Current Point to (0,0)
add (1,0) to Current Point = (1,0)
set Current Point to (1,0)
add Current Point (1,0) to (0,1) = (1,1)
set Current Point to (1,1)

I can't seem to figure out that + does, when I try it out it looks like the coordinates in the +(x,y) are absolute coordinates rather than delta coordinates, but the manual says otherwise

4
  • Start from here and then manual makes sense :) tex.stackexchange.com/questions/7643/…
    – percusse
    May 8, 2013 at 20:06
  • I remember reading that section of the manual but I interpreted as all +(x,y) terms are relative to the first coordinate, hence a list of +() would generate a set of lines radiating from a single point, which it doesn't. I will look more closely at the question you refer to.
    – rhody
    May 8, 2013 at 20:22
  • 1
    @rhody The pluses only affect the calculation of these relative coordinates, they do (++) or don’t update (+) the “current point for subsequent usages of relative coordinates.” The lines (or whatever is used) will always start from the last actual point. The set of lines radiating from a single point will always need a move-to operation. E.g. \draw (12,34) -- +(1,0) +(0,0) -- +(0,1) + (0,0) -- + (left:1) + (0,0) -- + (270:1) + (0,0) circle (2pt); vs. \draw (12,34) -- ++(1,0) ++(-1,0) -- ++(0,1) ++ (0,-1) -- ++ (left:1) ++ (right:1) -- ++ (270:1) ++(90:1) circle (2pt); May 8, 2013 at 20:47
  • It is also important to recognize that \draw (a,b) + (c,d) -- (e,f) + (g,h); draws a line from (a+c,b+d) to (e,f) and then moves the current point to (e+g,f+h) (here the pluses do not matter as the following coordinate is an absolute one). May 8, 2013 at 20:59

1 Answer 1

16

Your example:

\draw (0,0) -- ++(1,0) -- ++(0,1) means:

  • the current point is (0,0).
  • draw a line from the current point (0,0) to (0,0)+(1,0) (vector addition) and move the current point to (0,0)+(1,0).

  • next draw a line from the current point (0,0)+(1,0) to (0,0)+(1,0)+(0,1) and move the current point to (0,0)+(1,0)+(0,1).

Other examples are given as follows.

enter image description here

\documentclass[tikz,border=12pt]{standalone}

\begin{document}
\begin{tikzpicture}
    \draw (-2,-2) grid (2,2);
    \fill (110:2) circle (1pt);
    \draw (110:2) -- +(0,-1);
\end{tikzpicture}
\end{document}

Remarks for TikZ:

  • \draw (110:2) -- +(0,-1); The current point is (110:2). It draws a line from point (110:2) to point (110:2)+(0,-1) (vector addition). The current point is still at (110:2).

  • \draw (110:2) -- ++(0,-1); The current point is (110:2). It draws a line from point (110:2) to point (110:2)+(0,-1) (vector addition). The current point is moved to (110:2)+(0,-1).

  • \draw (110:2) +(0,-1) -- +(0,1); The current point is (110:2). It draws a line from point (110:2)+(0,-1) to point (110:2)+(0,1). The current point is still at (110:2).

  • \draw (110:2) ++(0,-1) -- +(0,1); The current point is (110:2)+(0,-1). It draws a line from point (110:2)+(0,-1) to point (110:2)+(0,-1)+(0,1). The current point is still at (110:2)+(0,-1).

  • \draw (110:2) ++(0,-1) -- ++(0,1); The current point is (110:2)+(0,-1). It draws a line from point (110:2)+(0,-1) to point (110:2)+(0,-1)+(0,1). The current point is moved to (110:2)+(0,-1)+(0,1) (which is equal to (110:2)).

Edit:

\draw (0,0) -- +(1,1) -- +(2,0) means

  • the current point is (0,0).

  • the first segment connecting (0,0) and (0,0)+(1,1).

  • the current point is still (0,0).

  • the second segment connecting the previous point (0,0)+(1,1) and (0,0)+(2,0).

The key is A -- B connects A and B with a line no matter how A and B are defined.

5
  • +1; Thanks for this answer. It clears up quite a bit for me.
    – kan
    May 8, 2013 at 20:15
  • Thanks for the detailed answer. In your notation what would the following do: \draw (0,0) -- +(1,1) -- +(2,0); Does it say: Current Point is (0,0); Draw line from (0,0) to (0,0)+(1,1); Current point remains at (0,0); Draw line from (0,0) to (0,0)+(2,0); If I run this I get a triangle, not two lines radiating from (0,0)
    – rhody
    May 8, 2013 at 20:29
  • I was looking again at the example shown in tex.stackexchange.com/questions/7643/… and what seems to be happening given: \draw (0,0) -- +(1,1) -- +(2,0) Current Point is (0,0);' Draw line from (0,0) to (0,0)+(1,1)` Current Point is set to (0,0)+(1,1) Draw a line from current point (0,0)+(1,1) to the point (0,0)+(2,0)` Seems like an odd thing to do?
    – rhody
    May 8, 2013 at 20:40
  • @rhody: The current point is (0,0), draw a line from (0,0) to (0,0)+(1,1) first and draw a line from the previous point (0,0)+(1,1) to (0,0)+(2,0). A -- B connects A and B regardless of how A and B are defined. May 8, 2013 at 20:41
  • Ok, I see what its doing now, I just need to let it sink in a bit. Thanks for your help.
    – rhody
    May 8, 2013 at 20:47

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.