如何绘制简单的弹簧质量系统?

如何绘制简单的弹簧质量系统?

有人能帮我用 LaTeX 画出这个弹簧质量系统吗?我试过在这里使用另一个弹簧质量系统代码,但不幸的是我无法按我想要的方式修改它。希望你们中有人比我更有经验。在此处输入图片描述

答案1

正如评论中所说,有无数的帖子绘制了这样的东西。其中许多都有一些独特的特点。这段代码与其他许多代码唯一不同的一点是它使用了patterns.meta

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{patterns.meta,decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}[>=stealth]
 \path[pattern={Lines[angle=45,distance={8pt/sqrt(2)}]}] (-2,5) edge ++(4,0)
  rectangle ++ (4,0.5);
 \draw[decorate,decoration={coil,segment length=5pt,aspect=0.7,amplitude=4pt,
    pre=lineto,pre length=5mm,post=lineto,post length=5mm},thick] (0,5) -- (0,1)
    node[below,draw,minimum size=1cm,fill=blue!20](m){$m$};
 \draw[blue] (m.center-|0,0) ++ (0,1) -- ++ (-2,0) 
    edge[<-,edge label'=$x$,shorten >=1pt] (m.center-|-2,0)
  (m.center-|0,0) ++ (0,-1) -- ++ (-2,0) 
    edge[<-,edge label=$-x$,shorten >=1pt] (m.center-|-2,0)
    (m.east) edge[dashed] (m.east-|2,0) 
     (m.east-|2,0) node[right] {Equilibrium};
\end{tikzpicture}
\end{document}

在此处输入图片描述

我还想补充一点,如果像你所说的那样,你很难修改现有代码以满足你的需求,那么在我看来,展示你尝试过的方法更有意义。然后你可以学习如何修改帖子以获得你需要的东西,从而能够创建你想要的任何东西,而不依赖于其他人的可用性。这在 Ti 中尤其容易Z 因为通常您只需要修改一些键/样式(当然还有坐标)。

答案2

如果您喜欢绘图...您可以TikZ使用它创建快速代码抹茶https://www.mathcha.io/editor

在此处输入图片描述

%% Compile and read me!
\documentclass[a4paper,12pt]{article}
\usepackage{tikz}

\begin{document}


% Gradient Info

\tikzset {_d1boahmbc/.code = {\pgfsetadditionalshadetransform{ \pgftransformshift{\pgfpoint{0 bp } { 0 bp }  }  \pgftransformrotate{0 }  \pgftransformscale{2 }  }}}
\pgfdeclarehorizontalshading{_0q4qqrb4y}{150bp}{rgb(0bp)=(0.65,0.81,0.87);
rgb(37.5bp)=(0.65,0.81,0.87);
rgb(62.5bp)=(0.14,0.33,0.54);
rgb(100bp)=(0.14,0.33,0.54)}
\tikzset{every picture/.style={line width=0.75pt}} %set default line width to 0.75pt        

\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
%uncomment if require: \path (0,667); %set diagram left start at 0, and has height of 667

%Shape: Spring [id:dp9040227812016859] 
\draw  [line width=1.5]  (237.28,61.08) .. controls (247.3,63.5) and (257.35,69.92) .. (257.45,82.92) .. controls (257.65,108.92) and (217.65,109.24) .. (217.61,103.24) .. controls (217.56,97.24) and (257.56,96.92) .. (257.76,122.92) .. controls (257.97,148.92) and (217.97,149.23) .. (217.92,143.23) .. controls (217.87,137.24) and (257.87,136.92) .. (258.08,162.92) .. controls (258.28,188.92) and (218.28,189.23) .. (218.24,183.23) .. controls (218.19,177.23) and (258.19,176.92) .. (258.39,202.92) .. controls (258.6,228.92) and (218.6,229.23) .. (218.55,223.23) .. controls (218.5,217.23) and (258.5,216.92) .. (258.71,242.92) .. controls (258.91,268.92) and (218.91,269.23) .. (218.86,263.23) .. controls (218.82,257.23) and (258.82,256.92) .. (259.02,282.92) .. controls (259.22,308.92) and (219.23,309.23) .. (219.18,303.23) .. controls (219.14,298.22) and (247.03,297.17) .. (256.35,312.11) ;
%Shape: Square [id:dp6396081153175814] 
\path  [shading=_0q4qqrb4y,_d1boahmbc] (227.5,313.5) -- (273,313.5) -- (273,359) -- (227.5,359) -- cycle ; % for fading 
 \draw  [color={rgb, 255:red, 0; green, 0; blue, 0 }  ,draw opacity=1 ] (227.5,313.5) -- (273,313.5) -- (273,359) -- (227.5,359) -- cycle ; % for border 

%Straight Lines [id:da3752568722922205] 
\draw    (167,61) -- (316.5,61) (177,57) -- (177,65)(187,57) -- (187,65)(197,57) -- (197,65)(207,57) -- (207,65)(217,57) -- (217,65)(227,57) -- (227,65)(237,57) -- (237,65)(247,57) -- (247,65)(257,57) -- (257,65)(267,57) -- (267,65)(277,57) -- (277,65)(287,57) -- (287,65)(297,57) -- (297,65)(307,57) -- (307,65) ;
%Straight Lines [id:da5553906400035267] 
\draw [color={rgb, 255:red, 74; green, 144; blue, 226 }  ,draw opacity=1 ] [dash pattern={on 0.84pt off 2.51pt}]  (397.5,334) -- (286,334) ;
%Straight Lines [id:da2550415269696811] 
\draw [color={rgb, 255:red, 74; green, 144; blue, 226 }  ,draw opacity=1 ]   (76.5,401) -- (200,401) ;
%Straight Lines [id:da48978661486538844] 
\draw [color={rgb, 255:red, 74; green, 144; blue, 226 }  ,draw opacity=1 ]   (76.5,262) -- (200,262) ;
%Straight Lines [id:da6237187057457076] 
\draw [color={rgb, 255:red, 74; green, 144; blue, 226 }  ,draw opacity=1 ]   (93.5,331) -- (93.02,267) ;
\draw [shift={(93,264)}, rotate = 449.57] [fill={rgb, 255:red, 74; green, 144; blue, 226 }  ,fill opacity=1 ][line width=0.08]  [draw opacity=0] (8.93,-4.29) -- (0,0) -- (8.93,4.29) -- cycle    ;
%Straight Lines [id:da5578569616892095] 
\draw [color={rgb, 255:red, 74; green, 144; blue, 226 }  ,draw opacity=1 ]   (93.5,343) -- (93.5,397) ;
\draw [shift={(93.5,400)}, rotate = 270] [fill={rgb, 255:red, 74; green, 144; blue, 226 }  ,fill opacity=1 ][line width=0.08]  [draw opacity=0] (8.93,-4.29) -- (0,0) -- (8.93,4.29) -- cycle    ;
%Straight Lines [id:da04727108644812783] 
\draw [color={rgb, 255:red, 74; green, 144; blue, 226 }  ,draw opacity=1 ] [dash pattern={on 0.84pt off 2.51pt}]  (212.5,335) -- (101,335) ;

% Text Node
\draw (243,328) node [anchor=north west][inner sep=0.75pt]    {\large $\textcolor[rgb]{1,1,1}{m}$};
% Text Node
\draw (406,323) node [anchor=north west][inner sep=0.75pt]  [color={rgb, 255:red, 74; green, 144; blue, 226 }  ,opacity=1 ] [align=left] {Equilibrium};
% Text Node
\draw (71,290.4) node [anchor=north west][inner sep=0.75pt]  [color={rgb, 255:red, 74; green, 144; blue, 226 }  ,opacity=1 ]  {$x$};
% Text Node
\draw (63,356.4) node [anchor=north west][inner sep=0.75pt]  [color={rgb, 255:red, 74; green, 144; blue, 226 }  ,opacity=1 ]  {$-x$};


\end{tikzpicture}

\end{document}

相关内容