答案1
对于简单和非常平滑的曲线,你可以伪造一个简单的导数动作,就像tikz 路径的衍生物?
然而 TeX 并不是进行这些 CAS 计算的地方。如果你有闭式曲线,那么你可以将公式代入其中,pgfplots
否则它总会在某个时候失败。
\documentclass[tikz]{standalone}
\pgfdeclaredecoration{approxderiv}{initial}{%
\state{initial}[width=0.01mm,
persistent postcomputation={%
\def\tempa{0}%
\pgfmathsetmacro{\plen}{(\pgfdecoratedpathlength-0.01mm)/500}%
\def\myderivlist{}%
},next state=walkthecurve]{}%do nothing
\state{walkthecurve}[width=\plen pt,
persistent postcomputation={%
\pgfmathparse{(sin(\pgfdecoratedangle))}\xdef\tempb{\pgfmathresult}%
\pgfmathparse{abs(cos(\pgfdecoratedangle))*\plen}%
\expandafter\xdef\expandafter\myderivlist\expandafter{%
\myderivlist --++ ({\pgfmathresult pt},{(\tempb-\tempa)*(1cm)})%
}%
\xdef\tempa{\tempb}%
}
]{}%do nothing
}
\begin{document}
\begin{tikzpicture}
\draw[style=help lines] (0,-7) grid[step=5mm] (6,2.5);
\draw[decoration=approxderiv,postaction={decorate}] (0,0) ..controls (2,2) and (1,1) .. (3,0);
\draw[red,decoration=approxderiv,postaction={decorate}] (0,-3) \myderivlist;
\draw[blue] (0,-6) \myderivlist;
\end{tikzpicture}
\end{document}