- status: open --> closed-accepted
In bug #482 it was suggested to improve the parabola operation by changing the given coordinates, which were found by "trial and error" as it was stated in the source code.
As it seems also the coordinates for the sin and cos operation are found by trial and error. But even though there is no analytical solution, maybe these coordinates should be replaced by something more "mathematical".
In my comment below the bug report #482 I already tested if the bezierplot could give a better result, which it does not. Also Kpym made a suggestion for an improvement, but it also seems to be worse than the current implementation.
Via email I received a "real" mathematical approach for an improvement by Linus, the author of the bezierplot package. He wrote two python scripts (the attachments) to search for an optimal solution. Both of them found the same solution (given in the last line of the scripts). These indeed seem to be better than the current implementation. Here the "proof":
% used PGFPlots v1.16
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{
compat=1.16,
every axis/.append style={
no markers,
samples=101,
},
}
\makeatletter
\def\pgfpathsine#1{%
{%
\pgf@process{#1}% untransformed
\pgf@xc=\pgf@x%
\pgf@yc=\pgf@y%
\pgf@pt@x=\pgf@path@lastx% evil trickery to transform to the last point
\pgf@pt@y=\pgf@path@lasty%
\pgfpathcurveto%
% -----------------------------------------------------------------------------
% % old solution
{\pgfqpoint{.31831\pgf@xc}{.5\pgf@yc}}% found by trial and error
{\pgfqpoint{.63503\pgf@xc}{\pgf@yc}}% found by trial and error
% -----------------------------------------------------------------------------
% % new solution from Linus' python script (package author of `bezierplot')
% {\pgfqpoint{.3260\pgf@xc}{.5120\pgf@yc}}%
% {\pgfqpoint{.6380\pgf@xc}{\pgf@yc}}%
% -----------------------------------------------------------------------------
{\pgfqpoint{\pgf@xc}{\pgf@yc}}%
}%
}
\def\pgfpathcosine#1{%
{%
\pgf@process{#1}% untransformed
\pgf@xc=\pgf@x%
\pgf@yc=\pgf@y%
\pgf@pt@x=\pgf@path@lastx% evil trickery to transform to the last point
\pgf@pt@y=\pgf@path@lasty%
\pgfpathcurveto%
% -----------------------------------------------------------------------------
% % old solution
{\pgfqpoint{.36497\pgf@xc}{0pt}}% found by trial and error
{\pgfqpoint{.68169\pgf@xc}{.5\pgf@yc}}% found by trial and error
% -----------------------------------------------------------------------------
% % new solution from Linus' python script (package author of `bezierplot')
% {\pgfqpoint{.3620\pgf@xc}{0pt}}%
% {\pgfqpoint{.6740\pgf@xc}{.4880\pgf@yc}}%
% -----------------------------------------------------------------------------
{\pgfqpoint{\pgf@xc}{\pgf@yc}}%
}%
}
\makeatother
\begin{document}
\begin{tikzpicture}
\begin{axis}
% real solution
\addplot+ [domain=0:pi/2] {sin(deg(x))};
% tikz function call (current implementation)
\draw [red,opacity=0.5,dashed]
(0,0) sin (pi/2,1);
% corresponds to the old implementation
\draw [red!50,opacity=0.5,loosely dashed,xscale=pi/2]
(0,0) .. controls (0.31831,0.5) and (0.63503,1) .. (1,1);
% % corresponds to the new implementation suggested by Kpym
% \draw [green!50!black,opacity=0.5,densely dotted,xscale=pi/2]
% (0,0) .. controls (1/pi,0.5) and (2/pi,1) .. (1,1);
% corresponds to the new implementation from Linus' python script
\draw [green!50,opacity=0.5,densely dotted,xscale=pi/2]
(0,0) .. controls (0.3260,0.5120) and (0.6380,1) .. (1,1);
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}
% real solution
\addplot+ [domain=0:pi/2] {cos(deg(x))};
% tikz function call (current implementation)
\draw [red,opacity=0.5,dashed]
(0,1) cos (pi/2,0);
% corresponds to the old implementation
\draw [red!50,opacity=0.5,loosely dashed,xscale=pi/2]
(0,1) .. controls (0.36497,1) and (0.68169,0.5) .. (1,0);
% % corresponds to the new implementation suggested by Kpym
% % (the y values of the control variables have to be `1-<value>')
% \draw [green!50!black,opacity=0.5,densely dotted,xscale=pi/2]
% (0,1) .. controls (1-2/pi,1) and (1-1/pi,0.5) .. (1,0);
% corresponds to the new implementation from Linus' python script
% (the y values of the control variables have to be `1-<value>')
\draw [green!50,opacity=0.5,densely dotted,xscale=pi/2]
(0,1) .. controls (0.3620,1) and (0.6740,0.5120) .. (1,0);
\end{axis}
\end{tikzpicture}
\end{document}