Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to fill the angular sector and just draw the curve part of it in one command. I tried with move to command but it doesn't work.

enter image description here

\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}
share|improve this question
1  
Do you know new (TiKZ 3.0) angles library? It doesn't mark angles with short lines like your code but draw, fill and label angles. –  Ignasi Mar 31 at 10:05
    
Actualy I did not. Thank you. –  Tarass Mar 31 at 10:48

1 Answer 1

up vote 4 down vote accepted

andle

\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}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.