0
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}

\begin{document}

\begin{tikzpicture}
\draw[step=1cm,gray,very thin] (0,0) grid (6,4);
\draw[decoration={aspect=0.2, segment length=1.5mm, amplitude=1mm,coil},decorate,ultra thick,domain=0:6,smooth] plot[id=sin] function{0.5*sin(2*x)+2};
\end{tikzpicture}

\end{document}
1
  • Decorations and smoothed paths don't play together well. Commented Aug 18, 2020 at 5:27

1 Answer 1

1

Decorations and smoothed paths don't play nicely. Instead, increase the number of samples.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,fpu}

\begin{document}

\begin{tikzpicture}
\draw[step=1cm,gray,very thin] (0,0) grid (6,4);
\draw[
    decoration={
        aspect=0.2,
        segment length=1.5mm,
        amplitude=1mm,
        coil,
    },
    decorate,
    ultra thick,
    domain=0:6,
    samples=55,
    %smooth
] plot[id=sin] function{0.5*sin(2*x)+2};
\end{tikzpicture}

\end{document}

enter image description here

Or even better, use the sin and cos path construction operators (here I drew only one period). This is much faster because there are a lot fewer low-level operations involved and the accuracy is much higher.

\documentclass{article}
\pagestyle{empty}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,fpu}

\begin{document}

\begin{tikzpicture}
\draw[step=1cm,gray,very thin] (0,0) grid (6,4);
\draw[
    decoration={
        aspect=0.2,
        segment length=1.5mm,
        amplitude=1mm,
        coil,
    },
    decorate,
    ultra thick,
] (0,2) sin (1*pi/4,2.5)
        cos (2*pi/4,2.0)
        sin (3*pi/4,1.5)
        cos (4*pi/4,2.0);
\end{tikzpicture}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .