[Tex/LaTex] TikZ: Smooth curve through three points without changing direction

tikz-pgf

In another question (see here) I was asking about how to put the control points of a curve on the tangent of a specific curve point. While the given answers where helpful for that particular arrangement of points, I would like to have a solution for a more general approach to that problem. It is important to me, that the curve does not change its direction at any given point. Consider the following example:

\documentclass[border=5pt,tikz]{standalone}

\usepackage{tikz}
\usetikzlibrary{calc,intersections,through}
\tikzset{point/.style={circle,inner sep=0pt,minimum size=3pt,fill=red}}

\begin{document}
\begin{tikzpicture}

\coordinate [label=left:$A$] (A) at (0,0);
\coordinate [label=left:$B$] (B) at (-.2,3);
\coordinate [label=left:$C$] (C) at (-.7,7);

\draw[thin,blue] plot [smooth] coordinates { (A) (B) (C) };

\node[point] at (A) {};
\node[point] at (B) {};
\node[point] at (C) {};

\end{tikzpicture}
\end{document}

This produces a smooth curve through points A, B and C, as you can see here:

smooth curve 1

However, I want the curve to leave A at an angle of 90 degrees and arrive at C at an angle of -45 degrees, running smoothly through B without changing its direction at any given point. So in this example the curve should always continue to turn to the left. Changing the above \draw statement to this

\draw[thin,green] (A) .. controls +(90:.3)  and +(-85:.2) .. (B) .. controls +(95:.2) and +(-45:.3) .. (C);

produces a curve that is close to what I need.

smooth curve 2

However, I have to guess about the angle of both control points surrounding B. From the blue plot above I figured that those angles are close to -85 and 95, respectively. But I would rather like to calculate these angles instead of eyeballing them.

So is there a way to determine the input and output angles of a bezier curve through B so that the curve does not change its direction anywhere?

Best Answer

Here's an answer to the question using the hobby package from Curve through a sequence of points with Metapost and TikZ.

\documentclass{article}
%\url{https://tex.stackexchange.com/q/309388/86}

\usepackage{tikz}
\usetikzlibrary{calc,intersections,through,hobby}
\tikzset{point/.style={circle,inner sep=0pt,minimum size=3pt,fill=red}}

\begin{document}
\begin{tikzpicture}[use Hobby shortcut]

\coordinate [label=left:$A$] (A) at (0,0);
\coordinate [label=left:$B$] (B) at (-.2,3);
\coordinate [label=left:$C$] (C) at (-.7,7);

\draw[thin,blue] plot [smooth] coordinates { (A) (B) (C) };

\node[point] at (A) {};
\node[point] at (B) {};
\node[point] at (C) {};

\draw[thin,green,out angle=90,in angle=-45] (A) .. (B) .. (C);
\draw[thin,red] (A) .. (B) .. (C);

\end{tikzpicture}
\end{document}

This produces:

curve through B

I wasn't aware of the issue with coordinates on the curve (as mentioned in the comments). I'll have to have a look into that to see what's going on with that.