# Making TikZ do certain calculations

I want to draw a picture illustrating how a vector field that is invariant under rotation around a point need not be radial in 2D, but does need to be radial in 3D. This question will concentrate on the 2D part. At the moment, I have:

\begin{tikzpicture}
\draw (0,0) circle (2cm);
\draw[->] (-2,0) -- (-2.5,0.25);
\draw[->] (-1.75,0.9682) -- (-2.1049,1.4001);
\end{tikzpicture}


So I have a circle and I'd like to have more tiny vectors of the same length as the first one and with the same angle relative to the radial direction as the first one. How do I make TikZ calculate both the points on the circle from which the vectors start and the endpoints? More precisely, I'd like to have one every 1/4cm, so I have the one starting ad (-2,0) and the one at (-1.75,…), I need the ones at (-1.5,…),(-1.25,…),(-1,…),(-0.75,…),(-0.5,…),(-0.25,…),(0,2),(0.25,…),(0.5,…),(0.75,…),(1,…),(1.25,…),(1.5,…),(1.75,…),(2,0), with both positive and negative y coordinates.

• I'd recommend using polar coordinates as opposed to Cartesian coordinates. – Peter Grill Oct 21 '14 at 20:18
• That might be an idea, at least for the starting points. And the endpoints shouldn't be too hard either. But how do I tell TikZ to interpret the given coordinates as polar rather than cartesian? – MickG Oct 21 '14 at 20:24

Do you mean something like this?

This offsets the radial vectors by the amount specified in \offset:

## Notes:

• As per @Bordaigorl's suggestion I have drawn the circle after the radial vectors which yields better line quality as then the circle is on top of the radial vectors.

## Code:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

\newcommand{\offset}{10}
\foreach \x in {0,30,...,180} {
}

\draw [thick] (0,0) circle (2cm);
\end{tikzpicture}
\end{document}

• Let me just interpret the code. \tikzset{…} is setting the radial vector option (and creating it btw, right?) to style of thick,blue,-latex, meaning a thick blue line with a latex arrow tip. I could have specified latex-latex or any tip combination desired, right? Can \tikzset be used outside the preamble? And the line with \draw, which is done for each element of {0,30,…,180} (which is filled in with all intermediate numbers adding 30 at each step right?), draws a vector from ("element":2cm), which is (theta,rho) in polar coords, to ("element"+"offset":2.5cm), … – MickG Oct 21 '14 at 20:32
• … therefore guaranteeing the same angle with the radial direction for all vectors and also the same length to all vectors. OK. And using : instead of , is the TikZ way of using polar coordinates in any case, right @PeterGrill? Btw, are there any other coordinates TikZ can use? – MickG Oct 21 '14 at 20:34
• @MickG: Yep, your understanding is correct. There are other coordinate systems available (see the tikz-pgf manual, or post a new question), but for this particular application, polar coordinates seems the way to go. Perhaps temporarily setting \offset to 0 will make things more obvious as to how the polar coordinates are working. – Peter Grill Oct 21 '14 at 20:36
• I would draw the circle as the last thing so the vectors join it nicely – Bordaigorl Oct 21 '14 at 21:32
• @Bordaigorl: Good suggestion. Have incorporated that in the solution. – Peter Grill Oct 21 '14 at 23:18

You can also use rotate around = {<angle>: (<x>, <y>)}.

\documentclass{article}
\usepackage{tikz}