# Tikz: unit tangent vectors to a curve

I looked at many of the question here and on www.texample.net on how to construct tangent lines to a given point but I have no idea how to do this.

Let's take a very simple example.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0) ellipse (2cm and 1cm);
\node[shape = circle, fill] (P) at ({2 * cos(163)}, {1 * sin(163)}) {};
\end{tikzpicture}
\end{document}


How would I put a unit tangent vector going counter clockwise at P?

-

You can approximate the tangent by placing a very small circle path around your tangent point and finding the intersection between that small circle and the ellipse. You can then use the calc library to draw the tangent using.

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections, calc}
\begin{document}
\begin{tikzpicture}
\draw [name path=ellipse] (0,0) ellipse (2cm and 1cm);
\node[shape = circle, inner sep=1.5pt, fill] (P) at (163:2cm and 1cm) {};
\path [name path=aux] (P) circle [radius=1bp];
\draw [name intersections={of=ellipse and aux}] (P) -- ($(intersection-1)!1cm!(intersection-2)$);
\end{tikzpicture}
\end{document}


A different approach is to use a path with an arc to place a node with the sloped option, which will result in the node being oriented along the arc. You can then use the node's anchors to draw the tangent with a fixed length using the calc library. If your node's name is tangent, you'd get the unit vector using

\draw (tangent.center) -- ($(tangent.center)!1cm!(tangent.west)$);


\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\def\angle{163}
\draw (0,0) ellipse (2cm and 1cm);
\node[shape = circle, inner sep=1.5pt, fill] (P) at (\angle:2cm and 1cm) {};
\path (2,0) arc [
start angle=0,
end angle=\angle,
]  node [pos=1,sloped, name=tangent] {};
\draw (tangent.center) -- ($(tangent.center)!1cm!(tangent.west)$);
\end{tikzpicture}
\end{document}

-
Why did you draw a separate path to point P? – dustin Jun 18 '13 at 3:37
Because the node needs to be specified as part of a path, so that the slope can be determined. The path isn't drawn. – Jake Jun 18 '13 at 3:37
What if we didn't know the angle location but there was an arbitrary point P. How could we handle that case? – dustin Jun 18 '13 at 3:40
The reason I ask is because I am plan on adapting this to the problem we worked on earlier where we found P1 and P2 with the intersection library. That is, we don't know the actual location since it was found behind the scene. – dustin Jun 18 '13 at 3:43
@dustin: Good point. I've added another approach. – Jake Jun 18 '13 at 4:09