TikZ 的角度“形状”错误

TikZ 的角度“形状”错误

我在使用 TikZ 绘制角度时遇到了麻烦。这很奇怪,因为我以前做过这个,我甚至复制了我使用的代码,但角度线的形状却很古怪。

\documentclass{article}
\usepackage{tikz}
\usepackage{tkz-euclide}
\usepackage{pgf}
\usepackage{pgfplots}
\usetikzlibrary{calc,patterns,angles,quotes}

\begin{document}

\begin{figure}[!h]
\centering
\begin{tikzpicture}[scale=1.3, > = Straight Barb, trig format = rad]
    \tkzDefPoint(0,0){o}
    \tkzDefPoint(1,0){x}
    \tkzDefPoint(0.7071,0.7071){a}
    \draw[thick, black, ->] (-1.5, 0) -- (1.5, 0) node[right] {$x$};
    \draw[thick, black, ->] (0, -1.5) -- (0, 1.5) node[above] {$y$};
    \draw[thick, blue] plot [domain=0:4.7124, smooth, variable = \x, samples = 200] ({cos(\x)},{sin(\x)});
     \fill [yellow, opacity = 0.1, domain=0:4.7124, smooth, variable=\x, samples = 200]
      (0,0)
      -- plot ({cos(\x)}, {sin(\x)})
      -- (0, -1)
      -- cycle;
    \path[black, thick] (1,0) node[below] {$4$};
    \path[black, thick] (0,1) node[anchor = south west] {$4$};
    \draw[thick, red](0, 0) -- (0.7071, 0.7071) node[sloped, pos = 0.5, allow upside down]{\arrowIn};
    \draw[thick, red, dotted] (0.7071, 0.7071) -- (1,1);
    \draw pic[draw, black, "$\theta$", angle eccentricity=1.2, angle radius=20] {angle=x--o--a};
\end{tikzpicture}
\end{figure}

\end{document}

代码给了我这个 在此处输入图片描述

无论我如何改变偏心率和半径,它都不会改变。我也尝试过将“x--o--a”改为“a--o--x”。我也想把它做成箭头。我看到了这个话题并尝试了他们的代码,但还是乱了套。我该怎么办?

编辑:我应该提一下,改变偏心率似乎会改变 theta 的位置。我还想出了把它做成箭头(说实话这很明显,抱歉。)

答案1

angles不适用于trig format=rad。您可以将其改回 ,deg如下\draw所示:

\draw pic[draw, black, "$\theta$", angle eccentricity=1.2, angle radius=20, trig format=deg] {angle=x--o--a};

您实际上不需要rad此图形的格式,并且我建议不要用图绘制圆和弧。 - 它会生成许多小的线/曲线段,从而花费更多的编译时间并产生更差的输出。

-参见@Sigur 的回答

答案2

这个代码比较简单,使用arc和极坐标(angle:radius)

在此处输入图片描述

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,patterns,angles,quotes,arrows.meta}

\begin{document}
\begin{tikzpicture}[scale=1.3, > = Straight Barb] 
  \coordinate (o) at (0,0);
  \coordinate (x) at (1,0);
  \coordinate (a) at (0.7071,0.7071);
  \draw[thick, black, ->] (-1.5, 0) -- (1.5, 0) node[right] {$x$};
  \draw[thick, black, ->] (0, -1.5) -- (0, 1.5) node[above] {$y$};
  \draw[fill=green, fill opacity = 0.1] (1,0) arc[start angle=0, end angle=270, radius=1cm] -- (0,0) -- cycle;
  \draw[thick, blue] (1,0) arc[start angle=0, end angle=270, radius=1cm];
  \path[black, thick] (1,0) node[below] {$4$};
  \path[black, thick] (0,1) node[anchor = south west] {$4$};
  \draw[thick, red, ->](0, 0) -- (45:1cm);
  \draw[thick, red, dotted] (45:1cm) -- (1,1);
  \draw pic[draw, black, "$\theta$", angle eccentricity=1.25, angle radius=.6cm] {angle=x--o--a};    
  \end{tikzpicture}
\end{document}

答案3

原因是存在一些冲突(正如@hpekristiansen 在他的回答中指出的那样:该库angles不适用于选项trig format=rad)。如果pgftkz-euclide不是真正需要的,那么就不要加载它们。

我认为,我们应该编写尽可能简单的代码!

在此处输入图片描述

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{angles,quotes}
\begin{document}
\begin{figure}[!h]
\centering
\begin{tikzpicture}[scale=2,thick]
\path 
(0,0) coordinate (o)
(1,0) coordinate (x) node[below right] {$4$}
(0,1) node[above left] {$4$}
(1,1) coordinate (a);
\fill[yellow,opacity=.2] (0,0)--(1,0) arc(0:270:1)--cycle;
\path pic[draw,-stealth,"$\theta$", angle eccentricity=1.3, angle radius=20] {angle=x--o--a};
\draw[red,dotted] (0,0)--(1,1);
\draw[->] (-1.25, 0) -- (1.5, 0) node[above left] {$x$};
\draw[->] (0, -1.25) -- (0, 1.5) node[below right] {$y$};
\draw[blue] (0,0) circle(1);
\end{tikzpicture}
\end{figure}
\end{document}

答案4

原帖用途tkz-euclide,我建议用这个包和来解决tkz-elements

% !TeX TS-program = lualatex
\documentclass{standalone}
% https://tex.stackexchange.com/questions/655544/error-with-angle-shape-with-tikz/655547#655547
\usepackage{tkz-elements}
\usepackage{tkz-euclide}
\begin{document}
\begin{tkzelements}
  z.O = point: new (0, 0)
  z.A = point: new (0, 4)
  z.B = point: new (0, -4)
  z.C = point: new (4, 0)
  z.F = point: polar (4, math.pi/4)
  z.Fp = point: polar (4.8, math.pi/4)
\end{tkzelements}

\begin{tikzpicture}
  \tkzSetUpStyle[postaction=decorate,
    decoration={
        markings,
        mark=at position .5 with {\arrow[thick]{#1}}
      }]{myarrow}
  \tkzGetNodes
  % with tkz-base
  \tkzInit[xmin=-4.5,xmax=4.5,ymin=-4.5,ymax=4.5,]
  \tkzDrawX[thick,right=0.5em]
  \tkzDrawY[thick,above=0.5em]
  \tkzLabelPoint[below](C){$4$}
  \tkzLabelPoint[above right](A){$4$}
  % with tkz-euclide
  \tkzDrawArc[thick,color=blue](O,C)(B)
  \tkzDrawSector[fill=yellow, opacity = 0.1](O,C)(B)
  % 
  \tkzDrawSegments[thick,myarrow={Straight Barb},red](O,F)
  \tkzDrawSegments[thick,red,dotted](F,F')%<-- Fp in tkzelements, F' in tikzpicture
  %
  \tkzPicAngle[
    "$\theta$",
    draw=black,
    ->,>={Straight Barb},
    angle eccentricity=1.3,
    angle radius=1cm
  ](C,O,F)
  % \tkzDrawPoints(A,B,C,F,F')%
  % \tkzLabelPoints(A,B,C,F,F')%
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容