TikZ-PGF – Modifying a Feynman Diagram: Drawing Squares and Lines

diagramsfeynmanfeynmp-autotikz-pgf

I have the following code:

\documentclass[border=3mm]{standalone}
\usepackage{tikz-feynman}
\usetikzlibrary{shapes.geometric}
\usepackage{amsmath}

\begin{tikzpicture}
\begin{feynman}
\node[shape=circle,draw=black, inner sep=0pt,minimum size=20pt] (m) at ( 0, 0) {};
\node[shape=rectangle,fill=black] (n) at (3, 0) {square };
\vertex (a) at ( 210:2cm) {};
\vertex (b) at ( -30:2cm) {};
\vertex (c) at (150:2cm) {};
\vertex (d) at (30:2cm) {};      
        
\diagram* {
(a) -- [photon,edge label'=$q_2$] (m) 
-- [photon,edge   label'=$q_1$] (c),
(n) -- [bend left=45, edge label=$\pi^+(K^+)$] (m)
-- [bend left=45, edge label=$\pi^-(K^-)$] (n),
};
\end{feynman}
\end{tikzpicture}

\end{document}

which produces:

enter image description here

I have three questions:

  1. How can we make the rectangle, a square?

  2. How can we make the curves lines enter the square at the two vertices in the left?

  3. How can we create two straight lines come out of the other two vertices of the square in right?

Thanks for your help!

Best Answer

  1. As you now have it, the node (n) contains the text "square", which is much wider than tall. You can make it square by adding a \rule there instead.
  2. The above will take care of this one too, thanks to geometry...
  3. You need two more vertices at coordinates calculated using node n as the origin. I called them (e) and (f).
\documentclass[border=3mm]{standalone}
\usepackage{tikz-feynman}
\usetikzlibrary{shapes.geometric,calc}
\usepackage{amsmath}
\begin{document}
\begin{tikzpicture}
\begin{feynman}
\node[shape=circle,draw=black,inner sep=0pt,minimum size=20pt] (m) at (0, 0) {};
\node[shape=rectangle,fill=black] (n) at (3, 0) {\rule{0.5cm}{0.5cm}};
\vertex (a) at (225:2cm) {};
\vertex (b) at (-45:2cm) {};
\vertex (c) at (135:2cm) {};
\vertex (d) at (45:2cm) {};
\vertex (e) at ($(n) + (-45:2cm)$) {};
\vertex (f) at ($(n) + (45:2cm)$) {};

\diagram*{
(a) -- [photon,edge label'=$q_2$] (m)
-- [photon,edge   label'=$q_1$] (c),
(n) -- [bend left=45, edge label=$\pi^+(K^+)$] (m)
-- [bend left=45, edge label=$\pi^-(K^-)$] (n),
(e) -- (n) -- (f),
};
\end{feynman}
\end{tikzpicture}
\end{document}

I also changed the angles of the lines to 45 degrees, instead of 30, otherwise the lines exiting the black square will not fall on the vertices (again, because geometry).

The result is shown below:

result