3

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?

Thank's in advanced!!!

Henri Menke
  • 109,596
  • 1
    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 useatan` if you wish to give tangents instead of angles. Καλησπερα (Good evening) – koleygr Jun 15 '19 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 '19 at 12:03
  • @koleygr , I 'm asking because I tried this, but nothing happens. – Kώστας Κούδας Jun 15 '19 at 12:05
  • @Κώστα I am not using pgfplots ... just creating the axis by lines and arrows with \foreach help... – koleygr Jun 15 '19 at 12:11
  • @koleygr I 'll try your solution. Although I prefer pgfplot, because I think it's more convenient for me. PS: Έλληνας; – Kώστας Κούδας Jun 15 '19 at 12:16
  • 1
    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 '19 at 12:19
  • 1
    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 '19 at 13:04
  • 1
    The hobby library allows you to draw smooth curves and to specify the tangents at points. –  Jun 15 '19 at 13:57
  • @koleygr , thank's for your trying! Χαιρετισμούς από Κέρκυρα! – Kώστας Κούδας Jun 15 '19 at 14:15
  • @JohnKormylo , before I learned about \addplot[color=black,smooth]coordinates... I used to calculate the interpolation polynomial. I spent 15min for something that I could spent 10sec. For this reason I 'm trying to find an automatic solution for my problem. – Kώστας Κούδας Jun 15 '19 at 14:23

1 Answers1

5

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}

enter image description here

  • 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 '19 at 14:28
  • 1
    @KώσταςΚούδας pgfplots is based on tikz. You can definitely use this in an axis environment, too. –  Jun 15 '19 at 14:30
  • I tried your solution but I had this (https://pastebin.com/wd2Fm9Wp) problem. I didn't try to change anything yet. – Kώστας Κούδας Jun 15 '19 at 14:41
  • 1
    @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.) –  Jun 15 '19 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 '19 at 15:10
  • MiKTeX's problem solved. Your answer works fine. One more question: I didn't understand what do you mean, when you said "you can definitely use this in an axis environment". How can I include your code between \begin{axis}...\end{axis}? Everything I tried was wrong... Do you mean than I can make them like this \draw[->] (-5,0) -- (5,0) node[below] {$x$};? Thank's for your patience! – Kώστας Κούδας Jun 16 '19 at 06:43
  • @marmot I tried \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) ..(2,-1).. ([tangent=0]4,2) .. (5,-2); \end{tikzpicture} The curve is not graph of a function. – minhthien_2016 Jun 16 '19 at 07:42