2

enter image description here

How should I put a square for 90 degrees angle? my code is;

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[scale=1.3]
\draw [->, ultra thick, grey](0,-6)--(0,6) node[right,font=\fontsize {30}
{30}\selectfont]{$x$};
\draw [->,ultra thick, grey](-6,0)--(6,0) node[above,font=\fontsize {30}
{30}\selectfont]{$y$};
\draw (6,-2)--(-6,6);
\draw (-4,-4)--(2,5);
\draw[font=\fontsize{15}{15}\selectfont,black]
 --(3,1) node {$\tan\theta_2$};
 \fill[yellow] (3,0)-- ++(4mm,0mm)
 arc[start angle=0, end angle=143.130102, radius=4mm]--cycle;
 \fill[yellow] (-1.333333333,0)-- ++(4mm,0mm)
 arc[start angle=0, end angle=56.3099, radius=4mm]--cycle;
 \draw[font=\fontsize{10}{10}\selectfont, black]
 --(-.5,.4) node {$\tan\theta_1$};

\end{tikzpicture}

\end{document}
4

In this case it might be simplest to do that by hand. (I also replaced grey by gray.)

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[scale=1.3]
\draw [->, ultra thick, gray](0,-6)--(0,6) node[right,font=\fontsize {30}
{30}\selectfont]{$x$};
\draw [->,ultra thick, gray](-6,0)--(6,0) node[above,font=\fontsize {30}
{30}\selectfont]{$y$};
\draw (6,-2)--(-6,6);
\draw (-4,-4)--(2,5);
\draw (0.3,{2-0.2}) -- ++(-0.2,-0.3)--++(-0.3,0.2);
\draw[font=\fontsize{15}{15}\selectfont,black]
 --(3,1) node {$\tan\theta_2$};
 \fill[yellow] (3,0)-- ++(4mm,0mm)
 arc[start angle=0, end angle=143.130102, radius=4mm]--cycle;
 \fill[yellow] (-1.333333333,0)-- ++(4mm,0mm)
 arc[start angle=0, end angle=56.3099, radius=4mm]--cycle;
 \draw[font=\fontsize{10}{10}\selectfont, black]
 --(-.5,.4) node {$\tan\theta_1$};

\end{tikzpicture}

\end{document}

enter image description here

EDIT: Here comes a perhaps even simpler alternative with explanation.

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[scale=1.3]
\draw [->, ultra thick, gray](0,-6)--(0,6) node[right,font=\fontsize {30}
{30}\selectfont]{$x$};
\draw [->,ultra thick, gray](-6,0)--(6,0) node[above,font=\fontsize {30}
{30}\selectfont]{$y$};
\draw (6,-2)--(-6,6);
\draw (-4,-4)--(2,5);
% the slope of the first line is -12/8, so this defines the rotation angle
\draw[rotate around={atan2(8,-12):(0,2)}] (0,2) rectangle ++(-0.3,0.3);
%\draw (0.3,{2-0.2}) -- ++(-0.2,-0.3)--++(-0.3,0.2);
\draw[font=\fontsize{15}{15}\selectfont,black]
 --(3,1) node {$\tan\theta_2$};
 \fill[yellow] (3,0)-- ++(4mm,0mm)
 arc[start angle=0, end angle=143.130102, radius=4mm]--cycle;
 \fill[yellow] (-1.333333333,0)-- ++(4mm,0mm)
 arc[start angle=0, end angle=56.3099, radius=4mm]--cycle;
 \draw[font=\fontsize{10}{10}\selectfont, black]
 --(-.5,.4) node {$\tan\theta_1$};

\end{tikzpicture}

\end{document}
| improve this answer | |
  • Thank you but how you chose those coordinates?I can't make sense of it. – Abbas Mar 7 '18 at 19:42
  • @Abbas Well, the slopes of your lines are -8/12 and +12/8. I just started from the point at which the lines intersect and, went a bit along the slope of the first line, than parallel to the second, and then parallel to the first. – user121799 Mar 7 '18 at 19:52
1

i would redraw your image as follows:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{angles,
                backgrounds,
                intersections,
                quotes}

\begin{document}
    \begin{tikzpicture}[%[scale=1.3]
     al/.style = {font=\Huge},% axis label
myangle/.style = {angle radius=7mm, angle eccentricity=1.6, fill=yellow, font=\scriptsize},
                    ]
\draw[->, ultra thick, gray] (0,-6)--(0,6) node[al,right]{$x$};
\draw[name path=A,->, ultra thick, gray] (-6,0)--(6,0) node[al,above]{$y$};
\draw[name path=B] (-6,6) -- node[draw, minimum size=5mm, outer sep=0pt, sloped, % <--
                                  below right] {} (6,-2);
\draw[name path=C] (-4,-4)--(2,5);
%
\path[name intersections={of=A and B, by=a}];
\path[name intersections={of=A and C, by=b}];
\path[name intersections={of=B and C, by=c}];
%
    \begin{scope}[on background layer]
\pic[myangle, "$\tan\theta_1$"] {angle = a--b--c};
\pic[myangle, "$\tan\theta_2$"] {angle = c--a--b};
    \end{scope}
    \end{tikzpicture}
\end{document}

which gives:

enter image description here

| improve this answer | |
1

Works even in 3D !

enter image description here

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

\pgfkeys{/tikz/.cd,
  AngleDt length/.store in=\AngleDtLgth,
  AngleDt length=5pt}

\tikzset{% Angle droit
    AngleDt/.style={very thin},
    pics/.cd,
    AngleDt/.style args={#1-#2-#3}{%
        code = {%
        \draw[AngleDt] ($(#2)!\AngleDtLgth!(#1)$)
        --($(#2)!2!($($(#2)!\AngleDtLgth!(#1)$)!.5!($(#2)!\AngleDtLgth!(#3)$)$) $)
        --($(#2)!\AngleDtLgth!(#3)$) ; ;
        }
    }}

\begin{document}

\begin{tikzpicture}[scale=1.3]
\draw [->, ultra thick](0,-6)--(0,6) node[right,font=\fontsize {30}
{30}\selectfont]{$x$};
\draw [->,ultra thick](-6,0)--(6,0) node[above,font=\fontsize {30}
{30}\selectfont]{$y$};
\draw[name path=P1] (6,-2) coordinate (A) --(-6,6);
\draw[name path=P2] (-4,-4)--(2,5) coordinate (C);
\draw[font=\fontsize{15}{15}\selectfont,black]
 --(3,1) node {$\tan\theta_2$};
 \fill[yellow] (3,0)-- ++(4mm,0mm)
 arc[start angle=0, end angle=143.130102, radius=4mm]--cycle;
 \fill[yellow] (-1.333333333,0)-- ++(4mm,0mm)
 arc[start angle=0, end angle=56.3099, radius=4mm]--cycle;
 \draw[font=\fontsize{10}{10}\selectfont, black]
 --(-.5,.4) node {$\tan\theta_1$};


\path[name intersections={of= P1 and P2,by=B}] ;
\path pic[AngleDt length=7mm,red] {AngleDt={A-B-C}} ;

\end{tikzpicture}

\begin{tikzpicture}[line join=round,
    x={(40:2.6cm)},
    y={(180:4cm)},
    z={(0cm,4cm)}]

\coordinate (C) at (1,0,0) ;
\coordinate (B) at (0,0,0) ;
\coordinate (A) at (0,1,0) ;
\coordinate (D) at (1,1,0) ;

\coordinate (H) at (.5,.5,.707) ;
\coordinate (h) at (.5,.5,0) ;

\fill[blue!15] (A)--(B)--(H)--cycle ;
\fill[blue!30] (B)--(C)--(H)--cycle ;

\draw (A)--(B)--(C)--(H)--cycle ;
\draw (B)--(H) ;

\draw[dashed] (A)--(D)--(C) ;
\draw[dashed] (H)--(D) ;

\draw[dotted] (A)--(C) ;
\draw[dotted] (B)--(D) ;
\draw[dotted] (H)--(h) node[midway,anchor=east] {$h$};

\path pic {AngleDt={H-h-A}} ;
\path pic {AngleDt={B-h-H}} ;

\foreach \Coor/\Text/\Pos in 
    {A/$A$/215,
    B/$B$/-45,
    C/$C$/0,
    D/$D$/-92,
    H/$H$/90%
    } {%
    \node[shift=(\Pos:8pt),anchor=center] at (\Coor) {\small\Text} ;
    }

\end{tikzpicture}
\end{document}
| improve this answer | |
1

This is how I would redraw your image using right angle from TikZ 3.1:

\documentclass[tikz,border=7pt]{standalone}
\usetikzlibrary{angles}
\begin{document}
  \tikz[nodes={scale=.7}]
    \path
      % axes
      (4,0) edge[latex-] (-2,0) coordinate (X) node[above]{$x$}
      (0,3) edge[latex-] (0,-1) coordinate (Y) node[right]{$y$}
      % points
      foreach \x/\y/\n in {0/0/O,-1.3/0/A,3/0/B,0/2/C}{
        (\x,\y) coordinate(\n)
      }
      % sloped lines
      (A) edge[gray,shorten <=-7mm,shorten >=-7mm] (C)
      (B) edge[gray,shorten <=-7mm,shorten >=-7mm] (C)
      % angles
      pic[fill=yellow,angle eccentricity=2.1,pic text=$\tan\theta_1$]{angle=X--A--C}
      pic[fill=yellow,angle eccentricity=1.5,pic text=$\tan\theta_2$]{angle=X--B--C}
      pic[fill=red,angle radius=4mm]{right angle=A--C--B}
    ;
\end{document}

enter image description here

| improve this answer | |

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.