在 tikz 中标记角度

在 tikz 中标记角度
\documentclass[12pt]{article}



\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{tikz, tkz-euclide,tikz-3dplot,ifthen}
\usepgfplotslibrary{fillbetween}

\begin{document}
\begin{tikzpicture}[scale=0.8]
\begin{axis}[
    xmin=-3, xmax=3,
    ymin=-3, ymax=3,
    samples=100,
    ticks=none,
    axis lines=middle,
       xlabel={$x$},
      ylabel={$y$},
   ]





\addplot[name path=p1,domain=-2:0]{sqrt(1-(x+1)^2)};
\addplot[name path=p2,domain=-2:0]{-sqrt(1-(x+1)^2)};
\addplot[name path=p3,domain=-1:0]{sqrt(1-x^2)};
\addplot[name path=p4,domain=-1:0]{-sqrt(1-x^2)};
\addplot[name path=p5,domain=0:1]{sqrt(1-x^2)};
\addplot[name path=p6,domain=0:1]{-sqrt(1-x^2)};

\addplot [color=gray!50,   opacity=0.5]%
        fill between [of=p1 and p2, soft clip={domain=-0.5:0}];
\addplot [color=gray!50,  opacity=0.5]%
        fill between [of=p3 and p4, soft clip={domain=-1:-0.5}];

\draw[fill=black]({cos(deg(2*pi/3))},{sin(deg(2*pi/3))})circle(2pt)node[above left,  xshift=0.5cm]{$\theta=\frac{2\pi}{3}$};

\draw[fill=black]({cos(deg(4*pi/3))},{sin(deg(4*pi/3))})circle(2pt)node[below left,  xshift=0.5cm]{$\theta=\frac{4\pi}{3}$};

\draw[dotted,  thick](0,0)--(-1/2,{sqrt(1-(0.5)^2)});
\draw[dotted,  thick](0,0)--(-1/2,-{sqrt(1-(0.5)^2)});

\draw[samples=100,domain=2*pi/3:4*pi/3] plot({0.2*cos(deg(\x))},{0.2*sin(deg(\x ))});
\draw(-0.4,0)node[]{$\frac{2\pi}{3}$};

\end{axis}

\end{tikzpicture}
\end{document}

我想标记两条虚线之间的角度,但我不知道该怎么做。我也尝试了 \tkzMarkAngle,但在 \begin{axis}~\end{axis} 中,它似乎不起作用。

在此处输入图片描述

答案1

由于您想保留代码原样,我仅添加了绘制此角度所需的内容。您只需使用angles库并将coordinates 放在您已经计算的那些交点上(参见代码的最后一部分)。然后只需一行代码即可绘制角度。

pgfplots 中的角度

\documentclass[12pt]{article}



\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{tikz, tkz-euclide,tikz-3dplot,ifthen}
\usetikzlibrary{intersections,angles}
\usepgfplotslibrary{fillbetween}

\begin{document}


\begin{tikzpicture}[scale=0.8]
\begin{axis}[
    xmin=-3, xmax=3,
    ymin=-3, ymax=3,
    samples=100,
    ticks=none,
    axis lines=middle,
       xlabel={$x$},
      ylabel={$y$},
   ]





\addplot[name path=p1,domain=-2:0]{sqrt(1-(x+1)^2)};
\addplot[name path=p2,domain=-2:0]{-sqrt(1-(x+1)^2)};
\addplot[name path=p3,domain=-1:0]{sqrt(1-x^2)};
\addplot[name path=p4,domain=-1:0]{-sqrt(1-x^2)};
\addplot[name path=p5,domain=0:1]{sqrt(1-x^2)};
\addplot[name path=p6,domain=0:1]{-sqrt(1-x^2)};

\addplot [color=gray!50,   opacity=0.5]%
        fill between [of=p1 and p2, soft clip={domain=-0.5:0}];
\addplot [color=gray!50,  opacity=0.5]%
        fill between [of=p3 and p4, soft clip={domain=-1:-0.5}];

\draw[fill=black]({cos(deg(2*pi/3))},{sin(deg(2*pi/3))})circle(2pt)node[above left,  xshift=0.5cm]{$\theta=\frac{2\pi}{3}$};

\draw[fill=black]({cos(deg(4*pi/3))},{sin(deg(4*pi/3))})circle(2pt)node[below left,  xshift=0.5cm]{$\theta=\frac{4\pi}{3}$};

\draw[dotted,  thick](0,0)--(-1/2,{sqrt(1-(0.5)^2)}) coordinate (a);
\draw[dotted,  thick](0,0)--(-1/2,-{sqrt(1-(0.5)^2)}) coordinate (b);

\coordinate (O) at (0,0);
\path pic[draw=blue,angle radius=10pt] {angle= a--O--b};




\end{axis}

\end{tikzpicture}



\end{document}

相关内容