【TikZ】バネのかき方

ライブラリが必要です。

`\usetikzlibrary{decorations.markings,decorations.pathmorphing}`

```tex
\begin{document}
 \begin{tikzpicture}
 \draw[decorate,decoration={coil}] (0,3) -- (0,-3);
 \end{tikzpicture}
\end{document}
```

<img src="https://texclip.marutank.net/render.php/texclip20230706223618.svg?s=%5Cusetikzlibrary%7Bdecorations.markings%2Cdecorations.pathmorphing%7D%0A%5Cbegin%7Btikzpicture%7D%0A%20%5Cdraw%5Bdecorate%2Cdecoration%3D%7Bcoil%7D%5D%20(0%2C3)%20--%20(0%2C-3)%3B%0A%5Cend%7Btikzpicture%7D&f=c&r=300&m=s&b=f&k=f">

`coil`にオプションをつけることができます。`amplitude`, `segment length`, `aspect`



## amplitudeの違い

```tex
 \begin{tikzpicture}
 \draw[decorate,decoration={coil,amplitude=2cm}] (-3,3) -- (-3,-3);
 \draw[decorate,decoration={coil,amplitude=3.5cm}] (0,3) -- (0,-3);
 \draw[decorate,decoration={coil,amplitude=5cm}] (3,3) -- (3,-3);
 \end{tikzpicture}
```

![](https://www.evernote.com/shard/s225/sh/ed500908-0978-c41f-e9ea-7b2ae84a6c13/kOSyBmyzEVwC79W3GMvRtEfEcvJJYPRbmJjWXJMoSbcEsP9rm5nr2ashNw/res/3673e0ed-a94c-91d8-9399-1fb38f62a682)


# segment lengthの違い

```tex
 \begin{tikzpicture}
 \draw[decorate,decoration={coil,segment length=5}] (-3,3) -- (-3,-3);
 \draw[decorate,decoration={coil,segment length=10}] (0,3) -- (0,-3);
 \draw[decorate,decoration={coil,segment length=15}] (3,3) -- (3,-3);
 \end{tikzpicture}
```


![](https://www.evernote.com/shard/s225/sh/ed500908-0978-c41f-e9ea-7b2ae84a6c13/kOSyBmyzEVwC79W3GMvRtEfEcvJJYPRbmJjWXJMoSbcEsP9rm5nr2ashNw/res/b3caf1b6-1f65-dc56-983f-15426b6c2b2b)



# aspectの違い

```tex
 \begin{tikzpicture}
 \draw[decorate,decoration={coil,aspect=0.4}] (-3,3) -- (-3,-3);
 \draw[decorate,decoration={coil,aspect=0.7}] (0,3) -- (0,-3);
 \draw[decorate,decoration={coil,aspect=1}] (3,3) -- (3,-3);
 \draw[decorate,decoration={coil,aspect=2}] (6,3) -- (6,-3);
 \end{tikzpicture}
```

<img src="https://texclip.marutank.net/render.php/texclip20230706224235.svg?s=%5Cusetikzlibrary%7Bdecorations.markings%2Cdecorations.pathmorphing%7D%0A%5Cbegin%7Btikzpicture%7D%0A%20%5Cdraw%5Bdecorate%2Cdecoration%3D%7Bcoil%2Caspect%3D0.4%7D%5D%20(-3%2C3)%20--%20(-3%2C-3)%3B%0A%20%5Cdraw%5Bdecorate%2Cdecoration%3D%7Bcoil%2Caspect%3D0.7%7D%5D%20(0%2C3)%20--%20(0%2C-3)%3B%0A%20%5Cdraw%5Bdecorate%2Cdecoration%3D%7Bcoil%2Caspect%3D1%7D%5D%20(3%2C3)%20--%20(3%2C-3)%3B%0A%20%5Cdraw%5Bdecorate%2Cdecoration%3D%7Bcoil%2Caspect%3D2%7D%5D%20(6%2C3)%20--%20(6%2C-3)%3B%0A%0A%20%5Cnode%5Bbelow%5D%20at%20(-3%2C-3)%20%7B0.4%7D%3B%0A%20%5Cnode%5Bbelow%5D%20at%20(0%2C-3)%20%7B0.7%7D%3B%0A%20%5Cnode%5Bbelow%5D%20at%20(3%2C-3)%20%7B1%7D%3B%0A%20%5Cnode%5Bbelow%5D%20at%20(6%2C-3)%20%7B2%7D%3B%0A%0A%5Cend%7Btikzpicture%7D&f=c&r=300&m=s&b=f&k=f">






TeXclipソースコード

<img src="https://texclip.marutank.net/render.php/texclip20230706223618.svg?s=%5Cusetikzlibrary%7Bdecorations.markings%2Cdecorations.pathmorphing%7D%0A%5Cbegin%7Btikzpicture%7D%0A%20%5Cdraw%5Bdecorate%2Cdecoration%3D%7Bcoil%7D%5D%20(0%2C3)%20--%20(0%2C-3)%3B%0A%5Cend%7Btikzpicture%7D&f=c&r=300&m=s&b=f&k=f">

https://texclip.marutank.net/#s=%5Cusetikzlibrary%7Bdecorations.markings%2Cdecorations.pathmorphing%7D%0A%5Cbegin%7Btikzpicture%7D%0A%20%5Cdraw%5Bdecorate%2Cdecoration%3D%7Bcoil%7D%5D%20(0%2C3)%20--%20(0%2C-3)%3B%0A%5Cend%7Btikzpicture%7D



![](https://www.evernote.com/shard/s225/sh/ed500908-0978-c41f-e9ea-7b2ae84a6c13/kOSyBmyzEVwC79W3GMvRtEfEcvJJYPRbmJjWXJMoSbcEsP9rm5nr2ashNw/res/3673e0ed-a94c-91d8-9399-1fb38f62a682)


https://texclip.marutank.net/#s=%5Cusetikzlibrary%7Bdecorations.markings%2Cdecorations.pathmorphing%7D%0A%5Cbegin%7Bdocument%7D%0A%20%5Cbegin%7Btikzpicture%7D%0A%20%5Cdraw%5Bdecorate%2Cdecoration%3D%7Bcoil%2Camplitude%3D0.5cm%7D%5D%20(-3%2C3)%20--%20(-3%2C-3)%3B%0A%20%5Cdraw%5Bdecorate%2Cdecoration%3D%7Bcoil%2Camplitude%3D1cm%7D%5D%20(0%2C3)%20--%20(0%2C-3)%3B%0A%20%5Cdraw%5Bdecorate%2Cdecoration%3D%7Bcoil%2Camplitude%3D1.5cm%7D%5D%20(3%2C3)%20--%20(3%2C-3)%3B%0A%0A%20%5Cnode%5Bbelow%5D%20at%20(-3%2C-3)%20%7B0.5cm%7D%3B%0A%20%5Cnode%5Bbelow%5D%20at%20(0%2C-3)%20%7B1cm%7D%3B%0A%20%5Cnode%5Bbelow%5D%20at%20(3%2C-3)%20%7B1.5cm%7D%3B%0A%0A%20%5Cend%7Btikzpicture%7D%0A%5Cend%7Bdocument%7D



![](https://www.evernote.com/shard/s225/sh/ed500908-0978-c41f-e9ea-7b2ae84a6c13/kOSyBmyzEVwC79W3GMvRtEfEcvJJYPRbmJjWXJMoSbcEsP9rm5nr2ashNw/res/b3caf1b6-1f65-dc56-983f-15426b6c2b2b)

https://texclip.marutank.net/#s=%5Cusetikzlibrary%7Bdecorations.markings%2Cdecorations.pathmorphing%7D%0A%5Cbegin%7Btikzpicture%7D%0A%20%5Cdraw%5Bdecorate%2Cdecoration%3D%7Bcoil%2Csegment%20length%3D5%7D%5D%20(-3%2C3)%20--%20(-3%2C-3)%3B%0A%20%5Cdraw%5Bdecorate%2Cdecoration%3D%7Bcoil%2Csegment%20length%3D10%7D%5D%20(0%2C3)%20--%20(0%2C-3)%3B%0A%20%5Cdraw%5Bdecorate%2Cdecoration%3D%7Bcoil%2Csegment%20length%3D15%7D%5D%20(3%2C3)%20--%20(3%2C-3)%3B%0A%0A%20%5Cnode%5Bbelow%5D%20at%20(-3%2C-3)%20%7B5%7D%3B%0A%20%5Cnode%5Bbelow%5D%20at%20(0%2C-3)%20%7B10%7D%3B%0A%20%5Cnode%5Bbelow%5D%20at%20(3%2C-3)%20%7B15%7D%3B%0A%0A%5Cend%7Btikzpicture%7D







<img src="https://texclip.marutank.net/render.php/texclip20230706224235.svg?s=%5Cusetikzlibrary%7Bdecorations.markings%2Cdecorations.pathmorphing%7D%0A%5Cbegin%7Btikzpicture%7D%0A%20%5Cdraw%5Bdecorate%2Cdecoration%3D%7Bcoil%2Caspect%3D0.4%7D%5D%20(-3%2C3)%20--%20(-3%2C-3)%3B%0A%20%5Cdraw%5Bdecorate%2Cdecoration%3D%7Bcoil%2Caspect%3D0.7%7D%5D%20(0%2C3)%20--%20(0%2C-3)%3B%0A%20%5Cdraw%5Bdecorate%2Cdecoration%3D%7Bcoil%2Caspect%3D1%7D%5D%20(3%2C3)%20--%20(3%2C-3)%3B%0A%20%5Cdraw%5Bdecorate%2Cdecoration%3D%7Bcoil%2Caspect%3D2%7D%5D%20(6%2C3)%20--%20(6%2C-3)%3B%0A%0A%20%5Cnode%5Bbelow%5D%20at%20(-3%2C-3)%20%7B0.4%7D%3B%0A%20%5Cnode%5Bbelow%5D%20at%20(0%2C-3)%20%7B0.7%7D%3B%0A%20%5Cnode%5Bbelow%5D%20at%20(3%2C-3)%20%7B1%7D%3B%0A%20%5Cnode%5Bbelow%5D%20at%20(6%2C-3)%20%7B2%7D%3B%0A%0A%5Cend%7Btikzpicture%7D&f=c&r=300&m=s&b=f&k=f">


https://texclip.marutank.net/#s=%5Cusetikzlibrary%7Bdecorations.markings%2Cdecorations.pathmorphing%7D%0A%5Cbegin%7Btikzpicture%7D%0A%20%5Cdraw%5Bdecorate%2Cdecoration%3D%7Bcoil%2Caspect%3D0.4%7D%5D%20(-3%2C3)%20--%20(-3%2C-3)%3B%0A%20%5Cdraw%5Bdecorate%2Cdecoration%3D%7Bcoil%2Caspect%3D0.7%7D%5D%20(0%2C3)%20--%20(0%2C-3)%3B%0A%20%5Cdraw%5Bdecorate%2Cdecoration%3D%7Bcoil%2Caspect%3D1%7D%5D%20(3%2C3)%20--%20(3%2C-3)%3B%0A%20%5Cdraw%5Bdecorate%2Cdecoration%3D%7Bcoil%2Caspect%3D2%7D%5D%20(6%2C3)%20--%20(6%2C-3)%3B%0A%0A%20%5Cnode%5Bbelow%5D%20at%20(-3%2C-3)%20%7B0.4%7D%3B%0A%20%5Cnode%5Bbelow%5D%20at%20(0%2C-3)%20%7B0.7%7D%3B%0A%20%5Cnode%5Bbelow%5D%20at%20(3%2C-3)%20%7B1%7D%3B%0A%20%5Cnode%5Bbelow%5D%20at%20(6%2C-3)%20%7B2%7D%3B%0A%0A%5Cend%7Btikzpicture%7D