Drawing a triangle with an angle inside and other details

The principle of TikZ is to build paths on which you can draw straight or curved lines, place text wherever you want.

So I grouped several paths into one. I commented the code that was no longer needed.

For the angles, I used the angles library. If you need more explanations, just say so, I will update my answer.

screenshot

\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}

With using the angles and quotes TikZ libraries:

\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}

enter image description here


I optimized your code a bit, I hope this gives you some hints how to use TikZ more productively. The angle you were looking for is drawn with \draw (1,0) arc (0:45:1)node[midway,above right]{$\theta$}; and that draws an arc from 1,0 with the starting angle 0, end angle 45 and a radius of 1. It also places a node midway and above right, so you don't have to manually calculate a coordinate here.

\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}

enter image description here

Tags:

Tikz Pgf