# TikZ: Automating a process with a for loop instead of coding in each piece

I am positive I could create the incoming hyperbolas and then the deflections by the planet by hand for each one, but how the image is set up conjures up the felling this could be done through automation of a loop.

\documentclass[convert = false, tikz]{standalone}
\usetikzlibrary{arrows}
\tikzset{
partial circle/.style args = {#1:#2:#3}{
insert path = {+ (#1:#3) arc (#1:#2:#3)}
}
}
\begin{document}
\begin{tikzpicture}
\def\angle{60}
\def\a{1}
\pgfmathsetmacro{\b}{\a / tan(\angle)}

\begin{scope}[rotate = {180 - \angle}, shift = {(0, -\a - \circradius)}]
\draw plot[red, domain = 0:2.5, samples = 100]
({\x}, {\a * sqrt(1 + (\x / \b)^2)});
\end{scope}

\draw[-latex] (.4, 0) -- (1, 0);
\draw[dashed] (-5, 0) -- (.2, 0);
\draw[thick, gray] (0, 0) [partial circle = -210:-150:4cm];
\end{tikzpicture}
\end{document}


The issues at hand are:

1. stopping ever hyperbola at the arc. How can this be done? I don't see how intersections could be used here. Even if we did a path of the hyperbola first and identified the intersection, how do I say draw from a function to a point? I just put 2.5 as the domain and it worked well but that was purely luck.

2. automating the process with a loop for 5 different hyperbolas.

3. setting up the deflection curves.

4. having the color of each hyperbola cycle.

5. using decorations.markings to decorate postaction with an arrow. Does that work well in a loop? If so, I wouldn't know how to achieve it unless there isn't anything special to do.

We could use \path to add in circle radius of fictitious circles for the other hyperbolas, but again, I am not versed in using loops or foreach in TikZ. So the only challenge I would think is the deflection trajectories. I don't have a model for them and they would differ per planet but that last part is irrelevant since I am just showing a diagram of what would happen for an arbitrary planet.

How can those partials hyperbolas and then the ensuing deflections be automated with a foreach loop?

Here is a reference link on how Jubob's added a hyperbola using periapsis and the fact that the equation for a hyperbola is x^2/a^2 - y^2/b^2 = 1. Additionally, form the figure, we know that the asymptote runs parallel to the x axis.

TikZ: constructing a piece of a hyperbola with a given asymptote

-

I have a partial answer. I have completed the automation of the hyperbolas stopping at the arc. So there is still a lot to improve on for those interested in picking up the bounty since I can't claim it.

\documentclass[convert = false, tikz, usenames, dvipsnames]{standalone}
\tikzset{
partial circle/.style args = {#1:#2:#3}{
insert path = {+ (#1:#3) arc (#1:#2:#3)}
}
}
\begin{document}
\begin{tikzpicture}[
every label/.append style = {font = \small},
dot/.style = {outer sep = 0pt, inner sep = 0pt,
shape = circle, label = {#1}},
dot/.default =,
small dot/.style = {minimum size = .05cm, dot = {#1}},
small dot/.default =,
big dot/.style = {minimum size = .15cm, dot = {#1}},
big dot/.default =
]

\def\angle{40}
\def\dom{5}

\draw[-latex] (.4, 0) -- (1, 0);
\draw[dashed] (-5, 0) -- (.2, 0);
\draw[thick, gray] (0, 0) [partial circle = -210:-150:4cm];

\begin{scope}
\begin{pgfinterruptboundingbox}
\clip (0, 0) circle[radius = 4cm];

\foreach \a/\circ/\col in
{1/.3/orange, 1.05/.42/blue, 1.1/.52/green, 1.15/.62/red,
1.2/.72/Goldenrod}{
\pgfmathsetmacro{\b}{\a / tan(\angle)}
\begin{scope}[rotate = {180 - \angle}, shift = {(0, -\a - \circ)}]
\draw[\col] plot[red, domain = 0:\dom, samples = 100]
({\x}, {\a * sqrt(1 + (\x / \b)^2)})
node[fill = \col, draw = \col, small dot = {}] at (0, \a) {};
\end{scope}
}
\end{pgfinterruptboundingbox}
\end{scope}

\begin{scope}[rotate = {180 - \angle}, shift = {(0, -1.585)}]