# TikZ arrow emanating from node at an angle for a distance

How do I draw a line of length l and at an angle of a from a circular node N in TikZ?

-

You can access the points around a node with <node name.angle> for example, a.50 will give you a point on the border of node a at an angle of 50 degrees. Further, you can draw a line of length lcm elevated at an angle of t degrees by (t:lcm).

\documentclass[tikz,margin=10pt]{standalone}
\begin{document}
\begin{tikzpicture}
\node[draw,circle]  at (0,0) (a) {N};
%% draw a line of 2cm length from the border of node a at an angle 50. The line is having a slope of tan(50).
\draw (a.50) -- (50:2cm);
\end{tikzpicture}
\end{document}


Putting many lines and some make-up ;-)

\documentclass[tikz,margin=10pt]{standalone}
\begin{document}
\begin{tikzpicture}
\node[circle]  at (0,0) (a) {N};
\foreach \angle in {5,10,...,360}{%
\draw (a.\angle) -- (\angle:2cm);
}
\end{tikzpicture}
\end{document}


And some animation:

\documentclass[tikz,margin=10pt]{standalone}
\begin{document}
\foreach \angle in {1,2,...,360}{%
\begin{tikzpicture}
\path (-2,-2.3) rectangle (2,2.3);  %% pad some bounding box
\node[circle]  at (0,0) (a) {N};
\draw (a.-\angle) -- (-\angle:2cm);
\end{tikzpicture}
}
\end{document}


-
Hope I understood the question :-) –  Harish Kumar Jan 3 at 7:18
Yes, this is exactly and much more than I was looking for! Thanks. –  Neil G Jan 3 at 18:26
Ah, am I right that to make it relative to the node a, you should add ++ in front of the (50:2cm)? –  Neil G Jan 3 at 18:35
What I mean is that if the node a were not at the origin, I think your solution doesn't work anymore? –  Neil G Jan 3 at 22:49
@NeilG: + also specifies a relative coordinate, but it does not update the current point for subsequent usages of relative coordinates. You can use this notation to specify numerous points, all relative to the same initial point, i.e., (0,0). ++ changes the initial point for subsequent paths in the same \draw command. –  Harish Kumar Jan 3 at 23:41

You could also use pins:

\documentclass{standalone}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\node [circle,draw,pin={[pin distance=2cm,pin edge={blue,thick}]330:$P_1$},
pin=60:$P_2$] at (0,0) {N};
\end{tikzpicture}
\end{document}


Pin P1 represents the default behaviour: gray line of a certain length, while pin P2 is customized. Length is set with pin distance, while pin edge lets you define the colour, the thickness, lets you add an arrowhead or even decorate the path (e.g. a snake path). In both cases what precedes the colon : is the angle that defines the slope of the line.

-