我想填充角扇区,并在一个命令中绘制其曲线部分。我尝试使用移动到命令,但它不起作用。
\documentclass[tikz,10pt]{standalone}
\usetikzlibrary{calc}
\pgfkeys{/tikz/.cd,
MarkAngleDim/.store in=\MarkAngleDim,
MarkAngleDim=0.5,
MarkDim/.store in=\MarkDim,
MarkDim=2,
}
\newcommand{\MarkAngle}[3][]{%
\foreach \Bn/\An/\Cn in {#2} {%
\pgfmathanglebetweenpoints%
{\pgfpointanchor{\An}{center}}%
{\pgfpointanchor{\Bn}{center}}%
\global\let\AnglA\pgfmathresult ;
\pgfmathanglebetweenpoints%
{\pgfpointanchor{\An}{center}}%
{\pgfpointanchor{\Cn}{center}}%
\global\let\AnglB\pgfmathresult ;
\pgfmathparse{ifthenelse(\AnglA>\AnglB,\AnglA-360,\AnglA)} \global\let\AnglA\pgfmathresult ;
%################# the faulty path #####################
\path[very thin,#1] (\An) to[move to]
($(\An) !\MarkAngleDim cm!(\Bn)$)
arc (\AnglA:\AnglB:\MarkAngleDim)
node[pos=.5] (Angle\Bn\An\Cn) {}
to[move to] (\An) --cycle;
%#######################################################
\ifnum#3>0
\pgfmathanglebetweenpoints%
{\pgfpointanchor{\An}{center}}%
{\pgfpointanchor{Angle\Bn\An\Cn}{center}}%
\global\let\AnglC\pgfmathresult ;
\begin{scope}[shift={(\An)}]
\foreach \i [evaluate=\i as \ang
using \AnglC+2*(\i-#3/2-.5)/\MarkAngleDim]
in {1,...,#3} {%
\draw[very thin] (\ang:\MarkAngleDim cm +\MarkDim pt)
--(\ang:\MarkAngleDim cm -\MarkDim pt) ;
}
\end{scope}
\fi
}
}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (0,0) ;
\coordinate (B) at (1,1) ;
\coordinate (C) at (0,-1) ;
\MarkAngle[draw,blue,fill=red!25]{C/A/B}{2} ;
\draw[dashed] (B)--(A)--(C) ;
\node[label=135:A] at (A) {} ;
\node[label=B] at (B) {} ;
\node[label=270:C] at (C) {} ;
\end{tikzpicture}
\end{document}
答案1
\documentclass[tikz,10pt]{standalone}
\usetikzlibrary{calc}
\pgfkeys{/tikz/.cd,
MarkAngleDim/.store in=\MarkAngleDim,
MarkAngleDim=0.5,
MarkDim/.store in=\MarkDim,
MarkDim=2,
}
\newcommand{\MarkAngle}[3][]{%
\foreach \Bn/\An/\Cn in {#2} {%
\pgfmathanglebetweenpoints%
{\pgfpointanchor{\An}{center}}%
{\pgfpointanchor{\Bn}{center}}%
\global\let\AnglA\pgfmathresult ;
\pgfmathanglebetweenpoints%
{\pgfpointanchor{\An}{center}}%
{\pgfpointanchor{\Cn}{center}}%
\global\let\AnglB\pgfmathresult ;
\pgfmathparse{ifthenelse(\AnglA>\AnglB,\AnglA-360,\AnglA)} \global\let\AnglA\pgfmathresult ;
%################# the faulty path #####################
\path[draw opacity=0,#1] ($(\An) !\MarkAngleDim cm!(\Bn)$) -- (\An) --
($(\An) !\MarkAngleDim cm!(\Cn)$);
\path[very thin,#1] ($(\An) !\MarkAngleDim cm!(\Bn)$)
arc (\AnglA:\AnglB:\MarkAngleDim)
node[pos=.5] (Angle\Bn\An\Cn) {};
%#######################################################
\ifnum#3>0
\pgfmathanglebetweenpoints%
{\pgfpointanchor{\An}{center}}%
{\pgfpointanchor{Angle\Bn\An\Cn}{center}}%
\global\let\AnglC\pgfmathresult ;
\begin{scope}[shift={(\An)}]
\foreach \i [evaluate=\i as \ang
using \AnglC+2*(\i-#3/2-.5)/\MarkAngleDim]
in {1,...,#3} {%
\draw[very thin] (\ang:\MarkAngleDim cm +\MarkDim pt)
--(\ang:\MarkAngleDim cm -\MarkDim pt) ;
}
\end{scope}
\fi
}
}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (0,0) ;
\coordinate (B) at (1,1) ;
\coordinate (C) at (0,-1) ;
\MarkAngle[draw,blue,fill=red!25]{C/A/B}{2} ;
\draw[dashed] (B)--(A)--(C) ;
\node[label=135:A] at (A) {} ;
\node[label=B] at (B) {} ;
\node[label=270:C] at (C) {} ;
\end{tikzpicture}
\end{document}