1

I try to draw a smooth line/curve with evenly spaced dots on it:

The following code draws a line but without any dots.

\begin{tikzpicture}
dot/.style={draw,circle,fill,minimum size=0.6mm,inner sep=0pt},
pins/.style={#1, pin edge={<-, #1, decorate, decoration={name=lineto, pre=moveto, pre length=2pt}}},

\draw coordinate [dot, pin={[pins]-90:P1}] (p1);
\coordinate [pin={[pins=green]100:TheLine}] (ppp) at ($(p1) + (1.4,0.3)$);
    \draw[smooth, color=green, thick] plot [dot] coordinates {(p1) 
                    ($(p1) + (0.2,0.0)$) 
                    ($(p1) + (0.4,0.05)$) 
                    ($(p1) + (0.6,0.1)$)
                    ($(p1) + (0.8,0.15)$)
                    ($(p1) + (1.0,0.2)$)
                    ($(p1) + (1.2,0.25)$)
                    (ppp)
                    ($(p1) + (1.6,0.35)$)
                    ($(p1) + (1.8,0.4)$)
                    ($(p1) + (2.0,0.45)$)
                    ($(p1) + (2.2,0.5)$)
                    ($(p1) + (2.4,0.5)$)
                    ($(p1) + (2.6,0.5)$)
                    ($(p1) + (2.8,0.5)$)
                    ($(p1) + (3.0,0.5)$)
                    ($(p1) + (3.2,0.5)$)
                };
\end{tikzpicture}

Note that I don't necessarily need all the coordinates. Just some evenly spaced dots along a smooth line including a pin in the middle.

My first attempt was to use the following and use something like dotted. However, this gives me no control of the spacing between the dots.

\begin{tikzpicture}
    \draw coordinate [dot, pin={[pins]-90:P1}] (p1);
    \draw[green, thick] (p1) to[out=0,in=-160] ($ (p1) +
    (1.6,0.25) $) coordinate [pin={[pins=green]100:TheLine}] (pm) 
    to[out=20,in=-180] ($ (p1) + (3.2,0.5) $);
\end{tikzpicture}

Could you please help me to find a smooth line/curve with evenly spaced dots on it

  • please include the preamble in your code starting with documentclass and finishing at enddocument – js bibra Feb 4 at 16:06
  • and please make your MWE compilable (you have error in \pin definitions). – Zarko Feb 4 at 16:20
5

You can add a dotted line with postaction. I use these beautiful dots. The spacing is controlled by the dash pattern

dash pattern=on 0.1\pgflinewidth off #1\pgflinewidth

and forwarded to the Dotted style as parameter.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{calc,decorations}
\begin{document}
\begin{tikzpicture}[dot/.style={draw,circle,fill,minimum size=0.6mm,inner sep=0pt},
    pins/.style={#1, pin edge={<-, #1, decorate, decoration={name=lineto,
    pre=moveto, pre length=2pt}}},
    Dotted/.style={% https://tex.stackexchange.com/a/52856/194703
    dash pattern=on 0.1\pgflinewidth off #1\pgflinewidth,line cap=round,
    shorten >=#1\pgflinewidth/2,shorten <=#1\pgflinewidth/2},
    Dotted/.default=4]

\draw coordinate [dot, pin={[pins]-90:P1}] (p1);
\coordinate [pin={[pins=green]100:TheLine}] (ppp) at ($(p1) + (1.4,0.3)$);
    \draw[smooth, color=green, thick,postaction={draw,black,ultra thick,Dotted}] plot [dot] coordinates {(p1) 
                    ($(p1) + (0.2,0.0)$) 
                    ($(p1) + (0.4,0.05)$) 
                    ($(p1) + (0.6,0.1)$)
                    ($(p1) + (0.8,0.15)$)
                    ($(p1) + (1.0,0.2)$)
                    ($(p1) + (1.2,0.25)$)
                    (ppp)
                    ($(p1) + (1.6,0.35)$)
                    ($(p1) + (1.8,0.4)$)
                    ($(p1) + (2.0,0.45)$)
                    ($(p1) + (2.2,0.5)$)
                    ($(p1) + (2.4,0.5)$)
                    ($(p1) + (2.6,0.5)$)
                    ($(p1) + (2.8,0.5)$)
                    ($(p1) + (3.0,0.5)$)
                    ($(p1) + (3.2,0.5)$)
                };
\end{tikzpicture}
\end{document}

enter image description here

Using e.g. Dotted=7 yields

enter image description here

| improve this answer | |

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.