# Perfect crossing of two dashed lines

I need to draw to dashed line which cross at the center of a circle using the tikz package. I would like to obtain a pefect cross at the center of the circle so I wonder if there is a method to force the dashed lines to intersect at the center forming a peferct cross.

\documentclass[tikz]{standalone}% 'crop' is the default
\begin{document}
\begin{tikzpicture}
\draw [dashed, line width=1.5pt] (0,5) -- (10,5);
\draw [dashed, line width=1.5pt] (5,0) -- (5,10);

\coordinate (c) at (5,5);   % center of circle
\def\nbpts{36}                   % nb of points
\colorlet{point color}{red}      % color of points
\end{tikzpicture}
\end{document} To get a cross in the middle, we need to dial an appropriate dash pattern. We want to achieve that there are 2n+1 dashes and 2n gaps. Call the ratio between gap and dash lengths r. Then the length a of the dash has to fulfill

2n r a + (2n+1) a = l ,


where l is the length of the path. So

a = l/(2n r + 2n +1)  .


In your example, l is 10cm (but we could let TikZ measure the with a decoration using \pgfdecoratedpathlength, if needed). Here is an example for n=15 and r=0.8, which you can adjust.

\documentclass[tikz]{standalone}% 'crop' is the default
\begin{document}
\begin{tikzpicture}
\pgfmathsetmacro{\myr}{0.8}
\pgfmathsetmacro{\myn}{15}
\pgfmathsetmacro{\myl}{10cm}
\pgfmathsetmacro{\myon}{\myl/(2*\myn*\myr+2*\myn+1)}
\pgfmathsetmacro{\myoff}{\myr*\myon}
\typeout{\myon,\myoff}
\draw [line width=1.5pt,dash pattern=on \myon pt off \myoff pt] (0,5) -- (10,5);
\draw [line width=1.5pt,dash pattern=on \myon pt off \myoff pt] (5,0) -- (5,10);

\coordinate (c) at (5,5);   % center of circle
\def\nbpts{36}                   % nb of points
\colorlet{point color}{red}      % color of points
\end{tikzpicture}
\end{document} You can define some sort of complete dashes, which are conceptually similar to Jake's complete sines. Then you can say something like

\draw [line width=1.5pt,complete dashes={a=6mm}] (0,5) -- (10,5);


where a is the target dash length. In addition, you can specify the above-mentioned ratio r. Note, however, that if you use this on paths of different lengths, the dash length will only coincide precisely in rare cases,but it will look pretty much the same as long there are many dashes.

\documentclass[tikz]{standalone}% 'crop' is the default
\usetikzlibrary{decorations.markings}
% earlier posts this post is conceptually similar to include
% https://tex.stackexchange.com/a/214448
% https://tex.stackexchange.com/a/25689
\makeatletter
\tikzset{%
complete dashes/.style={/tikz/bob/settings={#1},
decoration={
markings,
mark=at position 1 with {%
\pgfmathtruncatemacro{\myn}{0.5+2*(\pgfdecoratedpathlength-\pgfkeysvalueof{/tikz/bob/a})/
(2*\pgfkeysvalueof{/tikz/bob/a}*(1+\pgfkeysvalueof{/tikz/bob/r}))}%
\pgfmathsetmacro{\myon}{\pgfdecoratedpathlength/(2*\myn*\pgfkeysvalueof{/tikz/bob/r}+2*\myn+1)}%
\pgfmathsetmacro{\myoff}{\pgfkeysvalueof{/tikz/bob/r}*\myon}%
\global\pgfutil@tempdima=\myon pt%
\global\pgfutil@tempdimb=\myoff pt%
%\typeout{\myon,\myoff}
},
},
preaction=decorate,
draw,dash pattern=on \pgfutil@tempdima off \pgfutil@tempdimb,
},bob/.cd,settings/.code={\tikzset{bob/.cd,#1}},
a/.initial=3mm,r/.initial=0.8
}
\makeatother
\begin{document}
\begin{tikzpicture}
\draw [line width=1.5pt,complete dashes={a=6mm}] (0,5) -- (10,5);
\draw [line width=1.5pt,complete dashes={a=6mm}] (5,1) -- (5,9);

\coordinate (c) at (5,5);   % center of circle
\def\nbpts{36}                   % nb of points
\colorlet{point color}{red}      % color of points 