角符号怎么填充?

角符号怎么填充?

在线程中在两条垂直线的交点处插入垂直符号,杰克提出了一个非常有用的命令来标记直角。我试图给符号上色,但只涂了一半的颜色。

  \documentclass{standalone}
  \usepackage{pgfplots}
  \usetikzlibrary{calc}
  \pgfplotsset{compat=1.13}
    \tikzset{
     right angle quadrant/.code={
     \pgfmathsetmacro\quadranta{{1,1,-1,-1}[#1-1]}   
     \pgfmathsetmacro\quadrantb{{1,-1,-1,1}[#1-1]}},
      right angle quadrant=1, 
      right angle length/.code={\def\rightanglelength{#1}},   
      right angle length=2ex,
      right angle symbol/.style n args={3}{
      insert path={
        let \p0 = ($(#1)!(#3)!(#2)$) in    
            let \p1 = ($(\p0)!\quadranta*\rightanglelength!(#3)$), 
            \p2 = ($(\p0)!\quadrantb*\rightanglelength!(#2)$) in 
            let \p3 = ($(\p1)+(\p2)-(\p0)$) in 
        (\p1) -- (\p3) -- (\p2)
     }
     }
     }

  \begin{document}

  \begin{tikzpicture}[extended line/.style={shorten >=-#1,shorten <=-#1}]

  \begin{axis}[
    restrict x to domain=-4:5, xmax=5, xmin=-4,
    restrict y to domain=-2:4, ymax=4, ymin=-2,
    x=0.7cm,
    y=0.7cm,
    axis x line=middle,
    axis y line=middle,
    major tick style=black,
    axis line style = thick,
    tickwidth=0.1cm,
    grid=both,
    xtick={-3,...,4},
    ytick={-1,...,3},
    yticklabels={,,},
    xticklabels={,,},
    extra x ticks={-4,5}, 
    extra x tick label={\null}, 
    extra y ticks={-2,4}, 
    extra y tick label={\null},
    extra tick style={tick style={draw=none}},
    xlabel=$x$,ylabel=$y$,
    every axis x label/.style={
    at={(ticklabel* cs:1.01)},
   anchor=west,
   },
   every axis y label/.style={
   at={(ticklabel* cs:1.01)},
   anchor=south,
   },
  samples=1000,
  >=stealth,
  ]


 \coordinate [label=above right : $A$] (A) at (-2,3);
 \coordinate [label=below left : $B$](B) at (-3,1);
 \coordinate [label=above right : $C$](C) at (4,0);
 \coordinate [label=below right : $H$] (H) at ($(B)!(A)!(C)$);

 \draw [thick] (A)--(B)--(C)--cycle;
 \draw [thick,extended line=3cm] (A)--(H);
 \draw [fill=red,right angle quadrant=1,right angle symbol={B}{C}{A}];

 \node[below=2pt] at (1,0) {$1$};
 \node[left=2pt] at (0,1) {$1$};
 \node[below left=2pt] at (0,0) {$0$};

 \node[thick] at (A) {+};
 \node[thick] at (B) {+};
 \node[thick] at (C) {+};

 \end{axis}
 \end{tikzpicture}
 \end{document}

在此处输入图片描述

答案1

替换(\p1) -- (\p3) -- (\p2)(\p1) -- (\p3) -- (\p2) --(\p0)将填充符号。原始宏位于在两条垂直线的交点处插入垂直符号被设计用来绘制垂直符号,假设其他线已经到位;因此,它没有完成一个完整的循环。

笔记:

  • 在下面的版本中,我使用了来自您获取代码的后续问题的宏:使用 TikZ/Calc 进行直角符号对齐。但是,对于这种特定情况,两个版本right angle quadrant=似乎都可以正常工作:
  • 另外,我建议填写符号画出其他线条,如下图所示。

在此处输入图片描述

代码:

\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{calc}
\pgfplotsset{compat=1.13}

%% https://tex.stackexchange.com/questions/114680/right-angle-symbol-alignment-with-tikz-calc
\tikzset{
    right angle quadrant/.code={
        \pgfmathsetmacro\quadranta{{1,1,-1,-1}[#1-1]}     % Arrays for selecting quadrant
        \pgfmathsetmacro\quadrantb{{1,-1,-1,1}[#1-1]}},
    right angle quadrant=1, % Make sure it is set, even if not called explicitly
    right angle length/.code={\def\rightanglelength{#1}},   % Length of symbol
    right angle length=2ex, % Make sure it is set...
    right angle symbol/.style n args={3}{
        insert path={
            let \p0 = ($(#1)!(#3)!(#2)$),     % Intersection
                \p1 = ($(\p0)!\quadranta*\rightanglelength!(#3)$), % Point on base line
                \p2 = ($(\p0)!\quadrantb*\rightanglelength!(#2)$), % Point on perpendicular line
                \p3 = ($(\p1)+(\p2)-(\p0)$) in  % Corner point of symbol
            (\p1) -- (\p3) -- (\p2) --(\p0)%% <-- Added '--(\p0)'
        }
    }
}

\begin{document}

\begin{tikzpicture}[extended line/.style={shorten >=-#1,shorten <=-#1}]

\begin{axis}[
    restrict x to domain=-4:5, xmax=5, xmin=-4,
    restrict y to domain=-2:4, ymax=4, ymin=-2,
    x=0.7cm,
    y=0.7cm,
    axis x line=middle,
    axis y line=middle,
    major tick style=black,
    axis line style = thick,
    tickwidth=0.1cm,
    grid=both,
    xtick={-3,...,4},
    ytick={-1,...,3},
    yticklabels={,,},
    xticklabels={,,},
    extra x ticks={-4,5}, 
    extra x tick label={\null}, 
    extra y ticks={-2,4}, 
    extra y tick label={\null},
    extra tick style={tick style={draw=none}},
    xlabel=$x$,ylabel=$y$,
    every axis x label/.style={
    at={(ticklabel* cs:1.01)},anchor=west},
    every axis y label/.style={
    at={(ticklabel* cs:1.01)}, anchor=south},
    samples=1000,
    >=stealth,
]


 \coordinate [label=above right : $A$] (A) at (-2,3);
 \coordinate [label=below left : $B$](B) at (-3,1);
 \coordinate [label=above right : $C$](C) at (4,0);
 \coordinate [label=below right : $H$] (H) at ($(B)!(A)!(C)$);

 \draw [fill=red, right angle quadrant=1,right angle symbol={B}{C}{A}];
 \draw [thick] (A)--(B)--(C)--cycle;
 \draw [thick,extended line=3cm] (A)--(H);

 \node[below=2pt] at (1,0) {$1$};
 \node[left=2pt] at (0,1) {$1$};
 \node[below left=2pt] at (0,0) {$0$};

 \node[thick] at (A) {+};
 \node[thick] at (B) {+};
 \node[thick] at (C) {+};

 \end{axis}
 \end{tikzpicture}
 \end{document}

相关内容