I am using tikz to draw Feynman diagrams, and I learned how to draw a curved snake path.
The problem is that in general line segments are present (I'd like to avoid them).
I found a couple of post with could help to solve the problem, but none of them is working properly for me. The post are:
The second method results in the figure below,
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,decorations.markings,snakes}
\newif\ifstartcompletesineup
\newif\ifendcompletesineup
\pgfkeys{
/pgf/decoration/.cd,
start up/.is if=startcompletesineup,
start up=true,
start up/.default=true,
start down/.style={/pgf/decoration/start up=false},
end up/.is if=endcompletesineup,
end up=true,
end up/.default=true,
end down/.style={/pgf/decoration/end up=false}
}
\pgfdeclaredecoration{complete sines}{initial}
{
\state{initial}[
width=+0pt,
next state=upsine,
persistent precomputation={
\ifstartcompletesineup
\pgfkeys{/pgf/decoration automaton/next state=upsine}
\ifendcompletesineup
\pgfmathsetmacro\matchinglength{
0.5*\pgfdecoratedinputsegmentlength / (ceil(0.5* \pgfdecoratedinputsegmentlength / \pgfdecorationsegmentlength) )
}
\else
\pgfmathsetmacro\matchinglength{
0.5 * \pgfdecoratedinputsegmentlength / (ceil(0.5 * \pgfdecoratedinputsegmentlength / \pgfdecorationsegmentlength ) - 0.499)
}
\fi
\else
\pgfkeys{/pgf/decoration automaton/next state=downsine}
\ifendcompletesineup
\pgfmathsetmacro\matchinglength{
0.5* \pgfdecoratedinputsegmentlength / (ceil(0.5 * \pgfdecoratedinputsegmentlength / \pgfdecorationsegmentlength ) - 0.4999)
}
\else
\pgfmathsetmacro\matchinglength{
0.5 * \pgfdecoratedinputsegmentlength / (ceil(0.5 * \pgfdecoratedinputsegmentlength / \pgfdecorationsegmentlength ) )
}
\fi
\fi
\setlength{\pgfdecorationsegmentlength}{\matchinglength pt}
}] {}
\state{downsine}[width=\pgfdecorationsegmentlength,next state=upsine]{
\pgfpathsine{\pgfpoint{0.5\pgfdecorationsegmentlength}{0.5\pgfdecorationsegmentamplitude}}
\pgfpathcosine{\pgfpoint{0.5\pgfdecorationsegmentlength}{-0.5\pgfdecorationsegmentamplitude}}
}
\state{upsine}[width=\pgfdecorationsegmentlength,next state=downsine]{
\pgfpathsine{\pgfpoint{0.5\pgfdecorationsegmentlength}{-0.5\pgfdecorationsegmentamplitude}}
\pgfpathcosine{\pgfpoint{0.5\pgfdecorationsegmentlength}{0.5\pgfdecorationsegmentamplitude}}
}
\state{final}{}
}
\tikzset{
% style to apply some styles to each segment of a path
on each segment/.style={
decorate,
decoration={
show path construction,
moveto code={},
lineto code={
\path [#1]
(\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
},
curveto code={
\path [#1] (\tikzinputsegmentfirst)
.. controls
(\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb)
..
(\tikzinputsegmentlast);
},
closepath code={
\path [#1]
(\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
},
},
},
% style to add an arrow in the middle of a path
mid arrow/.style={postaction={decorate,decoration={
markings,
mark=at position .5 with {\arrow[#1]{stealth}}
}}},
}
\begin{document}
\begin{frame}
\frametitle{Field and Mass Renormalization}
\begin{center}
\begin{tikzpicture}[thick,scale=.6]
\path [draw=blue,postaction={on each segment={mid arrow=blue}}]
(-4,0) -- (-2,0) -- (2,0) -- (4,0);
\draw[draw=blue,decorate, decoration=complete sines] (2,0) arc (0:180:2cm);
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}
Any fresh ideas on this respect?