我如何画一个小红方块来标记我的直角三角形?

我如何画一个小红方块来标记我的直角三角形?

示例代码:

\documentclass{minimal}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw  ( 0 , 0 ) coordinate (A) 
    -- ( 4 , 0 ) coordinate (C) 
    -- ( 0 , 3 ) coordinate (B) 
    -- (0,    0);
\end{tikzpicture}
\end{document}

图示:

直角三角形

我想使用三角形左下角的方框来表示直角。

答案1

借助anglesTikZ 3.0.0 的新库和一个小补丁,可以获得:

在此处输入图片描述

谢谢:

\begin{tikzpicture}
\draw  ( 0 , 0 ) coordinate (A) 
    -- ( 4 , 0 ) coordinate (C) 
    -- ( 0 , 3 ) coordinate (B) 
    -- ( 0 , 0 )
    pic [draw,blue,thick,angle radius=0.5cm]  {squared angle = A--C--B}
    pic [draw,red,thick,angle radius=0.5cm]   {squared angle = C--A--B}
    pic [draw,green,thick,angle radius=0.5cm] {squared angle = C--B--A};
    ;
\end{tikzpicture}

完整代码:

\documentclass[tikz,border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{angles}

\makeatletter
\tikzset{
  pics/squared angle/.style = {
    setup code  = \tikz@lib@angle@parse#1\pgf@stop,
    background code = \tikz@lib@angle@background#1\pgf@stop,
    foreground code = \tikz@lib@squaredangle@foreground#1\pgf@stop,  
  },
  pics/squared angle/.default=A--B--C,
  angle eccentricity/.initial=.6,
  angle radius/.initial=5mm
}

\def\tikz@lib@squaredangle@foreground#1--#2--#3\pgf@stop{%
  \path [name prefix ..] [pic actions]
  ([shift={(\tikz@start@angle@temp:\tikz@lib@angle@rad pt)}]#2.center)
    |-
  ([shift={(\tikz@end@angle@temp:\tikz@lib@angle@rad pt)}]#2.center);
  \ifx\tikzpictext\relax\else%
    \def\pgf@temp{\node()[name prefix
      ..,at={([shift={({.5*\tikz@start@angle@temp+.5*\tikz@end@angle@temp}:\pgfkeysvalueof{/tikz/angle
            eccentricity}*\tikz@lib@angle@rad pt)}]#2.center)}]}
    \expandafter\pgf@temp\expandafter[\tikzpictextoptions]{\tikzpictext};%
  \fi
}
\makeatother

\begin{document}
\begin{tikzpicture}
\draw  ( 0 , 0 ) coordinate (A) 
    -- ( 4 , 0 ) coordinate (C) 
    -- ( 0 , 3 ) coordinate (B) 
    -- ( 0 , 0 )
    pic [draw,blue,thick,angle radius=0.5cm]  {squared angle = A--C--B}
    pic [draw,red,thick,angle radius=0.5cm]   {squared angle = C--A--B}
    pic [draw,green,thick,angle radius=0.5cm] {squared angle = C--B--A};
    ;
\end{tikzpicture}
\end{document}

所需的输出似乎是用红色填充的框以及标签,因此让我们使用该quotes库:

\documentclass[tikz,border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{angles,quotes}

\makeatletter
\tikzset{
  pics/squared angle/.style = {
    setup code  = \tikz@lib@angle@parse#1\pgf@stop,
    background code = \tikz@lib@angle@background#1\pgf@stop,
    foreground code = \tikz@lib@squaredangle@foreground#1\pgf@stop,  
  },
  pics/squared angle/.default=A--B--C,
  angle eccentricity/.initial=.6,
  angle radius/.initial=5mm
}

\def\tikz@lib@squaredangle@foreground#1--#2--#3\pgf@stop{%
  \path [name prefix ..] [pic actions]
  ([shift={(\tikz@start@angle@temp:\tikz@lib@angle@rad pt)}]#2.center)
    |-
  ([shift={(\tikz@end@angle@temp:\tikz@lib@angle@rad pt)}]#2.center);
  \ifx\tikzpictext\relax\else%
    \def\pgf@temp{\node()[name prefix
      ..,at={([shift={({.5*\tikz@start@angle@temp+.5*\tikz@end@angle@temp}:\pgfkeysvalueof{/tikz/angle
            eccentricity}*\tikz@lib@angle@rad pt)}]#2.center)}]}
    \expandafter\pgf@temp\expandafter[\tikzpictextoptions]{\tikzpictext};%
  \fi
}
\makeatother

\begin{document}
\begin{tikzpicture}
\draw  ( 0 , 0 ) coordinate (A) 
    -- ( 4 , 0 ) coordinate (C) 
    -- ( 0 , 3 ) coordinate (B) 
    -- ( 0 , 0 )
    pic [draw,fill=red,angle radius=0.5cm,angle eccentricity=2,
    "$90^\circ$" {black,font=\footnotesize}]   {squared angle = C--A--B}
    ;
\end{tikzpicture}
\end{document}

结果:

在此处输入图片描述

答案2

对于这个简单的情况,您只需在处画一个正方形即可(A)

\documentclass[tikz,border=10pt]{standalone}
\begin{document}
\begin{tikzpicture}
\draw  ( 0 , 0 ) coordinate (A)
    -- ( 4 , 0 ) coordinate (C)
    -- ( 0 , 3 ) coordinate (B)
    -- (0,  0);
\draw [fill=red](A) rectangle ++(0.5,0.5) node[above right]{$90^\circ$};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案3

这是一个简化的方法 »tkz-euclide«,这在您的问题评论中间接提到。定义三角形的点位于何处,都会自动标记直角。

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{tkz-euclide}
\usetkzobj{all}

\begin{document}
  \begin{tikzpicture}
    \tkzDefPoint(0,0){A}
    \tkzDefPoint(0,3){B}
    \tkzDefPoint(4,0){C}
    \tkzMarkRightAngle[draw=red,fill=red](B,A,C)
    \tkzDrawPolygon(A,B,C)
  \end{tikzpicture}
\end{document}

有关详细信息,请参阅包装手册,不幸的是,该手册仅提供法语版本。


在此处输入图片描述

答案4

方法如下。以 (A) 为参考点。然后 (1)yshift将起点稍微向上移动;(2)xshift确定终点;(3) 使用 -| 连接这两个点(先水平移动,然后垂直移动到终点)。 在此处输入图片描述

\documentclass{minimal}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw  ( 0 , 0 ) coordinate (A) 
    -- ( 4 , 0 ) coordinate (C) 
    -- ( 0 , 3 ) coordinate (B) 
    -- (0,  0);
%\draw [red]([yshift=0.5cm]A) -| node[above right]{$90^\circ$}; % generates red line
\draw [fill=red]([yshift=0.5cm]A) -| node[above right]{$90^\circ$} ([xshift=0.5cm]A) 
-- (A) -- cycle ;   % if path is used, the square becomes invisible.
\end{tikzpicture}
\end{document}

相关内容