The following code
\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\usetikzlibrary{arrows,backgrounds,patterns,shapes.geometric,calc,positioning}
\tikzset{small dot/.style={fill=black,circle,outer sep=8pt,scale=0.25}}
\begin{document}
\begin{tikzpicture}[scale=0.8]
\draw[ultra thin,color=lightgray] (-4,-2) grid (7,5); % coordinate grid
\draw[<->] (-4.5,0) -- (7.5,0) node[right] {$x$}; % x-axis
\draw[<->] (0,-2.5) -- (0,5.5) node[above] {$y$}; % y-axis
\foreach \x/\xtext in {-4,...,-1,1,2,..., 7} % x-axis labels
\draw (\x cm,2pt) -- (\x cm,-2pt) node[anchor=north, font=\footnotesize] {$\xtext$};
\foreach \y/\ytext in {-2, -1,1,2,..., 5} % y-axis labels
\draw (2pt,\y cm) -- (-2pt,\y cm) node[anchor=east, font=\footnotesize] {$\ytext$};
% parametric function alpha(t)
\draw [thick, samples=1000] plot[parametric, domain=0:2*pi, id=spiral] function{t*cos(t),-t*sin(t)};
% points on graph
\foreach \t in {0, 30, ..., 360}
\filldraw ({(\t*3.14/180)*cos(\t)},{-(\t*3.14/180)*sin(\t)}) circle (2pt);
% position vectors
\foreach \t in {0, 30, ..., 360}
\draw[->, color=blue, thin] (0,0) --
({(\t*3.1/180)*cos(\t)},{-(\t*3.1/180)*sin(\t)});
%tangent vectors
\foreach \t in {0, 30, ..., 360}
\draw[->, color=red, dashed, very thin] ({(\t*3.14/180)*cos(\t)},{-(\t*3.14/180)*sin(\t)}) --
+({-(\t*3.14/180)*sin(\t) + cos(\t)}, {-(\t*3.14/180)*cos(\t) - sin(\t)});
\end{tikzpicture}
\end{document}
produces exactly what I need for the moment:
I am generating a parametric curve, then drawing position and tangent vectors at various points. I have read through this, this, this, this, this, and this, and, in particular, this answer to a related question was very helpful. I still have a couple questions about doing this more efficiently.
First, is there a way to store coordinates along the curve at various points, then re-use those to create the position and tangent vectors? For example, I'd like to compute and store something like
\foreach \t in {0, 0.5236, ..., 6.28}
\x = {x(t)}
\y = {y(t)}
in an array, where x(t)
and y(t)
are the position functions. I would then use those stored values to create the position vectors as
\for each (\x, \y) in [position array]
\draw[->, color=blue, thin] (0,0) -- (\x,\y);
Similar, for the velocity vectors, I would compute
\foreach \t in {0, 0.5236, ..., 6.28}
\deltax = {x'(t)}
\deltay = {y'(t)}
and create velocity vectors
\for each (\x, \y) in [position array]
\draw[->, color=blue, thin] (\x,\y) -- + (\deltax, \deltay);
where (\deltax,\deltay)
is indexed to match with the appropriate (\x,\y)
position vector.
I have read where pgf / tikz stores gnuplot coordinates in a .table file, but I can't figure out how to access them to do this.
Secondly, I discovered that cos(\t)
and sin(\t)
are using \t
in degrees, so I had to manually convert to radians for the magnitude of the vectors. There has to be a better way to do this? The code
\foreach \t in {0, 30, ..., 360}
\pgfmathparse{rad(\t)}
\draw[->, color=blue, very thin] (0,0) --
({\pgfmathresult*cos(\t)},{-\pgfmathresult*sin(\t)});
does not work.