TikZ 没有 pstricks-add

TikZ 没有 pstricks-add

如果可能的话,我需要您的帮助来使用 TikZ/PGF 而不是 pstricks 转换此文档:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[a4paper]{geometry}
\usepackage{mathrsfs}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{ifthen}
\usepackage{fp}
\usepackage{pstricks-add}
\usepackage[frenchb]{babel}
\usepackage[colorlinks]{hyperref}

%% macro trace tangente
\def\traceTangente(#1,#2,#3,#4){%
\ifthenelse{\lengthtest{#4pt>0pt}}{\FPeval\DemiTangenteV{(#3)*(#4)}
\FPeval\TangentXa{(#1)-(#4)}
\FPeval\TangentXb{(#1)+(#4)}
\FPeval\TangentYa{(#2)-(\DemiTangenteV)}
\FPround\TangentYa\TangentYa{3}
\FPeval\TangentYb{(#2)+(\DemiTangenteV)}
\FPround\TangentYb\TangentYb{3}
\psline{<->,linecolor=orange!50!red}(\TangentXa,\TangentYa)(\TangentXb,\TangentYb)}{}}
\makeatletter
%% macro interpolation
\def\Interpolation(#1,#2,#3)(#4,#5,#6){%
\edef\PolyInterp{(x+(-1)*(#4))^2*((1+(-2)*(x+(-1)*(#1))*(#1+(-1)*
(#4))/((#1+(-1)*(#4))^2))*#2+(x+(-1)*(#1))*#3)/((#1+(-1)*(#4))^2)+(x+
(-1)*(#1))^2*((1+(-2)*(x+(-1)*(#4))*(#4+(-1)*(#1))/((#1+(-1)*(#4))^2))
*#5+(x+(-1)*(#4))*#6)/((#1+(-1)*(#4))^2)}%
\psplot[algebraic=true,linecolor=cyan!50!blue,linewidth=1.2pt]{#1}{#4}{\PolyInterp}}
%% la macro principale
\def\HermiteDDL(#1,#2,#3,#4){\def\Hermite@xa{#1}\def\Hermite@ya{#2}\def\Hermite@za{#3}
\psdot(#1,#2)
\traceTangente(#1,#2,#3,#4)\Hermite@next}

\def\Hermite@next{\@ifnextchar ({\Hermite@job}{\Hermite@end}}

\def\Hermite@job(#1,#2,#3,#4){%
\psdot(#1,#2)
\Interpolation(\Hermite@xa,\Hermite@ya,\Hermite@za)(#1,#2,#3)
\def\Hermite@xa{#1}\def\Hermite@ya{#2}\def\Hermite@za{#3}
\traceTangente(#1,#2,#3,#4)\Hermite@next}
\def\Hermite@end{}

\makeatother

\begin{document}
\begin{center}
\begin{pspicture*}(-5,-5.5)(10.5,4.5)
\psgrid[gridlabels=0,subgriddiv=1,griddots=7](0,0)(-5,-5)(10,5)
\psaxes{->}(0,0)(-5,-5.5)(10,5)
\psaxes(0,0)(-5,-3)(9,5)
\HermiteDDL(-5,1,1,1)(-3,2,-2,1)(-1,-2,3,1)(0,2,1,1)(2,1,0,1)(4,0,0.666,3)(6,-2,-2,1)(9,2,0.5,1)(10,-1,-4,0)
\end{pspicture*}
\end{center}
\end{document}

答案1

这只是部分解决方案。我无法添加轴,因为我不太了解 TikZ。取消注释这些\begin{axis}位会破坏我的情节。 更新:感谢@TorbjørnT.,斧头现在可以工作了。

另外,我必须将多项式内联到绘图命令中,因为它会中断,而且我不知道任何其他解决方案。

在此处输入图片描述

\documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage{mathrsfs}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{ifthen}
\usepackage{fp}
\usepackage[colorlinks]{hyperref}

\usepackage{tikz}


%% macro trace tangente
\def\traceTangente(#1,#2,#3,#4){%
\ifthenelse{\lengthtest{#4pt>0pt}}{\FPeval\DemiTangenteV{(#3)*(#4)}
\FPeval\TangentXa{(#1)-(#4)}
\FPeval\TangentXb{(#1)+(#4)}
\FPeval\TangentYa{(#2)-(\DemiTangenteV)}
\FPround\TangentYa\TangentYa{3}
\FPeval\TangentYb{(#2)+(\DemiTangenteV)}
\FPround\TangentYb\TangentYb{3}
\draw [<->,color=orange!50!red] (\TangentXa,\TangentYa) -- (\TangentXb,\TangentYb);}{}}

\makeatletter
%% macro interpolation
\def\Interpolation(#1,#2,#3)(#4,#5,#6){%
\draw[domain=#1:#4,smooth,variable=\x,color=cyan!50!blue,line width=1.2pt]%
  plot (\x,{(\x+(-1)*(#4))^2*((1+(-2)*(\x+(-1)*(#1))*(#1+(-1)*%
(#4))/((#1+(-1)*(#4))^2))*#2+(\x+(-1)*(#1))*#3)/((#1+(-1)*(#4))^2)+(\x+%
(-1)*(#1))^2*((1+(-2)*(\x+(-1)*(#4))*(#4+(-1)*(#1))/((#1+(-1)*(#4))^2))%
*#5+(\x+(-1)*(#4))*#6)/((#1+(-1)*(#4))^2)});}
%% la macro principale
\def\HermiteDDL(#1,#2,#3,#4){\def\Hermite@xa{#1}\def\Hermite@ya{#2}\def\Hermite@za{#3}%
\traceTangente(#1,#2,#3,#4)
\fill (#1,#2) circle[radius=1pt];
\Hermite@next
}

\def\Hermite@next{\@ifnextchar ({\Hermite@job}{\Hermite@end}}

\def\Hermite@job(#1,#2,#3,#4){%
\fill (#1,#2) circle[radius=1pt];  
\Interpolation(\Hermite@xa,\Hermite@ya,\Hermite@za)(#1,#2,#3)
\def\Hermite@xa{#1}\def\Hermite@ya{#2}\def\Hermite@za{#3}
\traceTangente(#1,#2,#3,#4)\Hermite@next}
\def\Hermite@end{}

\makeatother

\begin{document}
\begin{center}
  \begin{tikzpicture}
    \draw[help lines, color=gray!30, dashed] (-6.2,-5.1) grid (10.1,4.5);
    \draw [-stealth] (-6,0) -- (10,0);
    \draw [-stealth] (0,-5.3) -- (0,4.5);
    \foreach \x in {-6,...,-1,1,2,...,9}
    \draw (\x,2pt) -- (\x,-2pt) node[below]{$\x$};
    \foreach \y in {-5,...,-1,1,2,3,4}
       \draw (2pt,\y) -- (-2pt,\y) node[left]{$\y$};
    \HermiteDDL(-5,1,1,1)(-3,2,-2,1)(-1,-2,3,1)(0,2,1,1)(2,1,0,1)(4,0,0.666,3)(6,-2,-2,1)(9,2,0.5,1)(10,-1,-4,0) 
  \end{tikzpicture}
\end{center}
\end{document}

The above on Overleaf

相关内容