[Tex/LaTex] TikZ arrow emanating from node at an angle for a distance

tikz-pgf

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

Best Answer

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}

enter image description here

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}

enter image description here

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}

enter image description here