# hobby: trouble getting tangency information at a point to affect drawn path as expected

Consider the minimum not working example here:

\documentclass{article}

\usepackage{lmodern}
\usepackage[T1]{fontenc}

\usepackage{tikz}
\usetikzlibrary{calc, hobby}
\tikzset{
tangent/.style = {
in angle={(180+#1)},
Hobby finish,
designated Hobby path=next,
out angle=#1
}
}

\begin{document}
\begin{figure}[htbp]
\centering
\begin{tikzpicture}

\coordinate (y) at (0,3);
\coordinate (x) at (5,0);

\coordinate (sp0) at (1.5,0);
\coordinate (ep0) at (3.5,2);
\coordinate (csp0) at (2.5,1);
\coordinate (cep0) at (2.75,0);

\coordinate (sp1) at (ep0);
\coordinate (ep1) at (4.5,3);
\coordinate (csp1) at (4.25,4);
\coordinate (cep1) at (4.25,2);

\coordinate (sp2) at (sp0);
\coordinate (ep2) at (0,-1);
\coordinate (csp2) at (0.5,-1);
\coordinate (cep2) at (0.5,-1);

\draw[<->] (y) node[left] {$f(x)$} -- (0,0) --  (x) node[below] {$x$};

% Using \pgfmathanglebetweenpoints to calculate the angle for tangent
% tangent takes a degree unit angle
\pgfmathanglebetweenpoints{\pgfpointanchor{cep0}{center}}{\pgfpointanchor{ep0}{center}}
\let\angle=\pgfmathresult
\draw (ep2) to [curve through ={(sp0) .. ([tangent=\angle]ep0)}] (ep1) ;

\draw[dashed] (cep0) -- (csp1);
\draw[dotted] let \p1 = (ep0) in (ep0) -- (0,\y1);
\draw[dotted] let \p1 = (ep0) in (ep0)-- (\x1,0);

\draw let \p1 = (ep0) in (\x1,1pt) -- (\x1,-3pt) node[anchor=north] {$x_0$};
\draw let \p1 = (cep0) in (\x1,1pt) -- (\x1,-3pt) node[anchor=north] {$x_1$};
\draw let \p1 = (ep0) in (1pt,\y1) -- (-3pt,\y1) node [anchor=east] {$f(x_0)$};
\end{tikzpicture}
\caption{Newton's method in action: diagram drawn using the \texttt{hobby} package.}
\label{fig:newton_method_2}
\end{figure}
\end{document}


It produces output like so:

However, if the angle information was working as I would have expected it to, then the solid path drawn by hobby would have been tangent to the sloped dashed line. I have tried tweaking a few things, and my impression is that the "angle" information affects the path relative to the direction of path rather than some standard coordinate system (I would have expected 0 degrees to be in the direction of the positive x-axis, and positive angles representing CCW deviations from the positive x-axis)?

How can I get it to work as I expect? Or alternatively, how does the tangent function as defined work compared to how I expect it to?

• [Like this and in many of your other questions ;).] Not entirely minimal, but pretty close! – cfr Feb 1 '15 at 4:05

The tangent option wasn't designed to be used with the curve through syntax since it was written to fix a problem that the curve through syntax doesn't have. The tangent option works with the shortcut syntax. The problem is that if one wants to follow a Hobby curve by another Hobby curve then this is difficult to signal using the shortcut syntax but not with the curve through variant. The tangent key is designed to make it easy to insert such a break.

So your code works with the shortcut code:

\draw[use Hobby shortcut] (ep2)  .. (sp0) .. ([tangent=\angle]ep0) .. (ep1) ;


It also works with the curve through if I manually put the break in:

\draw (ep2) to [curve through ={([out angle=\angle]sp0)}] (ep0);


except that the second part of the curve (from (ep0) to (ep1)) doesn't have a middle point and the curve through doesn't really cope well with that.

So I think I recommend the shortcut syntax for what you are doing.

• Thanks for your answer, and especially for making this package! – user89 Feb 1 '15 at 16:45