绘制带圆圈点且自动留空的虚线

绘制带圆圈点且自动留空的虚线

我正在尝试创建虚线其中每个点都有定义的大小并且周围有一个圆圈,该圆圈也有定义的大小。

首先我申请这个答案创建虚线图案:

\tikzset{
    dot diameter/.store in=\dot@diameter,
    dot diameter=3pt,
    dot spacing/.store in=\dot@spacing,
    dot spacing=10pt,
    dots/.style={
        line width=\dot@diameter,
        line cap=round,
        dash pattern=on 0pt off \dot@spacing
    }
}

然后我把这些虚线画出来黑色 - 白色 - 黑色相互叠加以达到预期的效果。我如何更改 tikzset 以便一步获得此结果?

下一个问题是它需要一个定义的點距如果我知道线的端点之间的距离,那就没问题了,但我通常不知道,所以我手动调整间距。但我希望在开始和结束节点处有一个带圆圈的点,其余的点等距分布在中间。我怎样才能实现平等分配?是否可以定义,比如,正好 11 个点在那条线上,均匀分布?

谢谢你!


平均能量损失

\documentclass{article}
\usepackage{tikz}

\makeatletter
\tikzset{
    dot diameter/.store in=\dot@diameter,
    dot diameter=3pt,
    dot spacing/.store in=\dot@spacing,
    dot spacing=10pt,
    dots/.style={
        line width=\dot@diameter,
        line cap=round,
        dash pattern=on 0pt off \dot@spacing
    }
}
\makeatother

\begin{document}
    \begin{tikzpicture}

    \coordinate (A1) at (1,1);
    \coordinate (B1) at (5,1);
    \coordinate (A2) at (1,1.5);
    \coordinate (B2) at (5,1.5);

    % for reference frame
    \draw [black, thick]   (A1.center) -- (B1.center) -- (B2.center) -- (A2.center) -- (A1.center);

    % three dot layers #1
    \draw [black, dot diameter=3mm, dot spacing=3.8mm, dots]   (A1.center) -- (B1.center);
    \draw [white, dot diameter=2.5mm, dot spacing=3.8mm, dots]  (A1.center) -- (B1.center);
    \draw [black, dot diameter=1mm, dot spacing=3.8mm, dots]    (A1.center) -- (B1.center);

    % three dot layers #2
    \draw [black, dot diameter=3mm, dot spacing=4mm, dots]   (A2.center) -- (B2.center);
    \draw [white, dot diameter=2.5mm, dot spacing=4mm, dots]  (A2.center) -- (B2.center);
    \draw [black, dot diameter=1mm, dot spacing=4mm, dots]    (A2.center) -- (B2.center);


    \end{tikzpicture}
\end{document}

在此处输入图片描述

实线仅用于定位,点之间不应有连接。上方的虚线是手动调整以获得正确的间距。

答案1

该答案建议使用preactionand|orpostaction来定义一种样式,该样式在一条命令中绘制所有三个层,但不能解决两点之间均匀分布 11 个点的问题。

\documentclass{article}
\usepackage{tikz}

\makeatletter
\tikzset{
    dot diameter/.store in=\dot@diameter,
    dot diameter=3pt,
    dot spacing/.store in=\dot@spacing,
    dot spacing=10pt,
    dots/.style={
        line width=\dot@diameter,
        line cap=round,
        dash pattern=on 0pt off \dot@spacing
    },
     mydots/.style={
        dot spacing=3.8mm,
        preaction={draw=black,
                        dot diameter=3mm,
                        dots},
        draw = white,
        dot diameter=2.5mm,
        dots,
        postaction={draw=black,
                        dot diameter=1mm,
                        dots},
     }
}
\makeatother

\begin{document}
    \begin{tikzpicture}

    \draw [mydots]   (0,0) -- (4,0);

    \draw [mydots]   (0,1) .. controls (3,1) and (4,2).. (3,3);

    \end{tikzpicture}
\end{document}

在此处输入图片描述

更新:参数版本:\mydots={dot dimension}{distance}

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

\makeatletter
\tikzset{
    dot diameter/.store in=\dot@diameter,
    dot diameter=3pt,
    dot spacing/.store in=\dot@spacing,
    dot spacing=10pt,
    dots/.style={
        line width=#1,
        line cap=round,
        dash pattern=on 0pt off \dot@spacing
    },
     mydots/.style 2 args={
        dot spacing=#2,
        preaction={draw=black,
                        dots=#1},
        draw = white,
        dots=.8*#1,
        postaction={draw=black,
                        dots=.333*#1},
     }
}
\makeatother

\begin{document}
    \begin{tikzpicture}

    \draw [mydots={3mm}{3.8mm}]   (0,0) -- (4,0);

    \draw [mydots={2mm}{5mm}]   (0,1) .. controls (3,1) and (4,2).. (3,3);

    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容