# curve from given points and tangents

This is the inverse problem of that. At that I wanted the tangents given the curve. This time I want the curve given the tangents. I 'll explain it!

Given:

• some points A, B, C,... and K, L, M,... and
• some lines ε, ζ, η,...

how can I draw a curve:

• passing throw the points A, B, C,... and
• tangent to the lines ε, ζ, η,... at the points K, L, M,... respectively

using pgfplot, without calculus?

• Plain tikz could help like : \draw (A) to[out=ε, in=ζ] (B) to[in=180+ζ,out=η] (C); where ε,ζ,η are just the angles that the line leaves (out) the first point and gets into (in) the second etc... Don't even need their tangents... but could use atan if you wish to give tangents instead of angles. Καλησπερα (Good evening) – koleygr Jun 15 at 11:39
• @koleygr , ευχαριστώ πολύ! Do you mean this? \documentclass{article} \usepackage{tikz,pgfplots} \begin{document} \begin{tikzpicture}[>=latex] \begin{axis}[ grid, axis x line=center, axis y line=center, xtick={-5,-4,...,5}, ytick={-5,-4,...,5}, xlabel={$x$}, ylabel={$y$}, xlabel style={below right}, ylabel style={above left}, xmin=-5.5, xmax=5.5, ymin=-5.5, ymax=5.5] \draw (-3,5) to[out=90, in=10] (-2,3) to[in=180+10,out=20] (2,1); \end{axis} \end{tikzpicture} \end{document} – Kώστας Κούδας Jun 15 at 12:03
• Something like this was my solution: \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture}[>=latex] \draw[->] (-5.5,0) --(5.5,0); \draw[->] (0,-5.5) --(0,5.5); \foreach \x in {-5,-4,...,-1}{ \node[below] at (\x,0) {\x}; \node[left] at (0,\x) {\x}; } \foreach \x in {1,2,...,5}{ \node[below] at (\x,0) {\x}; \node[left] at (0,\x) {\x}; } \draw (-3,5) to[out=90, in=10] (-2,3) to[in=180+10,out=20] (2,1); \end{tikzpicture} \end{document} But you could try to find a solution with pgfplots (Sorry, can't really help you). (Greek from Chania) – koleygr Jun 15 at 12:19
• Slopes of curves without calculus? Seriously, just fit a polynomial or spline to all the given points and slopes and plot that. This will require matrix inversions, so do not try it with pgfmath. (You could do it with a calculator.) – John Kormylo Jun 15 at 13:04
• The hobby library allows you to draw smooth curves and to specify the tangents at points. – marmot Jun 15 at 13:57

The hobby library allows you to draw smooth curves for which you specify the tangents at some points. This example is literally from its very well written manual.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{hobby}
\begin{document}
\begin{tikzpicture}[use Hobby shortcut,
tangent/.style={%
in angle={(180+#1)} ,
Hobby finish ,
designated Hobby path=next , out angle=#1,
}, ]
\draw[help lines] (-5,-5) grid (5,5);
\draw (-5,0) -- (5 ,0) (0,-5) -- (0 ,5) ;
\draw[ thick ] (-5,2) .. ([ tangent=0]-3,3) .. (-1,1) ..
(0,-1.3) .. ([tangent=0]1,-2) .. ([tangent=45]2,-1.5) ..
([tangent=0]3,-2) .. (5,-4);
\end{tikzpicture}
\end{document}


• thank's for your answer! Unfortunately pgfplot is more convenient for me. Latex seems Greek to me, so I 'm trying to stay at "places" that I know (pgfplot not hobby). – Kώστας Κούδας Jun 15 at 14:28
• @KώσταςΚούδας pgfplots is based on tikz. You can definitely use this in an axis environment, too. – marmot Jun 15 at 14:30
• I tried your solution but I had this (pastebin.com/wd2Fm9Wp) problem. I didn't try to change anything yet. – Kώστας Κούδας Jun 15 at 14:41
• @KώσταςΚούδας It says ! Package tikz Error: I did not find the tikz library 'hobby'. which is strange since it is part of the standard TeX installations. Which installation do you use? (You could also download the library from CTAN, but the cleaner way is to use the package manager of your installation.) – marmot Jun 15 at 14:54
• maybe a miktex (2.9) problem. I tried to update the packages with miktex console, but an error occurs: The remote package repository is not online. You have to choose another repository.`. I 'll find a solution and I 'll come back. – Kώστας Κούδας Jun 15 at 15:10