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.

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}
As is explained in How do I draw shapes inside a tikz node? pics
can be used for defining new objects. My main problem using pics is how to place where you want because they aren't nodes
and positioning them is not so easy.
Following code shows how to define EDFA
block.
EDFA/.pic={
\begin{scope}[scale=.5]
\draw (-1,0) coordinate (in) -- (-1,1) -- (1,0) coordinate (out) -- (-1,-1) -- cycle;
\node[anchor=north,inner sep=2pt] at (0,-1) {$1$};
\end{scope}
In this case, coordinate (-1,0) will act as west
anchor and 1,0
as east. Both point will have an special name for further reference. Every pic
is placed according its own origin (0,0)
. You can use Claudio's answer to Anchoring TiKZ pics for better positioning.
As your example was simple, I'd prefer to star with EDFA
and place Source
and Sink
after it.
\documentclass[]{article}
% tikz
\usepackage{tikz}
\usetikzlibrary{positioning} %relative positioning
\begin{document}
\tikzset{%
EDFA/.pic={
\begin{scope}[scale=.5]
\draw (-1,0) coordinate (in) -- (-1,1) -- (1,0) coordinate (out) -- (-1,-1) -- cycle;
\node[anchor=north,inner sep=2pt] at (0,-1) {$1$};
\end{scope}
}
}
\begin{tikzpicture}[
block/.style={draw},
]
\draw pic (edfa) {EDFA};
\node[block, left=of edfain] (source) {Source};
\node[block, right= of edfaout] (sink) {Sink};
\draw[->] (source) -- (edfain);
\draw[->] (edfaout) -- (sink);
\end{tikzpicture}
\end{document}

I understand that your components are more complex than EDFA
because for this particular case an isosceles triangle
node with a label
will do the work and it can be used as a node
and not as a pic
:
\documentclass[]{article}
% tikz
\usepackage{tikz}
\usetikzlibrary{positioning} %relative positioning
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}[
block/.style={draw},
edfa/.style={isosceles triangle, minimum width=1cm,
draw, anchor=west, isosceles triangle stretches,
minimum height=1cm, label=-80:#1}
]
\node[block] (source) {Source};
\node[edfa=1, right=of source] (edfa) {};
\node[block, right= of edfa] (sink) {Sink};
\draw[->] (source) -- (edfa);
\draw[->] (edfa) -- (sink);
\end{tikzpicture}
\end{document}
Best Answer
The syntax for coordinate calculations is
The problem is that
(vertexA)+(vertexB)+(vertexC)
is not a coordinate. You have to telltikz
that you want it to calculate the coordinate at(vertexA)+(vertexB)+(vertexC)
. This will work:(You can nest coordinate calculations).