2

How can I show the right angle between the blue and the red line? enter image description here

\documentclass[border=2pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}% at least 1.11

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    axis equal=true,
    axis lines=middle, enlargelimits=false,
    xlabel={$x$},    ylabel={$y$},
    xlabel style={at={(ticklabel* cs:0.983)},anchor=west},
    ylabel style={at={(ticklabel* cs:1.03)}, anchor=north west, align=right},
    tick style={},
    x tick label style={below},
    y tick label style={left},
    xmin=-8,xmax=10,ymin=-8,ymax=12,
    xtick={}, ytick={},
    xticklabels={},   yticklabels={},
    after end axis/.code={
    \path(axis cs:0,0) 
    node [anchor=north east,xshift=0 cm] {O};}]
  \addplot[domain=-5:8,red] {5-x};
  \addplot[domain=-5:6,blue] {3+x};
\end{axis}
\end{tikzpicture}   
\end{document}
1
  • did you check the library angles in pgfmanual?
    – Black Mild
    Oct 16 at 20:23
4

With pgfplots and using TikZ libraries angle and intersection:

Edit: Added are dot on angle mark sign.

\documentclass[border=3.141592]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}% at least 1.11
\usetikzlibrary{angles,
                intersections,
                quotes}

\begin{document}
    \begin{tikzpicture}
\begin{axis}[
    axis lines=middle,
    axis equal=true,
    xlabel={$x$},    ylabel={$y$},  label style={anchor=north east},
    xmin=-4.5,xmax=6.5,ymin=-1.5,ymax=9.5,
%    xtick=\empty,   ytick=\empty,
    tick label style={font=\scriptsize},
%
    no marks,
    domain=-4:6,
            ]
  \addplot +[name path=b] {5-x} coordinate (B);
  \addplot +[name path=r] {3+x} coordinate (R);
  
  \path [name intersections={of=b and r, by={C}}]
       pic [draw, angle radius=3mm,
            angle eccentricity=0.5, "$\cdot$"] {right angle=B--C--R}; % or $\bullet$, if you like more bold dot
        
\coordinate[label=below left:O] (O) at (0,0);
\end{axis}
    \end{tikzpicture}
\end{document}
% add at end of axis if you like to have dashed lines between intersection and axis
%\draw[densely dashed, ultra thin] 
%        ([yshift=-2pt] O-|C) node[font=\scriptsize,below] {1}
%                             |- (O|-C) ;

enter image description here

6
  • Can we put a point in the middle of a right angle? @Zarko
    – cufcuf
    Oct 17 at 5:12
  • 1
    @cufcuf, yes. By use of quotes library. I will add this ASAP.
    – Zarko
    Oct 17 at 5:21
  • Thanks. It would be great, if we could also adjust the size of the right angle @Zarko
    – cufcuf
    Oct 17 at 5:24
  • One last thing, How do I send the right angle behind the lines? @Zarko
    – cufcuf
    Oct 17 at 5:57
  • 1
    @cufcuf, new problem, new question ;-). Try to use backgrounds library and insert \scoped[on background layer] before code for angle (if I understood you correctly).
    – Zarko
    Oct 17 at 6:07
4

You can use the right angle key from the library angles.

enter image description here

\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{angles}
\begin{document}
\begin{tikzpicture}[scale=.4]
\draw[->] (-6,0)--(8,0) node[below]{$x$};   
\draw[->] (0,-2)--(0,11)  node[left]{$y$};
\path
(0,0) node[below left]{O}
(1,0) node[below]{$1$}
(0,4) node[left]{$4$}
;
\draw[densely dotted] (1,4)--(1,0) (1,4)--(0,4);        
% the line y=3+x from x=-5 to x=6
\draw[blue] 
(-5,-2) coordinate (A1)--
(6,9)   coordinate (A2) 
node[pos=.9,sloped,above]{$y=3+x$};
        
% the line y=5-x from x=-5 to x=8
\draw[red] 
(-5,10) coordinate (B1)--
(7,-2)  coordinate (B2)
node[pos=.1,sloped,above]{$y=5-x$};   

\path 
(intersection of A1--A2 and B1--B2) coordinate (I)
pic[draw,angle radius=3mm,angle eccentricity=.5,pic text=$\cdot$]{right angle=B2--I--A2};
\end{tikzpicture}
\end{document}
1
  • I start to believe that simplicity is not target of many people ^^
    – Black Mild
    Oct 17 at 5:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.