我想策划卡西尼曲线与pgfplot
(避免gnuplot
)
对于a=1
和c=1.7
函数r(\p)=sqrt(a^2*cos(2*\p)+sqrt(a^4*(cos(2*\p))^2+(c^4-a^4)))
应该给出类似于(卡西尼式)椭圆的东西。
但我得到了一个奇怪的螺旋:
我需要做什么?
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
declare function={
a=1;
c=1.7;
r(\p)=sqrt(a^2*cos(2*\p)+sqrt(a^4*(cos(2*\p))^2+(c^4-a^4)));
},
]
\begin{axis}[
axis lines=center,
axis equal,
enlargelimits=true,
%smooth,
samples=222,
]
\addplot[data cs=polar, red, domain=0:360] (x,{r(x)});
\end{axis}
\end{tikzpicture}
\end{document}
答案1
r(x)
是保留的。请记住始终设置兼容级别 - 请参阅代码。
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
declare function={
a=1;
c=1.7;
cassini(\p)=sqrt(a^2*cos(2*\p)+sqrt(a^4*(cos(2*\p))^2+(c^4-a^4)));
},
]
\begin{axis}[
axis lines=center,
axis equal,
enlargelimits=true,
]
\addplot[data cs=polar, red, domain=0:360, samples=100, smooth] (x,{cassini(x)});
\end{axis}
\end{tikzpicture}
\end{document}
为了c=0.7
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
declare function={
a=1;
c=0.7;
cassinip(\p)=sqrt(a^2*cos(2*\p)+sqrt(a^4*(cos(2*\p))^2+(c^4-a^4)));
cassinin(\p)=sqrt(a^2*cos(2*\p)-sqrt(a^4*(cos(2*\p))^2+(c^4-a^4)));
},
]
\begin{axis}[
axis lines=center,
axis equal,
enlargelimits=true,
unbounded coords=jump,
]
\addplot[data cs=polar, red, domain=0:360, samples=1000, smooth] (x,{cassinip(x)});
\addplot[data cs=polar, red, domain=0:360, samples=1000, smooth] (x,{cassinin(x)});
\end{axis}
\end{tikzpicture}
\end{document}
在这里,我把 增加到了samples
一个荒谬的量,以更接近真正的曲线 - 封闭的圆。考虑不要使用极坐标,因为奇点在 xy 坐标中更容易处理。例如像y filter/.expression
这里https://tex.stackexchange.com/a/587018/8650