绘制三角形及其内部角度和其他细节

绘制三角形及其内部角度和其他细节

我正在尝试绘制下面的图像

在此处输入图片描述

到目前为止我已经完成了以下代码:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{tikz}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{xcolor}

\begin{document}

\begin{center}
\begin{tikzpicture}

    \node at (1.5,1) {$\theta$};
    \node at (5.4,0.6) {$\square$};
    \node at (3.5,3.8) {$r$};
    \node at (5.8,3.5) {$y$};
    \node at (5.5,6) {\color{red}$(x,y)$};
    \node at (5.5,5.5)[circle,red,fill,inner sep=3pt]{$ $} ;


\node[left] at (0.5,0.2) {$0$};
\node[left] at (0.5,7) {$y$};
\node[left] at (7,.2) {$x$};
\node[left] at (3,.2) {$x$};

   %coordinate system
    \color{black}
    \draw[thick,->] (.5,0)--(.5,7);
    \color{black}
    \draw[thick,->] (0,.5)--(7,.5);
    
    \color{red}
    \draw{  (0.5,0.5) -- (5.5,5.5)};
    
    \color{black}
    \draw[dashed]{  (5.5,0.5) -- (5.5,5.5)};
    

  \end{tikzpicture}
\end{center}

\end{document}

并显示:

在此处输入图片描述

现在,我在绘制里面的角度时遇到了困难,有人可以帮忙吗?

先感谢您。

答案1

TikZ 的原理是构建路径,您可以在其上绘制直线或曲线,并将文本放置在您想要的任何位置。

所以我把几条路径合并成一条。我注释掉了不再需要的代码。

对于角度,我使用了angles库。如果您需要更多解释,请说出来,我会更新我的答案。

截屏

\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{angles}
%\usepackage[utf8]{inputenc}

%\usepackage{tikz}
%\usepackage{graphicx}
%\usepackage{amsmath}
%\usepackage{amssymb}
%\usepackage{xcolor}

\begin{document}

%\begin{center}
\begin{tikzpicture}

%    \node at (1.5,1) {$\theta$};
%    \node at (5.4,0.6) {$\square$};
%    \node at (3.5,3.8) {$r$};
%    \node at (5.8,3.5) {$y$};

%--------  old code -----------------
%   \node at (5.5,6) {\color{red}$(x,y)$};
%    \node at (5.5,5.5)[circle,red,fill,inner sep=3pt]{$ $} ;
    \node (M) [circle,red,fill,inner sep=3pt,label={[red,above]:$(x,y)$}]at
     (5.5,5.5){} ;
%------------------------------------
%--------- old code -----------------
%\node[left] at (0.5,0.2) {$0$};
\node (O)[below left,label=below left:$O$,inner sep=0pt] at (0,0) {};
%------------------------------------
%--------- old code ----------------
%\node[left] at (0.5,7) {$y$};
%\node[left] at (7,.2) {$x$};
%\node[left] at (3,.2) {$x$};

   %coordinate system
%    \color{black}
    \draw[thick,->] (0,-.5)--(0,7)node[left]{$y$};
%    \color{black}
    \draw[thick,->] (-.5,0)--node[below]{$x$}(7,0)node[below left]{$x$};
    
%    \color{red}
    \path[draw=red]  (O) -- node[above]{$r$}(M);
    
%    \color{black}
    \draw[dashed]  (5.5,0)coordinate(H) -- node[right]{$y$}(M);
%-------------------------------------
    \pic[draw,radius=7mm,angle eccentricity=1.5,pic text=$\theta$]{angle=H--O--M};
    \pic[draw,angle radius=3mm]{right angle=M--H--O};
  \end{tikzpicture}
%\end{center}

\end{document}

答案2

我稍微优化了你的代码,希望这能给你一些提示,让你知道如何更有效地使用 TikZ。你要找的角度是用 绘制的\draw (1,0) arc (0:45:1)node[midway,above right]{$\theta$};,它从 绘制一个圆弧,1,0其起始角度为0,终止角度45为 ,半径为1。它还放置了一个节点midwayabove right,因此你不必在这里手动计算坐标。

\documentclass[tikz,border=5mm]{standalone}

\begin{document}
    \begin{tikzpicture}
    %coordinate system
    \draw[thick,->] (0,-.5) -- ++(0,7)node[above left]{$y$};
    \draw[thick,->] (-.5,0) -- ++(7,0)node[midway, below]{$x$} node[below right]{$x$};
    \node[below left] at (0,0) {$0$};

    \draw[dashed] (5,0) -- (5,5) node[midway,right]{$y$};
    \draw (4.7,0) |- ++(0.3,0.3);
    \draw[red] (0,0) -- (5,5) node[midway,above left,text=black]{$r$} node[circle,red,fill,inner sep=2pt]{} node[above]{$(x,y)$};
    \draw (1,0) arc (0:45:1)node[midway,above right]{$\theta$};
    \end{tikzpicture}
\end{document}

在此处输入图片描述

答案3

使用anglesquotesTikZ 库:

\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{angles, arrows.meta,
                quotes}

\begin{document}
    \begin{tikzpicture}[auto,
              > = Straight Barb,
     dot/.style = {circle, fill, inner sep=2pt},
my angle/.style = {draw,
                   angle radius = 12mm,
                   angle eccentricity=1.2}
                        ]
% axses
\draw[thick,->] (0,-.5) -- ++(0,7) coordinate[label=left:$y$] (y);
\draw[thick,->] (-.5,0) -- ++(7,0) coordinate[label=below:$x$] (x);
\coordinate[label=below left:$0$] (O) at (0,0); 
% vector
\draw[red] (O) to [sloped, text=black, "$r$"] (45:7) 
               node (v) [dot, label=above:{$(x,y)$}] {};
% vector projections
\draw[densely dashed] 
        (v) to ["$y$"] (v |- O);
\path   (O) to ["$x$" '] (v |- O) coordinate (aux);
% angles
\pic [my angle, "$\theta$"]     {angle = x--O--v};
\pic [draw, angle eccentricity=.5, "$\cdot$"]
            {right angle = v--aux--O};    
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容