4

I am trying to draw this image below

enter image description here

So far I have done the following code:

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

And displays:

enter image description here

Now, I'm having difficulties in drawing the angle inside, could someone please help?

Thank you in advance.

3 Answers 3

6

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

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

4

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

4
  • Thank you so much for the alternative sir. I know not too much about tikz. I noticed that when adding \draw (1,0.5) arc (0:26:1)node[midway,above right]{$\theta$}; and removing \node at (5.4,0.6) {$\square$}; on my code, works too to draw the angle. Jul 31, 2020 at 17:58
  • 1
    @América Well it draws an arc of 26 degrees and hence it is not really what you want. For your initial drawing it would be more like \draw (1.5,0.5) arc (0:45:1)node[midway,above right]{$\theta$};
    – TobiBS
    Jul 31, 2020 at 18:01
  • right right, that looks better. Jul 31, 2020 at 18:20
  • @América If you like my answer and it was helpful, please consider upvoting (by clicking on the arrows next to the score) and/or marking it as the accepted answer (by clicking on the checkmark ✓).
    – TobiBS
    Jul 31, 2020 at 18:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .