绘制伯努利双纽线

绘制伯努利双纽线

我想画伯努利双纽线。它的极坐标方程是 r^2=a^2\cos(2\theta),因此绘制起来应该相当简单。选择 a=2,我尝试了以下方法

\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{polar}
\pgfplotsset{compat=1.10}

\begin{document}
\begin{tikzpicture}
  \begin{polaraxis}[style=black!10,grid style=black!10,ticklabel style=black!50,enlargelimits=false, xticklabel=$\pgfmathprintnumber{\tick}^\circ$]
    \addplot [thick, red, domain=0:360, samples=100] {2*sqrt(cos(2*x))};
\end{polaraxis}
\end{tikzpicture}
\end{document}

但结果是

在此处输入图片描述

这可不太好。此外,我还遇到了很多类似这样的错误

NOTE: coordinate (1Y2.3272287e2],3Y0.0e0]) has been dropped because it is unbounded (in y). (see also unbounded coords=jump).

我可以通过增加样本来改善图表的外观,但这会增加编译时间和错误数量,而且永远不会足够流畅。

我不明白发生了什么事。

作为一种解决方法,我可以使用以下方法获得更好看的图形

\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{polar}
\pgfplotsset{compat=1.10}

\begin{document}
\begin{tikzpicture}
  \begin{polaraxis}[style=black!10,grid style=black!10,ticklabel style=black!50,enlargelimits=false, xticklabel=$\pgfmathprintnumber{\tick}^\circ$]
    \addplot [thick, green, domain=-45:45, samples=100] {2*cos(2*x)};
    \addplot [thick, green, domain=135:225, samples=100] {2*cos(2*x)};
\end{polaraxis}
\end{tikzpicture}
\end{document}

由此得出的图形

在此处输入图片描述

从定性的角度来看,这是相同的,但从数学的角度来看,这是完全不同的事情,这并不令人满意。

请注意,该图编译时没有错误,即使只有少量样本也相当流畅。

答案1

正如问题下方的评论中所述,您得到的结果失真是因为您使用了不适当的采样。您可以通过显示标记(替换\addplot\addplot+)来使这一点显而易见。

然后你会发现你需要所有 cos 的采样点(θ) = 0 个角度,即 0°、90°、180°、270°,以确保曲线的所有特征都可见。因此,主要任务是选择适当的domainsamples值或直接地陈述适当的样本使用samples at

为了确保曲线平滑,请添加该smooth选项。

% used PGFPlots v1.18.1
\documentclass{standalone}
\usepackage{pgfplots}
    \usepgfplotslibrary{polar}
    \pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
    \begin{polaraxis}[
        style=black!10,
        grid style=black!10,
        ticklabel style=black!50,
        enlargelimits=false,
        xticklabel=$\pgfmathprintnumber{\tick}^\circ$,
        % ensure a smooth curve
        smooth,
    ]
        % choose appropriate `domain` and `sample` values
        \addplot+ [
            thick,
            domain=-45:225,
            samples=55,
        ] {2*sqrt(cos(2*x))};

        % alternatively "manually" state the samples to use
        \addplot+ [
            samples at={-45,-40,-35,...,45,135,140,...,225},
        ] {2*sqrt(cos(2*x))};
    \end{polaraxis}
\end{tikzpicture}
\end{document}

该图显示了上述代码的结果

相关内容