I'm not sure of my formula but (path length - shape sep)/2
is not very fine. You can use some values like
\pgfmetadecoratedpathlength
and \pgf@lib@shapedecoration@sep
.
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.shapes}
\begin{document}
\makeatletter
\begin{tikzpicture}%
[foo/.style={decorate,
decoration={shape backgrounds,
shape=circle,
shape sep=2.5cm,
pre=moveto,
pre length=(\pgfmetadecoratedpathlength-%
floor(\pgfmetadecoratedpathlength/\pgf@lib@shapedecoration@sep)*%
\pgf@lib@shapedecoration@sep)/2}}]
\node at (0cm,0cm) [label=below:0] {};
\node at (5cm,0cm) [label=below:5] {};
\node at (9cm,0cm) [label=below:9] {};
\node at (10cm,0cm) [label=below:10] {};
\draw[foo] (0cm,1cm) -- ( 9cm,1cm);
\end{tikzpicture}
\end{document}
Here's a different approach that does not use a decoration, but rather a to
path together with a plot
statement that connects two points using a semicircle with a superimposed sine wave.
The number of complete periods to be drawn is specified using the key wave count
. Another half period is added to this number so that the wave starts and ends on the outside (I think this looks better than starting on the inside or asymmetrically).
The amplitude of the wave is set using wave amplitude
, and the semicircle can be flipped to the opposite side of the path using mirror semicircle=true
.
This approach could reasonably easily be adapted to allow for circle sectors different from 180° (I don't know if that's ever needed in Feynman diagrams, though).
\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,calc}
\newif\ifmirrorsemicircle
\tikzset{
wave amplitude/.initial=0.2cm,
wave count/.initial=8,
mirror semicircle/.is if=mirrorsemicircle,
mirror semicircle=false,
wavy semicircle/.style={
to path={
let \p1 = (\tikztostart),
\p2 = (\tikztotarget),
\n1 = {veclen(\y2-\y1,\x2-\x1)},
\n2 = {atan2(\y2-\y1,\x2-\x1))} in
plot [
smooth,
samples=(\pgfkeysvalueof{/tikz/wave count}+0.5)*8+1, % Calculate the number of samples needed, so the samples are in sync with the wave and fall on the extrema
domain=0:1,
shift={($(\p1)!0.5!(\p2)$)}
] ({ % Polar coordinates: Angle...
(\x*180-\n2 + 180 + \ifmirrorsemicircle 1 \else -1 \fi * 90%
}:{ % ... and radius
(%
\n1/2+\pgfkeysvalueof{/tikz/wave amplitude} * %
sin(
\x * 360 * (\pgfkeysvalueof{/tikz/wave count} + 0.5%
)%
)%
})
} (\tikztotarget)
}
}
\begin{document}
\begin{tikzpicture}[thick,scale=.6]
\draw [blue] (-4,0) -- (-2,0) -- (2,-1) -- (4,-2);
\draw [red] (-2,0) to [wavy semicircle] (2,-1)
to [
wavy semicircle,
wave amplitude=0.1cm,
wave count=15,
mirror semicircle
] (4,-2);
\end{tikzpicture}
\end{document}
Best Answer
(this is the first time I add another answer --- if it's not the correct thing to do, please tell me; but this is so different from my first one that... should I mark it community wiki?)
You can use a
transform
on a decoration, thanks to the fact that the coordinate system in a decoration is along the path; that will shift the node after the end of the path by a distance specified as the second argument:This makes the node centered at a fixed distance from the end of the path, along the path. It doesn't change the node anchors, unfortunately... and
auto
is not working here.Thanks to: Length of curve in TikZ, Torbjørn T.'s answer, \tikzset key with multiple arguments.