Plotting a curve using "plot function" Vs Bezier curve (Method of tangents)

Regarding the shown MWE, I need to plot a parabola with the following properties:

• Parabola starts at point "A"
• Parabola ends at point "B"
• Peak of the parabola is at point "F"
• "AE" is tangent to the parabola at point "A"
• "BE" is tangent to the parabola at point "B"
• "I-I" is tangent to the parabola at point "F"

I plotted this parabola using three methods:

• Plot function: The correct one the one in magenta line
• Bezier curve with 2 control points, where only start and end point are defined (Red curve)
• Bezier curve with 2 control points, where start and end points as well as the peak of the parabola are defined (Blue curve).

The issue is, how can I draw the parabola using the method of tangents (control points, bezier curve....) so that I can obtain the same result acheived through the plot function, since I cannot always get the function of the curve. So in short:

• Through the knowledge of the tangents and control points shown: How can I draw the curve using the bezier curve method ( ...controls ...) such that the result is the same as the magenta curve obtained by the "Plot function" (which is the correct one)
• In case I happen to know the angles at (A) and (B) to be (14.036243468) degrees and (82.874983651) degrees respectively (horizontal line: angle = 0) (angles might vary a bit,it is only to emphasize the process), how can I define the angle of the tangents in case I know the angles as well??
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}

\begin{document}

\begin{figure}[!htbp]
\begin{center}
\begin{tikzpicture}

%%%%%%%%%%%%%%GRID%%%%%%%%%%%%%%%%%%%%%%%%

\draw[help lines,step=0.5](0,2) grid(12,25);

\coordinate (a1) at (0,12.5);
\node[circle,inner sep=2pt,fill=none, draw=black] at (a1) (a1) {A};

\coordinate (b1) at (12,12.5);
\node[circle,inner sep=2pt,fill=none, draw=black] at (b1) (b1) {B};

\draw  [very thick] (a1) -- (b1);

\coordinate (V1) at (2*12/3,12.5-0.1*32);
\node[circle,inner sep=2pt,fill=none, draw=black] at (V1) (V1) {E};

\draw [dashed] (a1) -- (V1);
\draw [dashed] (V1) -- (b1);

\coordinate (ZS1) at (12/3^0.5,12.5-0.1*18.475);
\node[circle,inner sep=2pt,fill=none, draw=black] at (ZS1) (ZS1) {F};

\coordinate (V2L) at (0,12.5-0.1*18.475);
\node[circle,inner sep=2pt,fill=none, draw=black] at (V2L) (V2L) {I};

\coordinate (V2'L) at (04.6188,12.5-0.1*18.475);
\node[circle,inner sep=2pt,fill=none, draw=black] at (V2'L) (V2'L) {C};

\coordinate (V2R) at (12,12.5-0.1*18.475);
\node[circle,inner sep=2pt,fill=none,draw=black] at (V2R) (V2R) {I};

\coordinate (V2'R) at (12-2.3094,12.5-0.1*18.475);
\node[circle,inner sep=2pt,fill=none,draw=black] at (V2'R) (V2'R) {B};

\draw[dashed] (V2L) -- (V2R);

%RED CURVE
\draw[very thick,color=red] (a1) .. controls (V2'L) and  (V2'R) .. (b1);

%BLUE CURVE
\draw[very thick,color=blue] (a1) .. controls (V2'L) .. (ZS1) ..  controls (V2'R).. (b1);

%plot the function
\begin{scope}[shift={(0,12.5)}]
\draw[very thick,color=magenta, domain=0:12] plot (\x, {0.1*-(2*-1)*pow(\x,3)/(6*12)+\x*12*0.1*(2*-1)/6});
\end{scope}

\end{tikzpicture}
\end{center}
\end{figure}
\end{document}


• I modified the code and replaced the Stanli packag with the Tikz package. Nov 7, 2020 at 18:35

This is more or less taken from the hobby manual.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{hobby}
\begin{document}
\begin{tikzpicture}[tangent/.style={%
in angle={(180+#1)} ,
Hobby finish ,
designated Hobby path=next , out angle=#1,
}]
\draw[color=magenta,ultra thick, domain=0:12] plot
(\x, {0.1*-(2*-1)*pow(\x,3)/(6*12)+\x*12*0.1*(2*-1)/6});

\draw[thick,use Hobby shortcut] ([tangent=-22]0,0) .. ([tangent=0]7,-1.85) ..
([tangent=38]12,0);

\end{tikzpicture}
\end{document}


And this is a style that uses the hobby library to construct the path from the inputs: start point, end point, tip and point that determines the slopes.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{calc,hobby}
\begin{document}
\begin{tikzpicture}[tangent/.style={%
in angle={(180+#1)} ,
Hobby finish ,
designated Hobby path=next , out angle=#1},
para/.code={\tikzset{/tikz/params/.cd,#1}
\def\pv##1{\pgfkeysvalueof{/tikz/params/##1}}
\tikzset{use Hobby shortcut,insert path={let \p1=($(\pv{S})-(\pv{start})$),
\p2=($(\pv{end})-(\pv{S})$),\n1={atan2(\y1,\x1)},\n2={atan2(\y2,\x2)} in
([tangent=\n1]\pv{start}) .. ([tangent=0]\pv{tip}) .. ([tangent=\n2]\pv{end})
}}
},params/.cd,start/.initial={-1,0},end/.initial={1,0},
tip/.initial={0,-1},S/.initial={0,-2}]
% define the coordinates in an intuitive way
\path (0,0) coordinate (A) (12,0) coordinate (B)
(2*12/3,-0.1*32) coordinate (E)
(12/3^0.5,-0.1*18.475) coordinate (F);
\draw[color=magenta,ultra thick, domain=0:12] plot
(\x, {0.1*-(2*-1)*pow(\x,3)/(6*12)+\x*12*0.1*(2*-1)/6});
\draw[dashed] (A) -- (E) (B) -- (E);
% hobby-based path
\draw[thick,para={start=A,end=B,tip=F,S=E}];
% label the points
\path foreach \X in {A,B,E,F}
{(\X) node[circle,fill,inner sep=1pt,label=below:{$\X$}]{}};
\end{tikzpicture}
\end{document}


Notice that a cubic Bezier curve has 8 parameters. 3 of them are two translation parameters and one angle. So you have 5 parameters that can be used to characterize the curve. You can work backwards to construct the above curve, yet hobby does that for you, at least for the situation you describe here.

• I modified the code and replaced the Stanli packag with the Tikz package, so now the code is run based upon Tikz and not Stanli. It is truly essential to solve this issue using the tikz package. Nov 7, 2020 at 18:34
• It would be nice to know why the Bezier curve method differs from the plot function method. Nov 7, 2020 at 18:36
• @Silva I updated the answer. Yet I cannot really answer the question. There is one thing to note: the two control points have two purposes each: determine the slopes of the tangents and set the "looseness". The "looseness" fixes the turning point. So if you know how to choose the looseness the results should match, but I do not see that you are doing that.
– user227987
Nov 7, 2020 at 19:17
• Why do we need to increase the angle by 180 (180+#1). Also, is there a way to solve using only tikz, I would like to avoid "Hobby". Also did you need points "C" and "D" or did you avoid them? Nov 7, 2020 at 19:30
• @Silva The shift by 180 is due to the definition of in angle (which I find very intuitive). You can avoid hobby, and maybe someone will work this out for you. As for C and D, they are not needed here. As you found yourself, they are not the control points you need. You can compute the relevant control points from the input. I just happen to not see why one should do that, given that the hobby package already exists.
– user227987
Nov 7, 2020 at 20:14