6

I'm trying to draw a dashed circle. However, the one I created is not symmetric so that, at different symmetric positions with respect to the center, the dashed elements do not correspond. I would like to have a perfectly centered element (or space) at the positions 0 and 180 degrees (and also 90 and 270). Here the code I'm using

\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}
\draw [ultra thick, blue, dash pattern=on 0.39793506944cm off 0.09948376736cm]circle(2.85cm);

\def\centerarc[#1](#2)(#3:#4:#5)% Syntax: [draw options] (center) (initial angle:final angle:radius)
    { \draw[#1] ($(#2)+({#5*cos(#3)},{#5*sin(#3)})$) arc (#3:#4:#5); }
    
\centerarc[black,ultra thick](0,0)(20:160:3)
\centerarc[black,ultra thick](0,0)(200:340:3)

\draw[black, ultra thick] (-2.80,1.02606042998)  -- (-4.178,1.02606042998);
\draw[black, ultra thick] (-2.81907786236,-1.02606042998) -- (-4.178,-1.02606042998);

\draw[black,ultra thick] (2.81907786236,1.02606042998)  -- (4.178,1.02606042998);
\draw[black,ultra thick] (2.81907786236,-1.02606042998) -- (4.178,-1.02606042998);

\def\centerarc[#1](#2)(#3:#4:#5)% Syntax: [draw options] (center) (initial angle:final angle:radius)
    { \draw[#1] ($(#2)+({#5*cos(#3)},{#5*sin(#3)})$) arc (#3:#4:#5); }
    

\end{tikzpicture}
\end{document}

enter image description here

2 Answers 2

9

Instead of a dashed pattern you can draw multiple arcs to simulate it. This way you can control start and ending angles of every fragment.

\documentclass[tikz,border=3mm]{standalone}

\begin{document}

\begin{tikzpicture}

\foreach \i [evaluate=\i as \start using (\i-1)*5] in {1,2,...,72}
    \draw[blue, ultra thick] (\start+.5:2.85cm) arc[start angle=\start+.5, delta angle=4, radius=2.85cm];
    
\draw[ultra thick] (20:3) arc[start angle=20, end angle=160, radius=3cm];
\draw[ultra thick] (200:3) arc[start angle=200, end angle=340, radius=3cm];
\draw[ultra thick] (20:3)--++(0:3cm);
\draw[ultra thick] (160:3)--++(180:3cm);
\draw[ultra thick] (200:3)--++(180:3cm);
\draw[ultra thick] (340:3)--++(0:3cm);

\draw[red] (-90:4)--(90:4) (0:4)--(180:4);

\end{tikzpicture}

\end{document}

enter image description here

1
  • Simple and effective idea Ignasi, Thank you a lot.
    – Fly
    Mar 8, 2021 at 10:31
3

The example from Ignasi's answer with the following changes:

  • The black lines are properly connected
  • The black lines start and ends at the same horizontal position as the red lines.

Example code:

\documentclass[tikz,border=3mm]{standalone}

\begin{document}

\begin{tikzpicture}

\draw[blue, ultra thick]
  \foreach \i [evaluate=\i as \start using (\i-1)*5] in {1,2,...,72} {
     (\start+.5:2.85cm) arc[start angle=\start+.5, delta angle=4, radius=2.85cm]
};

\draw[ultra thick]
  (20:3) coordinate (tmp) (4, 0 |- tmp) -- (tmp)
  arc[start angle=20, end angle=160, radius=3cm] to (-4, 0 |- \tikztostart)
  (200:3) coordinate (tmp) (-4, 0 |- tmp) -- (tmp)
  arc[start angle=200, end angle=340, radius=3cm] to (4, 0 |- \tikztostart)
;

\draw[red] (-90:4)--(90:4) (0:4)--(180:4);

\end{tikzpicture}

\end{document}

enter image description here

3
  • Thank you a lot Heiko, it's much better now!
    – Fly
    Mar 14, 2021 at 12:37
  • Thank you for your correction. It's much better now. Just a question. Is there any reason for using to (-4, 0 |- \tikztostart) instead of -- (-4, 0 |- tmp)?
    – Ignasi
    Mar 14, 2021 at 17:34
  • @Ignasi This would also work. Mar 14, 2021 at 17:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.