有人能帮我在 Tikz 中标记直角吗?

有人能帮我在 Tikz 中标记直角吗?

我已经在这里玩数字\draw好久了。一定有更好的方法。我想添加这个直角符号: 在此处输入图片描述 但我不知道该怎么做才能做得漂亮。有人能帮我吗?谢谢。MWE:

\documentclass{article}
\usepackage{tikz}
\begin{document}
    \begin{tikzpicture}[domain=0:4]
    \draw (0.1,-0.2) node[left]{\textcolor{gray}{O}};
    \draw[thick, color=gray,->] (-4,0) -- (8,0) node[right] {\textcolor{black}{$x$}};
    \draw[thick, color=gray, ->] (0,-1) -- (0,5) node[above] {\textcolor{black}{$y$}};  
    \draw (3+2,5)--(-4+2,-1) node[above]{$l_1$};
    \draw (-0.5,5)--(36/7-0.5,-1) node[above]{$l_2$};
    \draw [color=gray, dashed] (1.9, 2.28) node[circle,fill=black,inner sep=0pt,minimum size=3pt, label=left:{\textcolor{black}{$P~~$}}]{}--(4.5,2.28)node[circle,fill=black,inner sep=0pt,minimum size=3pt, label=below right:{\textcolor{black}{$Q$}}]{}--(4.5,4.6) node[circle,fill=black,inner sep=0pt,minimum size=3pt, label= right: {\textcolor{black}{$~R$}}]{};
    \draw (4.5,2.58)--(4.2,2.58)--(4.2,2.28);
    \draw [color=gray, dashed] (1.9, 2.28) --(1.9,-0.3)node[circle,fill=black,inner sep=0pt,minimum size=3pt, label= below left:{\textcolor{black}{$S$}}]{}--(4,-0.3) node[circle,fill=black,inner sep=0pt,minimum size=3pt, label= below:{\textcolor{black}{$T~~~$}}]{};
    \draw (1.9,0)--(2.2,0)--(2.2,-0.3);
    \draw (2.9,2.28) arc (0:45:1cm);
    \node at (2.5,2.5) {$\theta$};
    \draw (3.4,2.28) arc (0:-51:1.5cm);
    \node[rotate=-25] at (2.7,1.9) {$\theta-90^{\circ}$};
    \draw (2.6,1.38) arc (-51:-93:1cm);
    \node at (2.1,1.5) {$\theta$};
    \end{tikzpicture}
\end{document}

答案1

使用最新的 PGF/TikZ,Angle 库支持直角

以下片段摘自官方手册(适用于 3.1.8b)在第571页:

\usetikzlibrary {angles}
  \tikz
    \draw (0,0,0)coordinate(O)
      (1,0,0)coordinate(A)-- (O)
      (0,0,1)coordinate(B)-- (O)
      (0,1,0)coordinate(C)-- (O)
      pic[fill=gray,angle radius=4mm] {right angle= A--O--B}
      pic[draw,red,thick,angle eccentricity=.5,pic text=.]{right angle= A--O--C};

答案2

这是一个(几乎)完全使用该tkz-euclide包的解决方案,几乎,排除前四个节点。那是因为我(目前)不知道如何在某些点放置自定义标签。

如有任何疑问,请在评论中提问!

输出

在此处输入图片描述

代码

\documentclass{article}
\usepackage{tikz, tkz-euclide}
\usetkzobj{all}

\usetikzlibrary{arrows.meta,intersections,calc}

\tikzset{
    mynode/.style={circle,fill=black,inner sep=0pt,minimum size=3pt},
}

\begin{document}
    \begin{tikzpicture}[domain=0:4]

    \node[anchor=north west] at (8,0) {$x$};
    \node[anchor=south east] at (0,5) {$y$};    
    \node[anchor=west] at (-2.5,-2) {$l_1$};
    \node[anchor=east] at (5,-2) {$l_2$};

    %%% Axis coordinates and axis lines (X axis, Y axis)
    \tkzDefPoints{-4/0/Z, 8/0/X, 0/-1/W, 0/5/Y} 
    \tkzDrawLines[add=0 and 0.1,arrows=->,>=latex](Z,X W,Y)

    %%% Our main lines
    \tkzDefPoints{5/5/A, -2/-1/B, -.5/5/C, 4.642857143/-1/D}

    %Getting points 
    \tkzInterLL(A,B)(C,D) \tkzGetPoint{P}
    \tkzDefPointBy[projection=onto B--D](P) \tkzGetPoint{S}

    \tkzDefLine[parallel=through S](Z,X) \tkzGetPoint{parax}
    \tkzInterLL(S,parax)(C,D) \tkzGetPoint{T}

    \tkzDefPointBy[rotation=center P angle 90](S) \tkzGetPoint{Q}
    \tkzDefLine[parallel=through Q](W,Y) \tkzGetPoint{paray} 
    \tkzInterLL(Q,paray)(A,B) \tkzGetPoint{R}

    % Draw lines and draw/place label points
    \tkzDrawLines(A,B C,D)
    \tkzDrawLines[dashed,color=gray,add=0 and 0](P,S S,T P,Q Q,R)   
    \tkzLabelPoints[left](P,S)
    \tkzLabelPoints[right](T,Q,R)   
    \tkzDrawPoints[color=black,fill=black](P,S,T,Q,R)

    %%% Angles  
    % Right angles
    \tkzFindAngle(C,P,A)
    \tkzGetAngle{angleCPA};
    \tkzMarkRightAngle[draw=black,size=.5](C,P,A)
    \tkzFindAngle(T,S,P)
    \tkzGetAngle{angleTSP};
    \tkzMarkRightAngle[draw=black](T,S,P)
    \tkzFindAngle(P,Q,R)
    \tkzGetAngle{anglePQR};
    \tkzMarkRightAngle[draw=black](P,Q,R)

    % other angles
    \tkzFindAngle(S,P,T) 
    \tkzGetAngle{angleSPT};
    %\tkzMarkAngle[draw=black](S,P,T) % This one cannot be used here because dashed lines. See \tkzDrawArc below
    \tkzDrawArc[R with nodes, color=blue](P,1cm)(S,T)
    \tkzLabelAngle[dist=.6](S,P,T){$\theta$}

    \tkzFindAngle(Q,P,R)
    \tkzGetAngle{angleQPR};
    \tkzDrawArc[R with nodes, color=blue](P,1cm)(Q,R)
    \tkzLabelAngle[dist=.6](Q,P,R){$\theta$}

    \tkzFindAngle(T,P,Q)
    \tkzGetAngle{angleTPQ};
    \tkzDrawArc[R with nodes, color=red](P,1.8cm)(T,Q)
    \tkzLabelAngle[dist=1.1,rotate=-25](T,P,Q){$\theta - 90^\circ$}

    \end{tikzpicture}
\end{document}

答案3

我无法让 tkz-euclide 工作,所以我编写了自己的 \MarkRightAngle 宏。我还更正了您的一些坐标:l_1 由 y=.857 x +.714 给出,l_2 由 y = -1.167 x +4.4167 给出。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}

\newcommand{\MarkRightAngle}[4][.3cm]% #1=size (optional), #2-#4 three points: \angle #2#3#4
{\coordinate (tempa) at ($(#3)!#1!(#2)$);
 \coordinate (tempb) at ($(#3)!#1!(#4)$);
 \coordinate (tempc) at ($(tempa)!0.5!(tempb)$);%midpoint
 \draw (tempa) -- ($(#3)!2!(tempc)$) -- (tempb);
}

\begin{document}
    \begin{tikzpicture}[domain=0:4]
    \coordinate (P) at (1.83,2.28);
    \coordinate (Q) at (4.5,2.28);
    \coordinate (R) at (4.5,4.57);
    \coordinate (S) at (1.83,-0.367);
    \coordinate (T) at (4.1,-0.367);
    \coordinate (U) at (0,4.417);
    \draw (0.1,-0.2) node[left]{\textcolor{gray}{O}};
    \draw[thick, color=gray,->] (-4,0) -- (8,0) node[right] {\textcolor{black}{$x$}};
    \draw[thick, color=gray, ->] (0,-1) -- (0,5) node[above] {\textcolor{black}{$y$}};  
    \draw (3+2,5)--(-4+2,-1) node[above]{$l_1$};
    \draw (-0.5,5)--(36/7-0.5,-1) node[above]{$l_2$};
    \draw [color=gray, dashed] (P) node[circle,fill=black,inner sep=0pt,minimum size=3pt, label=left:{\textcolor{black}{$P~~$}}]{}--(Q) node[circle,fill=black,inner sep=0pt,minimum size=3pt, label=below right:{\textcolor{black}{$Q$}}]{}--(R) node[circle,fill=black,inner sep=0pt,minimum size=3pt, label= right: {\textcolor{black}{$~R$}}]{};
    \draw [color=gray, dashed] (P) --(S)node[circle,fill=black,inner sep=0pt,minimum size=3pt, label= below left:{\textcolor{black}{$S$}}]{}--(T) node[circle,fill=black,inner sep=0pt,minimum size=3pt, label= below:{\textcolor{black}{$T~~~$}}]{};
    \draw (2.9,2.28) arc (0:45:1cm);
    \node at (2.5,2.5) {$\theta$};
    \draw (3.4,2.28) arc (0:-51:1.5cm);
    \node[rotate=-25] at (2.7,1.9) {$\theta-90^{\circ}$};
    \draw (2.6,1.38) arc (-51:-93:1cm);
    \node at (2.1,1.5) {$\theta$};
    \MarkRightAngle{P}{S}{T}
    \MarkRightAngle{P}{Q}{R}
    \MarkRightAngle{U}{P}{R}
    \end{tikzpicture}
\end{document}

直角

答案4

这是另一种方法

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
%% \usetikzlibrary{calc}
\usepackage{tkz-euclide}
\usetkzobj{all}

\tikzset{my node dot/.style={circle,fill=black,inner sep=0pt,minimum size=3pt}}

\begin{document}

  \begin{tikzpicture}[domain=0:4]

  %% origin and axes including axis names:
  \coordinate (O) at (0,0);
  \draw[thick, color=gray,->]  (-4,0) -- (8,0) node[right] {$x$};
  \draw[thick, color=gray, ->] (0,-1) -- (0,5) node[above] {$y$};  

  %% line with positive slope
  \coordinate (l1a) at (3+2,5);
  \coordinate (l1b) at (-4+2,-1);
  \path (l1a) -- (l1b) coordinate[pos=0.07] (R);

  %% line with negative slope
  \coordinate (l2a) at (-0.5,5);
  \coordinate (l2b) at (36/7-0.5,-1);
  \path (l2a) -- (l2b) coordinate[pos=0.88] (T);

  %%
  \tkzInterLL(l1a,l1b)(l2a,l2b)\tkzGetPoint{P}
  \coordinate (Q) at (P-|R);
  \coordinate (S) at (P|-T);

  %% labels for points
  \node[my node dot,label=below left:{$O$}]      at (O) {};
  \node[my node dot,label=right:{$R$}]           at (R) {};
  \node[my node dot,label=below left:{$T$}]      at (T) {};
  \node[my node dot,label=left:{$P$}]            at (P) {};
  \node[my node dot,label=below right:{$Q$}]     at (Q) {};
  \node[my node dot,label=below left:{$S$}]      at (S) {};

  %% labels for lines
  \draw (l1a) -- (l1b) node[pos=1,above] {$l_1$} ;
  \draw (l2a) -- (l2b) node[pos=1,above] {$l_2$};

  %% marking angles
  %% marking the right angles
  %%\tkzMarkRightAngle(P,Q,R) %% appears as a square
  \draw (Q) ++ (-6pt,0) -- ++ (0,6pt) -- ++ (6pt,0);
  \draw [color=gray, dashed] (P) -- (Q) -- (R) ;

  %%\tkzMarkRightAngle(P,S,T) %% appears as a square
  \draw (S) ++ (6pt,0) -- ++ (0,6pt) -- ++ (-6pt,0);
  \draw [color=gray,dashed] (P) -- (S) -- (T);

  \tkzMarkRightAngle(R,P,l2a)
  %% if you use the `calc` library then the following will also draw a right angle
  %% \draw[red] ($(P)!6pt!(R)$) --  ($($(P)!6pt!(R)$)!6pt!90:(R)$) -- ($(P)!6pt!(l2a)$);

  %% marking other angles
  \tkzMarkAngle(S,P,T)
  \tkzLabelAngle[pos=0.75](S,P,T) {$\theta$}

  \tkzMarkAngle(Q,P,R)
  \tkzLabelAngle[pos=0.75](Q,P,R) {$\theta$}

  \tkzMarkAngle[size=1.65](T,P,Q)
  \tkzLabelAngle[rotate=-25](T,P,Q){$\theta-90^\circ$}

  \end{tikzpicture}

\end{document}

结果是

在此处输入图片描述

这里与其他示例的不同之处在于我使用tkz-euclide宏来查找:

  • 两条线的交点:\tkzInterLL(<point>,<point>)(<point>,<point>)
  • 您可以通过以下方式检索点并命名:\tkzGetPoint{<point name>}
  • 我使用tkz-euclide宏来标记和标注角度:\tkzMarkAngle\tkzLabelAngle

我有时发现 的方法tkz-euclide不太理想。例如,\tkzMarkRightAngle做得比较好,但对虚线不太好。所以,我即兴发挥了。我还向您展示了如何在 处即兴发挥那个直角P。我的方法与 @JohnKormylo 的方法略有不同。我使用 TikZ 库calc。如果我要将其编写为宏,我会按如下方式执行:

\def\aeMarkRightAngle[size=#1](#2,#3,#4){%%
   \draw ($(#3)!#1!(#2)$) -- 
         ($($(#3)!#1!(#2)$)!#1!90:(#2)$) --
         ($(#3)!#1!(#4)$);}

然后可以将其称为

  \aeMarkRightAngle[size=6pt](R,P,l2a)

相关内容