我想在二维空间中使用乳胶绘制圆锥形弹簧。
我使用以下命令在两个节点 a 和 b 之间绘制一个圆柱弹簧:
\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{decorations.pathmorphing,patterns}
\begin{document}
\begin{tikzpicture}
\node[circle,fill=blue,inner sep=2.5mm] (a) at (0,1.5) {};
\draw[decoration={aspect=0.3, segment length=1.5mm, amplitude=3mm,zigzag},decorate] (0,4) -- (a);
\draw[decoration={aspect=0.3, segment length=2mm, amplitude=3mm,zigzag},decorate] (0,-4) -- (a);
\draw[decoration={aspect=0.3, segment length=1.8mm, amplitude=3mm,zigzag},decorate] (4,0) -- (a);
\draw[decoration={aspect=0.3, segment length=1.8mm, amplitude=3mm,zigzag},decorate] (-4,0) -- (a);
\fill [pattern = north east lines] (-1,4) rectangle (1,4.3);
\draw[thick] (-1,4) -- (1,4);
\end{tikzpicture}
\end{document}
但我无法使用曲折选项来绘制具有各种直径的圆锥形弹簧。
有谁能够帮助我?
提前致谢。
答案1
这是一个快速编写的代码,而不是装饰(通常意义上),因此这仅适用于直线。它允许您绘制不同幅度的锯齿形。在此实现中,您可以指定锯齿形的数量,而不是线段长度。
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{calc,decorations.pathreplacing}
\tikzset{
varying zigzag/.style={
decorate,decoration={show path construction,
lineto code={
\draw
(\tikzinputsegmentfirst)
foreach \XX in {1,...,\vzgigzagsteps}
{ --
($($(\tikzinputsegmentfirst)!{(2*\XX-1)/(2*\vzgigzagsteps+2)}!(\tikzinputsegmentlast)$)!
{(\pgfkeysvalueof{/tikz/vzigzag/left diameter}+(\pgfkeysvalueof{/tikz/vzigzag/right
diameter}-\pgfkeysvalueof{/tikz/vzigzag/left
diameter})*(2*\XX-1)/(2*\vzgigzagsteps))*0.5cm}!-90:(\tikzinputsegmentlast) $)
--
($($(\tikzinputsegmentfirst)!{(2*\XX)/(2*\vzgigzagsteps+2)}!(\tikzinputsegmentlast)$)!
{(\pgfkeysvalueof{/tikz/vzigzag/left diameter}+(\pgfkeysvalueof{/tikz/vzigzag/right
diameter}-\pgfkeysvalueof{/tikz/vzigzag/left
diameter})*(2*\XX)/(2*\vzgigzagsteps))*0.5cm}!90:(\tikzinputsegmentlast) $)
} -- (\tikzinputsegmentlast);
}}},
vzigzag/.cd,
left diameter/.initial=1,
right diameter/.initial=0,
steps/.store in=\vzgigzagsteps,
steps=10}
\begin{document}
\begin{tikzpicture}
\node[circle,fill=blue,inner sep=2.5mm] (a) at (0,1.5) {};
\draw[varying zigzag] (0,4) -- (a);
\draw[varying zigzag] (0,-4) -- (a);
\draw[varying zigzag] (4,0) -- (a);
\draw[varying zigzag] (-4,0) -- (a);
\begin{scope}[,xshift=9cm,vzigzag/left diameter=0,vzigzag/right diameter=1.5]
\node[circle,fill=blue,inner sep=2.5mm] (a) at (0,1.5) {};
\draw[varying zigzag] (0,4) -- (a);
\draw[varying zigzag] (0,-4) -- (a);
\draw[varying zigzag] (4,0) -- (a);
\draw[varying zigzag] (-4,0) -- (a);
\end{scope}
\end{tikzpicture}
\end{document}