TikZ 能更准确地绘制立方根函数吗?

TikZ 能更准确地绘制立方根函数吗?

我画了一条抛物线、两个椭圆和一个立方根函数水平位移的倍数,如下TikZ图所示。只有后者画得不好。只使用TikZ,有没有办法画得更准确?

\documentclass[10pt]{amsart}

\usepackage{mathtools,array}

\usepackage{tikz}
\usetikzlibrary{calc}





\begin{document}



\begin{center}
\begin{tikzpicture}



%Part of two ellipses and a parabola are drawn.
\draw (0,0) arc (0:90: 2 and 1);
\draw (0,0) arc (0:-72: 2 and 1);
\path node[anchor=east] at ({-2+sqrt(31)/8},-15/16){$E$};
\draw[fill] (0,0) circle (1.5pt);
%
\draw (3,0) arc (180:90: 2 and 1);
\draw (3,0) arc (180:252: 2 and 1);
\path node[anchor=west] at ({5-sqrt(31)/8},-15/16){$F$};
\draw[fill] (3,0) circle (1.5pt);
%
\draw[domain=-1:4, smooth, variable=\x, blue] plot ({\x}, {-1/9*\x*\x + 1/3*\x});
\path node[anchor=south west, xshift=-0.5mm, yshift=-1mm] at (3.75,-5/16){$G$};
%
%A "pin" is drawn between (0,0) and its label.
\draw[draw=gray, line width=0.8pt, shorten <=1.5mm, shorten >=1mm] (0,0) -- ({(atan(1/3)+90)/2}:0.75);
\path node[anchor=south west, inner sep=0] (P) at ({(atan(1/3)+90)/2}:0.75 ){$P$};
%
%A "pin" is drawn between (3,0) and its label Q.
\draw[draw=gray, line width=0.8pt, shorten <=1.5mm, shorten >=2mm] (3,0) -- ($(3,0) +({(atan(-1/3)+180+90)/2}:0.75)$);
\node[anchor=base, baseline={P.base}, inner sep=0] (Q) at ($(3,0) +({(atan(-1/3)+180+90)/2}:0.75)$) {$Q$};




%
\draw[domain=1.5:4, smooth, variable=\x] plot ({\x}, {3/2*pow((\x - 3/2),1/3) + 1/4});
\draw[domain=-1:1.5, smooth, variable=\x] plot ({\x}, {-3/2*pow((3/2 - \x),1/3) + 1/4});
\draw[fill] (3/2,1/4) circle (1.5pt);
\node[anchor=north west] at (3/2,1/4){$R$};
\path node[anchor=west] at (4,2.2858){$H$};


\end{tikzpicture}
\end{center}


\end{document}

答案1

为了使曲线更平滑,您可以使用samples选项,该选项将表示绘图样本数量的整数作为值。其默认值为 25(对于/tikz/samples和 都成立/pgfplots/samples)。数字越大,绘图越平滑,但编译时间也越长。

由于舍入误差,图的末尾(靠近坐标(3/2,1/4))可能存在间隙,在这种情况下,您可以通过翻转选项的值轻松解决该domain问题。这样,TiZ 将从坐标处开始绘制图表(3/2,1/4),因此,如果由于舍入误差而出现间隙,它将位于图表的另一端,这并不是什么大问题。

另一种弥补这一差距的解决方案是,只需在路径中添加最后一个缺失的部分-- (3/2,1/4),但这样做可能被认为是一种快速而粗糙的修复方法。此外,使用samples at这个答案可能是一个解决方案,但我不知何故未能以令人满意的方式在这里应用它。最后,正如同一答案中所建议的那样,使用样本值 2+ 1 也应该可以防止出现此类间隙,因此您可以使用samples=257,例如。

以下示例显示如何使用samples并使用选项的翻转值domain

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}

%Part of two ellipses and a parabola are drawn.
\draw (0,0) arc (0:90: 2 and 1);
\draw (0,0) arc (0:-72: 2 and 1);
\path node[anchor=east] at ({-2+sqrt(31)/8},-15/16){$E$};
\draw[fill] (0,0) circle (1.5pt);
%
\draw (3,0) arc (180:90: 2 and 1);
\draw (3,0) arc (180:252: 2 and 1);
\path node[anchor=west] at ({5-sqrt(31)/8},-15/16){$F$};
\draw[fill] (3,0) circle (1.5pt);
%
\draw[domain=-1:4, smooth, variable=\x, blue] plot ({\x}, {-1/9*\x*\x + 1/3*\x});
\path node[anchor=south west, xshift=-0.5mm, yshift=-1mm] at (3.75,-5/16){$G$};
%
%A "pin" is drawn between (0,0) and its label.
\draw[draw=gray, line width=0.8pt, shorten <=1.5mm, shorten >=1mm] (0,0) -- ({(atan(1/3)+90)/2}:0.75);
\path node[anchor=south west, inner sep=0] (P) at ({(atan(1/3)+90)/2}:0.75 ){$P$};
%
%A "pin" is drawn between (3,0) and its label Q.
\draw[draw=gray, line width=0.8pt, shorten <=1.5mm, shorten >=2mm] (3,0) -- ($(3,0) +({(atan(-1/3)+180+90)/2}:0.75)$);
\node[anchor=base, baseline={P.base}, inner sep=0] (Q) at ($(3,0) +({(atan(-1/3)+180+90)/2}:0.75)$) {$Q$};
%
\draw[domain=1.5:4, smooth, variable=\x, samples=200] plot ({\x}, {3/2*pow((\x - 3/2),1/3) + 1/4});
\draw[domain=1.5:-1, smooth, variable=\x, samples=200] plot ({\x}, {-3/2*pow((3/2 - \x),1/3) + 1/4});
\draw[fill] (3/2,1/4) circle (1.5pt);
\node[anchor=north west] at (3/2,1/4){$R$};
\node[anchor=west] at (4,2.2858){$H$};

\end{tikzpicture}

\end{document}

在此处输入图片描述

答案2

如果您在绘制草图时遇到困难(尤其是当图形垂直时),一个好方法是尝试找到图形的参数形式。有时这很困难,但在这种情况下,您可以反转表达式并将 x 绘制为 y 的函数。这与另一个答案的图形相匹配:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}

%Part of two ellipses and a parabola are drawn.
\draw (0,0) arc (0:90: 2 and 1);
\draw (0,0) arc (0:-72: 2 and 1);
\path node[anchor=east] at ({-2+sqrt(31)/8},-15/16){$E$};
\draw[fill] (0,0) circle (1.5pt);
%
\draw (3,0) arc (180:90: 2 and 1);
\draw (3,0) arc (180:252: 2 and 1);
\path node[anchor=west] at ({5-sqrt(31)/8},-15/16){$F$};
\draw[fill] (3,0) circle (1.5pt);
%
\draw[domain=-1:4, smooth, variable=\x, blue] plot ({\x}, {-1/9*\x*\x + 1/3*\x});
\path node[anchor=south west, xshift=-0.5mm, yshift=-1mm] at (3.75,-5/16){$G$};
%
%A "pin" is drawn between (0,0) and its label.
\draw[draw=gray, line width=0.8pt, shorten <=1.5mm, shorten >=1mm] (0,0) -- ({(atan(1/3)+90)/2}:0.75);
\path node[anchor=south west, inner sep=0] (P) at ({(atan(1/3)+90)/2}:0.75 ){$P$};
%
%A "pin" is drawn between (3,0) and its label Q.
\draw[draw=gray, line width=0.8pt, shorten <=1.5mm, shorten >=2mm] (3,0) -- ($(3,0) +({(atan(-1/3)+180+90)/2}:0.75)$);
\node[anchor=base, baseline={P.base}, inner sep=0] (Q) at ($(3,0) +({(atan(-1/3)+180+90)/2}:0.75)$) {$Q$};
%
\draw[domain=-1.78:2.28,variable=\y]plot({((\y-.25)*2/3)^3+1.5},{\y});
%\draw[domain=1.5:4, smooth, variable=\x] plot ({\x}, {3/2*pow((\x - 3/2),1/3) + 1/4});
%\draw[domain=-1:1.5, smooth, variable=\x] plot ({\x}, {-3/2*pow((3/2 - \x),1/3) + 1/4});
\draw[fill] (3/2,1/4) circle (1.5pt);
\node[anchor=north west] at (3/2,1/4){$R$};
\node[anchor=west] at (4,2.2858){$H$};

\end{tikzpicture}

\end{document}

相关内容