我正在尝试绘制一个虚线圆。但是,我创建的圆不对称,因此,在相对于中心的不同对称位置,虚线元素不对应。我希望在 0 度和 180 度(以及 90 度和 270 度)的位置有一个完美居中的元素(或空间)。这是我使用的代码
\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}
答案1
您可以绘制多个圆弧来模拟它,而不是绘制一个dashed
图案。这样您就可以控制每个片段的起始和终止角度。
\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}
答案2
Ignasi 的例子回答修改如下:
- 黑线连接正确
- 黑线的起点和终点与红线的水平位置相同。
示例代码:
\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}