我尝试用此代码绘制 $r^2=3\cos{2\theta}$
\documentclass{book}
\usepackage[dvinames]{xcolor}
\usepackage[top=2in,left=1.5in,bottom=1.5in,right=1.5in]{geometry}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage[colorlinks=false,
pdfborder={0 0 0},
]{hyperref}
\usepackage{lipsum}
\usepackage[absolute]{textpos}
\usepackage{tikz}
\usetikzlibrary{spy,fit}
\usetikzlibrary{calc}
\usepackage{color}
\usepackage{pgfplots}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=1.2]
\fill [yellow, domain=0:2*pi, samples=500, variable=\x]
(-2, 0)
-- plot ({deg(\x)}:{3*cos(2*\x r)})
-- (0, 0)
-- cycle;
\draw[->] (-4,0) -- (4,0) node[below right] {$x$};
\draw[->] (0,-4) -- (0,4) node[above] {$y$};
\foreach \n in {-3,3}{%
\draw (\n,-0.7pt) -- (\n,0.7pt) node [below] {$\n$};
% \draw (-0.7pt,\n) -- (0.7pt,\n) node [left] {$\n$ };
}
\foreach \n in {-3,3}{%
% \draw (\n,-0.7pt) -- (\n,0.7pt) node [below] {$\n$};
\draw (-0.7pt,\n) -- (0.7pt,\n) node [left] {$\n$ };
}
\draw[color=orange][domain=0:2*pi,samples=500] plot ({deg(\x)}:{sqrt(3*cos(2*\x r))});
\node [right, orange] at (+1.6,+1.2) {$ r=3\cos{2\theta} $};
\node [darkgray] at (+1.6,+0.4) {$A_1$};
\end{tikzpicture}
\end{center}
\end{document}
但出现错误。我应该怎么办?
答案1
这是我画它的努力。我使用了两个不同的函数+sqrt(3*cos(2*x)
和-sqrt(3*cos(2*x))
。我的代码中的deg()
周围的是必要的,因为该函数只接受度数的值并将弧度转换为度数。2*x
cos()
deg()
\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{polar}
\begin{document}
\begin{tikzpicture}
\begin{axis}[data cs=polarrad, domain=0:2*pi, samples=2500]
\addplot[] {sqrt(3*cos(deg(2*x)))};
\addplot[] {-sqrt(3*cos(deg(2*x)))};
\end{axis}
\end{tikzpicture}
\end{document}