Tikz:Tikz 样式中角度标记的更多方式

Tikz:Tikz 样式中角度标记的更多方式

继续这个美丽的答案,是否可以有以下附加角度标记?((1)中心带有点的角度;(2)带有装饰的紫色角度,如果可能,可以自定义(段号、长度、距离、颜色等);(3)具有多个圆弧的角度。

在此处输入图片描述

答案1

这里有一个建议。正如 Kpym 在评论中友好地解释的那样,角度构造有两种路径:圆弧和填充。必须防止 TiZ 绘制装饰两次。此答案带有一个 style insert angle lines,它接受两个参数,即线条数和它们应连接到的顶点。一个例子是

\pic [draw=red,angle radius=1cm,insert angle lines={3}{A}] 
    {angle = C--A--B};

点有第二种样式

\pic [draw=blue,angle radius=1cm,insert angle dot={B}] {angle = A--B--C};

如果您想改变这些标记的样式,请调整every angle mark。这是 MWE。

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.markings,angles}
\newcounter{trstep}
\begin{document}
\tikzset{insert |/.style={decoration={markings,
  mark=at position #1 with {%
   \draw[line cap=round,mark segment] 
    (0,-\pgfkeysvalueof{/tikz/mark
    segment length}/2) -- (0,\pgfkeysvalueof{/tikz/mark
    segment length}/2);}
  }},
  | mark/.style={postaction=decorate,insert |=#1},
  insert ||/.style={decoration={markings,
  mark=at position #1 with {%
   \draw[line cap=round,mark segment] 
    (-\pgfkeysvalueof{/tikz/mark segment distance}/2,-\pgfkeysvalueof{/tikz/mark
    segment length}/2) -- (-\pgfkeysvalueof{/tikz/mark segment distance}/2,\pgfkeysvalueof{/tikz/mark
    segment length}/2);
   \draw[line cap=round,mark segment] (\pgfkeysvalueof{/tikz/mark segment distance}/2,-\pgfkeysvalueof{/tikz/mark
    segment length}/2) -- (\pgfkeysvalueof{/tikz/mark segment distance}/2,\pgfkeysvalueof{/tikz/mark
    segment length}/2);}
  }},
  || mark/.style={postaction=decorate,insert ||=#1},
 insert |||/.style={decoration={markings,
  mark=at position #1 with {%
   \draw[line cap=round,mark segment] 
    (-\pgfkeysvalueof{/tikz/mark segment distance},-\pgfkeysvalueof{/tikz/mark
    segment length}/2) -- (-\pgfkeysvalueof{/tikz/mark segment distance},\pgfkeysvalueof{/tikz/mark
    segment length}/2);
   \draw[line cap=round,mark segment] 
    (0,-\pgfkeysvalueof{/tikz/mark
    segment length}/2) -- (0,\pgfkeysvalueof{/tikz/mark
    segment length}/2); 
   \draw[line cap=round,mark segment] 
   (\pgfkeysvalueof{/tikz/mark segment distance},-\pgfkeysvalueof{/tikz/mark
    segment length}/2) -- (\pgfkeysvalueof{/tikz/mark segment distance},\pgfkeysvalueof{/tikz/mark
    segment length}/2);}
  }},
  ||| mark/.style={postaction=decorate,insert |||=#1},
 mark segment/.style={thick},
 mark segment options/.code=\tikzset{mark segment/.style={#1}},
 mark segment distance/.initial=2pt,
 mark segment length/.initial=4pt,
 angle deco |/.style={insert |=0.5,
      pic actions/.append code=\tikzset{postaction=decorate}},
 angle deco ||/.style={insert ||=0.5,
      pic actions/.append code=\tikzset{postaction=decorate}},
 angle deco |||/.style={insert |||=0.5,
      pic actions/.append code=\tikzset{postaction=decorate}},
 insert angle lines/.style n args={2}{
 /utils/exec={\pgfmathsetmacro{\mystep}{1/(#1+1)}
 \setcounter{trstep}{0}},
 decoration={markings,mark=between positions {\mystep} and {1-\mystep} step {\mystep}
 with {\stepcounter{trstep}
 \ifnum\number\value{trstep}>#1
 \else
  \draw[shorten <=-1pt,every angle mark] (0,0)-- (#2);
  \fi}},
 pic actions/.append code=\tikzset{postaction={decorate}}
 },
 every angle mark/.style={line cap=round,semithick},
 double arc/.style={double,double distance=2pt},
 triple arc/.style={double distance=4pt,
    pic actions/.append code=\tikzset{postaction={draw}}},
 insert angle dot/.style={
 /utils/exec={\setcounter{trstep}{0}},
 decoration={markings,mark=at position 0.5  with {\stepcounter{trstep}
 \ifnum\number\value{trstep}=1
  \fill[\pgfkeysvalueof{/tikz/angle dot color}] (#1) -- (0,0)  coordinate[pos=\pgfkeysvalueof{/tikz/angle dot pos}] (aux) (aux) 
  circle[radius=\pgfkeysvalueof{/tikz/angle dot radius}];
  \fi}},
 pic actions/.append code=\tikzset{postaction={decorate}}},
 angle dot radius/.initial=1pt,
 angle dot pos/.initial=0.6,
 angle dot color/.initial=black}

\begin{tikzpicture}[]
    \coordinate (A) at (0,0);
    \coordinate (B) at (2,4);
    \coordinate (C) at (4,0);

    \draw(A)--(B)--(C)--cycle;
    \path[| mark=0.5] (A) -- (B);
    \path[mark segment options={thick,yscale=2},|| mark=0.5] (B) -- (C);
    \path[mark segment options={blue,line width=1pt,scale=2},||| mark=0.5] (C) -- (A);
    \pic [draw=blue,angle radius=1cm,insert angle dot={B}] 
    {angle = A--B--C};
    \pic [draw=red,angle radius=1cm,insert angle lines={3}{A}] 
    {angle = C--A--B};
    \pic [draw=purple,angle radius=1cm,triple arc,
    insert angle lines={3}{C}] 
    {angle = B--C--A};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容