4

I get the following error: Package pgf Error: No shape named Q is known. Without the \begin{axis} ... \end{axis}, the code is compiled but the images depicted is a jumbled mess. I intended to get a right triangle with vertices A, P, and Q and with a right angle at Q. B is a point on the line through P and Q. How do I get a right angle drawn at Q?

\documentclass[10pt]{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathtools,array}

\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\usepackage{tkz-euclide}
\usetkzobj{all}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}


\begin{document}


\begin{tikzpicture}
\begin{axis}
[width=6in,axis equal image,
    axis lines=middle,
    xmin=-10,xmax=10,samples=201,
    xlabel=$x$,ylabel=$y$,
    ymin=-4,ymax=6,
    restrict y to domain=-4:6,
    enlargelimits={abs=0.5cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xtick={\empty},ytick={\empty},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\path (80:3) coordinate (a) (20:3.5) coordinate (b) (0:0) node[label=below left:$P$]{} coordinate(P)(-100:1)coordinate (e) (-160:1) coordinate (f)(80:2) node [label=above left:$A$]{} coordinate (A) (20:2.5) node [label=below:$B$]{} coordinate (B) ($(P)!(A)!(B)$) coordinate (Q) node [label=below:$Q$]{};
\draw[<->]  (a) node [above left ]{$l$} -- (e);
\draw[<->]  (b) node [below right]{$k$} -- (f);

\draw[purple!70!black,dashed] (A) -- (Q);
%\tkzMarkRightAngle(A,Q,P);

\draw[|<->|] ($(P)!3mm!90:(A)$)--node[fill=white,sloped] {$r$} ($(A)!3mm!-90:(P)$);
\draw[|<->|] ($(P)!-3mm!90:(Q)$)--node[fill=white,sloped] {$x$} ($(Q)!-3mm!-90:(P)$);
\draw[|<->|] ($(Q)!-3mm!90:(A)$)--node[fill=white,sloped] {$y$} ($(A)!-3mm!-90:(Q)$);
\path pic[draw, angle radius=5mm,"$\theta$",angle eccentricity=1.25] {angle = B--P--A};
\end{axis}
\end{tikzpicture}

    \end{document}
  • Please paste the full code then others can just paste it and compile out what your get. your current code can not compile and even if comment out the axis command. – Beatlej Nov 26 '14 at 20:39
  • Maybe help: tex.stackexchange.com/a/188562/31034 – ferahfeza Nov 26 '14 at 21:09
  • @ Beatlej I had a typographical mistake - "\end\end{axis}." It will compile now without the optional argument for the axis. – Adelyn Nov 27 '14 at 0:13
2
+50

This is one way of doing it. Firstly, the proposal converts points into axis cs coordinate so that they are comparable with the pgfplot axis.

The right angles on the triangle are found via intersections of grid lines notion, that is, finding intersection points of parallel lines that are parallel to lines A-Q and P-Q.

enter image description here

Code

\documentclass[border=10pt]{standalone}%[10pt]{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathtools,array}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\usepackage{tkz-euclide}
\usetkzobj{all}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[width=6in,axis equal image,
    axis lines=middle,
    xmin=-2,xmax=4,samples=201,
    xlabel=$x$,ylabel=$y$,
    ymin=-2,ymax=3,
    restrict y to domain=-4:6,
    enlargelimits={abs=0.5cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xtick={\empty},ytick={\empty},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
% Convert all points into axis cs system
\node[] at (axis cs: {3*cos(80)},{3*sin(80)})       (a){};
\node[] at (axis cs: {3.5*cos(20)},{3.5*sin(20)}) (b){};
\node[label=below left:$P$] at (axis cs: 0,0)     (P){};
\node[] at (axis cs: {1*cos(-100)},{1*sin(-100)}) (e){}; 
\node[] at (axis cs: {1*cos(-160)},{1*sin(-160)})  (f){};
\node[label=above left:$A$] at (axis cs: {2*cos(80)},{2*sin(80)})(A){}; 
\node[label=below:$B$] at (axis cs: {2.5*cos(20)},{2.5*sin(20)}) (B){} ;
\node[label=below right:$Q$,coordinate] at ($(P)!(A)!(B)$) (Q){};
\node [] at (axis cs:0.5,3){$l$};
\node [] at (axis cs:3,0.9){$k$};
\draw[<->]  (a) -- (e);
\draw[<->,name path=linea]  (b) -- (f);                   % added path name
\draw[purple!70!black,dashed,name path=lineb] (A) -- (Q); % added path name
%
\draw[|<->|] ($(P)!3mm!90:(A)$)--node[fill=white,sloped] {$r$} ($(A)!3mm!-90:(P)$);
\draw[|<->|] ($(P)!-3mm!90:(Q)$)--node[fill=white,sloped] {$x$} ($(Q)!-3mm!-90:(P)$);
\draw[|<->|] ($(Q)!-3mm!90:(A)$)--node[fill=white,sloped] {$y$} ($(A)!-3mm!-90:(Q)$);
\path pic[draw, angle radius=5mm,"$\theta$",angle eccentricity=1.25] {angle = B--P--A};

% draw parallel lines
\path[name path=line1,red]  ([yshift=1cm]$(P)!0!(Q)$) -- ([yshift=1cm]$(P)!1!(Q)$);
\path[name path=line2,red]  ([yshift=-2cm]$(A)!0!(Q)$) -- ([yshift=-2cm]$(A)!1!(Q)$);

% find intersections
\path [name intersections={of=line1 and line2,by={E}}];  % corner tip
\path [name intersections={of=line2 and linea,by={E2}}];
\path [name intersections={of=line1 and lineb,by={E1}}];

% draw the right angle
\draw[red] (E1)--(E)--(E2);
\end{axis}

\end{tikzpicture}
\end{document}
  • Hi, @Adelyn, Andrew said in this post tex.stackexchange.com/a/188562/34618 that euclide and tikz use completely different coordinate. That remarks inspired me to seek alternatives as posed in my answer. To have the same right angle for all diagram requires manually adjust the yshift value for the parallel lines. – Jesse Dec 6 '14 at 16:05
  • Yeah, I did see this post on tex.stackexchange. (I am glad that you made a reference to it.) Are you saying that a command like (120:1)coordinate (A) will not be compiled in euclide? – Adelyn Dec 6 '14 at 16:24
  • Do you know the length of each side of the right angle mark when the package TikZ is used? I have diagrams of right triangles that are drawn using TikZ` on other pages; I want the right angle marks to be identical to the right angle mark that I have to manually make using euclide. – Adelyn Dec 6 '14 at 16:25
  • Polar coordinate (120:1) did give me trouble when I tackled your question. As to the length of the right angle, you can change the \path to \draw, to see the red line1 and line2. The solution uses yshift= 1cm and 2cm, but reducing the number gets a smaller right angle. you need to try to find the one you need. – Jesse Dec 6 '14 at 16:54

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.