3

I would like to draw lines at a specific angle with tikzpicture. But it doesn't work the way I think it should.

Example:

\documentclass[a4paper,12pt]{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
  %\draw [help lines] (-3,-1) grid (9,7);
  \coordinate (a) at (0,0) node at (a) {A};
  \coordinate (c) at (0,5) node at (c) {C};
  \draw (0,0) -- (0:2cm);
  \draw (0,0) -- (30:3cm);
  \draw (0,5) -- (0:2cm);
\end{tikzpicture}

\end{document}

the two lines from (0,0) does what I want, a line at 0 degrees from (0,0) to (2,0) and a line from the same point at an angle of 30 degrees with the length of 3 cm.

The line from point (0,5) does something else. I thought it should be parallel to the first line, that is, from (0,5) to (2,5) (0 degrees angle) but it ends in (2,0).

I have been looking in the pgf-manual section 13.1 (page 125).

But I think I need something more.

4

The problem is quite simply that polar coordinates are also relative to the origin, so (0:2cm) is the same as the point (2cm,0). To make the coordinate relative to the previous coordinate, add a + before it:

\draw (0,5) -- +(0:2cm);

This is described in section 13.4 Relative and Incremental Coordinates of the manual. You can also use two plus signs, which updates the current point.

\documentclass[a4paper,12pt]{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
  %\draw [help lines] (-3,-1) grid (9,7);
  \coordinate (a) at (0,0) node at (a) {A};
  \coordinate (c) at (0,5) node at (c) {C};
  \draw (0,0) -- (0:2cm);
  \draw (0,0) -- (30:3cm);
  \draw (0,5) -- +(0:2cm);
\end{tikzpicture}

\end{document}

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.