28

I'd like to be able to draw lines in LaTeX by specifying an angle, rather than specifying it like so

\put(0,0){\line(2,1){3}}

Is this possible? I've looked at tikz and tikz-euclid. I've even tried installing tikz-euclid, but I couldn't even do that (I found these but couldn't find the .ins for tikz-euclid). And I'm not sure if that's what I want anyway.

What do I need to do to accomplish this?

Werner
  • 603,163
  • Drawing a line by knowing a point and a slope: http://tex.stackexchange.com/a/6000/9467, drawing chained lines by knowing a point and slopes relative to the previous line: http://tex.stackexchange.com/a/7788/9467 – kiss my armpit Feb 09 '12 at 00:36

2 Answers2

59

You can read about it in the pgf manual, Section 13: Specifying Coordinates.

An example:

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
    % Draw a line at 30 degrees and of length 3
    \draw (0,0) -- (30:3cm);
\end{tikzpicture}
\end{document}

You can also use the relative coordinates:

\begin{tikzpicture}
    % Draw the first line with absolute coordinates and the 
    % second with relative coordinates to the first line
    \draw (0,0) -- (30:3cm) -- ++(80:3cm);
\end{tikzpicture}
aignas
  • 1,306
  • 1
    This is like some kind of special magic. Thank you so much. – AncientSwordRage Feb 08 '12 at 23:31
  • You're welcome, although I could not find, how to specify a relative angle to the previous line. If you find it, please post here. :) – aignas Feb 08 '12 at 23:42
  • 3
    As a note, this only works when the line originates at the origin. So the example is correct if it starts at (0,0) but if you were to write \draw (-2,0) -- (30:3cm); the line has the wrong angle. It points toward the end point it would have if it started at the origin. – Ian Durham Sep 29 '13 at 19:15
  • 14
    The point is that (30:3cm) defines a point in polar coordinates with respect to the origin. What want in this case is to use relative coordinates and to preceed the coordinate with ++. So, the command in your case is \draw (-2,0) -- ++(30:3cm); – aignas Sep 30 '13 at 12:24
11

Here is a very minimal example showing how this can be done using pstricks:

enter image description here

\documentclass{article}
\usepackage{pstricks}% http://ctan.org/pkg/pstricks
\begin{document}
\begin{pspicture}(4,4)
  \psgrid % For reference; shows a coordinate grid
  \SpecialCoor % Allows for specifying polar coordinates (r;t)
  \psline(0,0)(4;65)
\end{pspicture}
\end{document}​

\SpecialCoor adds a polar coordinate reference to the existing Cartesian (x,y)-coordinate specification. The difference is specified using (r;t) (r = length; t = angle) rather than (x,y). Measurements in the above MWE is in centimetres (default).

Werner
  • 603,163