This is a slightly adapted version of my answer to Nicer wavy line with TikZ. This version doesn't insist on drawing a full sine wave, but will be happy with half periods as well (i.e. it can start and end with an upward arch, while the previous version would always start with an upward and end with a downward arch):

\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usetikzlibrary{decorations}
\begin{document}
\pgfdeclaredecoration{complete sines}{initial}
{
\state{initial}[
width=+0pt,
next state=upsine,
persistent precomputation={\pgfmathsetmacro\matchinglength{
\pgfdecoratedinputsegmentlength / int(\pgfdecoratedinputsegmentlength/\pgfdecorationsegmentlength)}
\setlength{\pgfdecorationsegmentlength}{\matchinglength pt}
}] {}
\state{upsine}[width=\pgfdecorationsegmentlength,next state=downsine]{
\pgfpathsine{\pgfpoint{0.25\pgfdecorationsegmentlength}{0.5\pgfdecorationsegmentamplitude}}
\pgfpathcosine{\pgfpoint{0.25\pgfdecorationsegmentlength}{-0.5\pgfdecorationsegmentamplitude}}
}
\state{downsine}[width=\pgfdecorationsegmentlength,next state=upsine]{
\pgfpathsine{\pgfpoint{0.25\pgfdecorationsegmentlength}{-0.5\pgfdecorationsegmentamplitude}}
\pgfpathcosine{\pgfpoint{0.25\pgfdecorationsegmentlength}{0.5\pgfdecorationsegmentamplitude}}
}
\state{final}{}
}
\begin{tikzpicture}[
every path/.style={
decoration={
complete sines,
segment length=1cm,
amplitude=1cm
},
decorate,
thick
}]
\draw (0,0) -- (2,0);
\draw [yshift=-1.2cm] (0,0) -- (2.5,0);
\draw [yshift=-2.4cm] (0,0) -- (3,0);
\draw [yshift=-3.6cm] (0,0) -- (3.5,0);
\end{tikzpicture}
\end{document}
Edit 2: Adapted code using \makeatletter
and \makeatother
to avoid the bad practice of midifying a package's file.
Edit: Changed code to make the coils end at the middle of the line.
If I understand correctly, you can get the result you are looking for by changing the predefined coil
decoration. Although, the solution I propose is not prefect. The problem is that you need to change the segment length
value a little bit to avoid too much (or too little) space at the end of the coil. Here are some examples, the blue coils correspond to the modified decoration:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\makeatletter
% gluon decoration (based on the original coil decoration)
\pgfdeclaredecoration{gluon}{coil}
{
\state{coil}[switch if less than=%
0.5\pgfdecorationsegmentlength+%>
\pgfdecorationsegmentaspect\pgfdecorationsegmentamplitude+%
\pgfdecorationsegmentaspect\pgfdecorationsegmentamplitude to last,
width=+\pgfdecorationsegmentlength]
{
\pgfpathcurveto
{\pgfpoint@oncoil{0 }{ 0.555}{1}}
{\pgfpoint@oncoil{0.445}{ 1 }{2}}
{\pgfpoint@oncoil{1 }{ 1 }{3}}
\pgfpathcurveto
{\pgfpoint@oncoil{1.555}{ 1 }{4}}
{\pgfpoint@oncoil{2 }{ 0.555}{5}}
{\pgfpoint@oncoil{2 }{ 0 }{6}}
\pgfpathcurveto
{\pgfpoint@oncoil{2 }{-0.555}{7}}
{\pgfpoint@oncoil{1.555}{-1 }{8}}
{\pgfpoint@oncoil{1 }{-1 }{9}}
\pgfpathcurveto
{\pgfpoint@oncoil{0.445}{-1 }{10}}
{\pgfpoint@oncoil{0 }{-0.555}{11}}
{\pgfpoint@oncoil{0 }{ 0 }{12}}
}
\state{last}[next state=final]
{
\pgfpathcurveto
{\pgfpoint@oncoil{0 }{ 0.555}{1}}
{\pgfpoint@oncoil{0.445}{ 1 }{2}}
{\pgfpoint@oncoil{1 }{ 1 }{3}}
\pgfpathcurveto
{\pgfpoint@oncoil{1.555}{ 1 }{4}}
{\pgfpoint@oncoil{2 }{ 0.555}{5}}
{\pgfpoint@oncoil{2 }{ 0 }{6}}
}
\state{final}{}
}
\def\pgfpoint@oncoil#1#2#3{%
\pgf@x=#1\pgfdecorationsegmentamplitude%
\pgf@x=\pgfdecorationsegmentaspect\pgf@x%
\pgf@y=#2\pgfdecorationsegmentamplitude%
\pgf@xa=0.083333333333\pgfdecorationsegmentlength%
\advance\pgf@x by#3\pgf@xa%
}
\makeatother
\begin{document}
\begin{tikzpicture}
\node (a) at (0,0) {A};
\node (b) at (2,0) {B};
\path (a) edge[decorate,decoration={coil, amplitude=4pt,
segment length=5pt}] (b);
\end{tikzpicture}
\begin{tikzpicture}
\node (a) at (0,0) {A};
\node (b) at (2,0) {B};
\path (a) edge[color=blue,decorate,decoration={gluon, amplitude=4pt,
segment length=5.25pt}] (b);
\end{tikzpicture}
\begin{tikzpicture}
\node (a) at (0,0) {A};
\node (b) at (2,0) {B};
\path (a) edge[decorate,decoration={coil, amplitude=4pt,
segment length=5pt, aspect=0}] (b);
\end{tikzpicture}
\begin{tikzpicture}
\node (a) at (0,0) {A};
\node (b) at (2,0) {B};
\path (a) edge[color=blue,decorate,decoration={gluon, amplitude=4pt,
segment length=5.2pt, aspect=0}] (b);
\end{tikzpicture}
\begin{tikzpicture}
\node (a) at (0,0) {A};
\node (b) at (3.5,0) {B};
\path (a) edge[decorate,decoration={coil, amplitude=4pt,
segment length=5pt}] (b);
\end{tikzpicture}
\begin{tikzpicture}
\node (a) at (0,0) {A};
\node (b) at (3.5,0) {B};
\path (a) edge[color=blue,decorate,decoration={gluon, amplitude=4pt,
segment length=5.25pt}] (b);
\end{tikzpicture}
\begin{tikzpicture}
\node (a) at (0,0) {A};
\node (b) at (3.5,0) {B};
\path (a) edge[decorate,decoration={coil, amplitude=4pt,
segment length=5pt, aspect=0}] (b);
\end{tikzpicture}
\begin{tikzpicture}
\node (a) at (0,0) {A};
\node (b) at (3.5,0) {B};
\path (a) edge[color=blue,decorate,decoration={gluon, amplitude=4pt,
segment length=4.9pt, aspect=0}] (b);
\end{tikzpicture}
\end{document}
Best Answer
Here's an extended version of the
complete sines
decoration, which can now be controlled usingstart up
/start down
andend up
/end down
.