如何用 tikz 绘制角度

如何用 tikz 绘制角度

我必须画一个像这张图片一样的角度。我想知道如何在角度内添加颜色,就像第二张图片一样 在此处输入图片描述

在此处输入图片描述

我的代码是:

\noindent\begin{tikzpicture}[> = stealth]
\draw[gray,step=1cm] (0,0) grid +(9cm,6cm);
    \draw[ultra thick,red, ->]  (1,4) -- node[above] {\Large $\vec{c}$} +(2,1);
    \draw[ultra thick,blue,->]  (1,4) -- node[below left] {\Large $\vec{d}$} +(4,0);

    \draw[ultra thick,black,|-|] (3,1) -- node[below] {\Large $u$} +(1,0);
\end{tikzpicture}

答案1

您可以使用库angle pic定义的angles以及quotes语法。

在此处输入图片描述

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{angles,quotes}
\begin{document}
\begin{tikzpicture}[> = stealth]
\coordinate (a) at (1,4);
\coordinate (b) at (3,5);
\coordinate (c) at (5,4);

\draw[gray,step=1cm] (0,0) grid +(9cm,6cm);
\draw pic[draw,fill=green!30,angle radius=1cm,"$\alpha$" shift={(6mm,1mm)}] {angle=c--a--b};
\draw pic[draw,fill=blue!30,angle radius=0.7cm,"$\epsilon$" shift={(-3mm,5mm)}] {angle=b--a--c};

\draw[ultra thick,red, ->]  (a) -- node[above] {\Large $\vec{c}$} (b);
\draw[ultra thick,blue,->]  (a) -- node[below left] {\Large $\vec{d}$} (c);
\end{tikzpicture}
\end{document}

这是没有上述库的版本。我真的不记得这在 PGF 2.10 中是否能正常工作,但你可以试试。不过我建议升级。

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[> = stealth]
\coordinate (a) at (1,4);
\coordinate (b) at (3,5);
\coordinate (c) at (5,4);

\draw[gray,step=1cm] (0,0) grid +(9cm,6cm);

\draw [fill=green!30] (a) -- ++(1cm,0) arc(0:{atan(1/2)}:1cm) node[midway,right] {$\alpha$} -- cycle;
\draw [fill=blue!30] (a) -- ++(0.6cm,0) arc(0:{-360+atan(1/2)}:0.6cm) node[pos=0.6,left]{$\epsilon$} -- cycle;

\draw[ultra thick,red, ->]  (a) -- node[above] {\Large $\vec{c}$} (b);
\draw[ultra thick,blue,->]  (a) -- node[below left] {\Large $\vec{d}$} (c);
\end{tikzpicture}
\end{document}

相关内容