Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

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}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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