# TikZ: How can I extend a line to match another line (bad title, best I could do)

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc, arrows, intersections}
\begin{document}
\begin{tikzpicture}[line cap = round, line join = round, >=triangle 45,
fixed point arithmetic]
\coordinate (P1) at (-2, 0);
\coordinate (P2) at (2.5, 0);
\coordinate (P3) at (2, 0);

\draw (P1) -- (P2);
\draw[red] (P3) circle (.1cm);
\path[name path = line] (P1) -- (70: 4.5cm and 2.5cm);
\path[name path = arc] (P3) arc (0:70: 4cm and 2cm) coordinate (P4);
\path[name intersections = {of = line and arc, by = P4}];

\begin{scope}
\clip (P4) rectangle (P3);
\draw (P3) arc (0:70: 4cm and 2cm);
\end{scope}

\draw[-latex] (P1) -- (P4) node[above, scale = .75, pos = .5, fill = white,
inner sep = 0cm] {$$\mathbf{r}$$};

\draw[orange] let
\p1 = (P1),
\p3 = (P3),
\p4 = (P4),
\n1 = {atan2(\x3 - \x1, \y3 - \y1)},
\n2 = {atan2(\x4 - \x1, \y4 - \y1)},
\n3 = {.75cm}
in (P1) +(\n1:\n3) arc[radius = \n3, start angle = \n1, end angle = \n2]
node [scale = .75, shift = {(.5cm, -.25cm)}] {$$\nu$$};

\path[name path = aux] (P4) circle [radius = 1bp];

\draw[name intersections = {of = arc and aux}, -latex] (P4) --
($(intersection-2)!1cm!(intersection-1)$);
\draw[-latex] (P4) -- ($(P4)!1cm!-90:(P1)$);
\end{tikzpicture}
\end{document}


How can I extend the line tangent to the end of the arc to the length of the perpendicular line? I know I could make another perpendicular \path at the end of the first perpendicular line, then run a longer tangential \path, mark the intersection, and change my tangential line to that new marked intersection. However, there has to be a better way.

-
@Jake I forgot to copy this over: \draw[-latex] (P4) -- ($(P4)!1cm!-90:(P1)$); I will add it to the OP – dustin Jun 27 '13 at 3:47
Does the length of the perpendicular arrow have to be fixed, or would you also be happy with a solution where you fix the length of the tangential arrow and make the length of the perpendicular arrow depend on that? – Jake Jun 27 '13 at 4:17
@Jake either is fine. – dustin Jun 27 '13 at 4:22
This was exactly my question, too bad I don't understand the answer :/ – Mac Oct 25 '15 at 18:15

If you name the coordinate at the end of the tangential arrow (P5), you can use the calc library's projection syntax to draw the perpendicular arrow to the correct length.

Using the projection syntax, the expression

($(A)!(C)!(B)$)


describes the projection of C on the line from A to B. This can be combined with the rotation syntax:

($(A)!(C)!90:(B)$)


describes the projection of C on the line from A to B, after that line has been rotated around A by 90 degrees.

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, arrows, intersections}
\begin{document}
\begin{tikzpicture}[line cap = round, line join = round, >=triangle 45]
\coordinate (P1) at (-2, 0);
\coordinate (P2) at (2.5, 0);
\coordinate (P3) at (2, 0);

\path[name path = line] (P1) -- (70: 4.5cm and 2.5cm);
\path[name path = arc] (P3) arc (0:70: 4cm and 2cm) coordinate (P4);
\path[name intersections = {of = line and arc, by = P4}];

\begin{scope}
\clip (P4) rectangle (P3);
\draw (P3) arc (0:70: 4cm and 2cm);
\end{scope}

\draw[-latex] (P1) -- (P4);
\path[name path = aux] (P4) circle [radius = 1bp];

\draw[name intersections = {of = arc and aux}, -latex] (P4) --
($(intersection-2)!1.2cm!(intersection-1)$) coordinate (P5);
\draw[-latex] (P4) -- ($(P4)!(P5)!-90:(P1)$);

\end{tikzpicture}
\end{document}

-
I knew there had to be an easier way then what I was going to do. – dustin Jun 27 '13 at 4:27