What is the TikZ equivalent for \psline[origin={1,2}](3;45) ?

\psline[origin={1,2}](3;45) draws a line 3 units long at an angle of 45 degrees starting from the point (1,2).

What is the TikZ equivalent for \psline[origin={1,2}](3;45) ?

• Both Martin's and Andrew's solutions are accepted. But I chose Andrew for a trivial reason. :D Mar 25 '11 at 10:25
• To try to justify the acceptance (!), I've added a reference to the relevant part of the manual (and I noticed that there are two polar coordinate systems so I also added a note about that). Mar 25 '11 at 10:26

You can specify polar coordinates using the (angle:radius) syntax, so a line at an angle of 45 degree and length 3 is (45:3). But as a bare coordinate, this is centred at the origin. So we need to shift it using either + or ++ (depending on whether we want to shift the point from which we compute the next point as well). Thus:

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\tikz \draw (0,0) (1,2) --  +(45:3) -- +(90:2);
\tikz \draw (0,0) (1,2) -- ++(45:3) -- +(90:2);
\end{document}

In both, the (45:3) is relative to the point (1,2) (as requested) but in the first the (90:2) is also relative to the point (1,2) as opposed to the second where it is relative to the point specified by (45:3).

Result (sort of, see below): (I hope that the circles aren't distracting. They're there to emphasise where the specified points are.)

(Added in Edit) The details on polar coordinates is in Section 13.2.1 (Canvas, XYZ, and Polar Coordinate Systems) of the pgfmanual (in my version, which is PGF2.10, polar coordinates are on p125). In looking up this reference, I noticed a subtlety about polar coordinates. There are two versions: canvas polar and xyz polar. In the latter, one is allowed to predefine an x vector and a y vector which will be taken as the new x and y vectors for any subsequent non-canvas coordinate calculations. So canvas polar is always with respect to the canvas whereas xyz polar is with respect to the current coordinate system in use. The subtlety is that the implicit form of specifying a polar coordinate, as (angle:radius) contains within it a way of choosing whether to be canvas polar or xyz polar. If the radius contains an explicit unit then it is canvas polar, otherwise it is xyz polar.

Most of the time this will be of no concern. In particular, if you don't mess with the x and y vectors, the two are equivalent.

(Added in second edit) As requested, grid lines, plus (automatic!) coordinates. The actual code to produce the diagram was:

\documentclass{standalone}
\usepackage{tikz}
\makeatletter
\tikzset{c/.style={insert path={node[fill,circle] {} node[above left] {(\pgfmathparse{\pgf@x * 0.03514598035}\pgfmathprintnumber{\pgfmathresult},\pgfmathparse{\pgf@y * 0.03514598035}\pgfmathprintnumber{\pgfmathresult})}}}}
\tikzset{ce/.style={c,insert path=(current bounding box.south west) grid (current bounding box.north east)}}
\makeatother
\begin{document}
\tikz \draw[ce] (0,0)[c] (1,2)[c] --  +(45:3)[c] -- +(90:2)[ce];
\tikz \draw (0,0)[c] (1,2)[c] -- ++(45:3)[c] -- +(90:2)[ce];
\end{document}

(The factor 0.03514598035 is (apparently) the conversion from TeX points to cm)

• It will be easier to relate coordinates in the code with the corresponding objects in the rendered diagram if you also show the navigational grids on the diagram. Mar 25 '11 at 10:34
• @xport: As requested! Mar 25 '11 at 11:11

It would be:

\draw (1,2) -- +(45:3);

It starts at (1,2). The -- means that a line should be drawn (without only a "move" is done). The + means that the next coordinate is relative to the current one and (45:3) stands for the angle and the length.

• @xport: If you want to keep drawing then you can use ++ instead of + to make the new point the reference for all following + coordinates. Mar 25 '11 at 10:14