1

How can i represent the following spring mass system?

[spring mass system[1]

koleygr
  • 20,105
  • TikZ and circuitikz can both handle it. – John Kormylo Sep 20 '18 at 02:11
  • Welcome to TeX.SX! The short answer is that, yes, this is possible but I have to warn you that questions of the form "Please draw this for me" that show no effort on the part of OP, often don't get answered. You will get more help if you post some code showing what you have tried and give a minimal working example. A quick search on TeX.SX for drawing functions (with tikz or pstricks) will give you an idea of where to start from. –  Sep 20 '18 at 04:02

2 Answers2

2

Welcome to TeX.SE! I'd like to advertize 3d coils for that.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{decorations.pathmorphing,patterns}
\makeatletter
\newif\ifcoil@closed
\pgfkeys{%
/pgf/decoration/.cd,
3d coil color/.store in=\TDCoilColor, 
3d coil color/.initial=black,
3d coil color=black,
3d coil width/.store in=\TDCoilWidth, 
3d coil width/.initial=0.4pt,
3d coil width=0.4pt,
3d coil dist/.store in=\TDCoilDist, 
3d coil dist/.initial=0.6pt,
3d coil dist=0.6pt,
3d coil opacity/.store in=\TDCoilOpacity, 
3d coil opacity/.initial=1,
3d coil opacity=1,
3d coil closed/.code=\coil@closedtrue
}

 % https://tex.stackexchange.com/a/219088/121799
\tikzset{get stroke color/.code={%
    \expandafter\global% Jump over, now we have \global
    \expandafter\let% Jump over now we have \global\let
    \expandafter\pgfsavedstrokecolor% Jump we have \global\let\pgf...
    \csname\string\color@pgfstrokecolor\endcsname% Finally expand this and put it at the end 
    },                                           % \global\let\pgf...{} in expanded form 
    restore stroke color/.code={\pgf@setstrokecolor#1},
}
\def\pgfpoint@onthreedcoil#1#2#3{%
  \pgf@x=#1\pgfdecorationsegmentamplitude%
  \pgf@x=\pgfdecorationsegmentaspect\pgf@x%
  \pgf@y=#2\pgfdecorationsegmentamplitude%
  \pgf@xa=0.083333333333\pgfdecorationsegmentlength%
  \advance\pgf@x by#3\pgf@xa%
  \advance\pgf@x by-\generaloffset pt%
}

% coil decoration
%
% Parameters: \pgfdecorationsegmentamplitude, \pgfdecorationsegmentlength,

\pgfdeclaredecoration{3d complete coil}{initial}
{ 
    \state{initial}[width=0.5*\pgfdecorationsegmentlength,
    next state=coil, persistent precomputation={% from https://tex.stackexchange.com/a/25689/121799
    \pgfmathsetmacro\matchinglength{\pgfdecoratedinputsegmentlength / int(\pgfdecoratedinputsegmentlength/\pgfdecorationsegmentlength)}
    \setlength{\pgfdecorationsegmentlength}{\matchinglength pt}
    \tikzset{get stroke color}
    \pgfmathsetmacro{\generaloffset}{\pgfdecorationsegmentlength}
    \pgfmathsetmacro{\initialoffset}{1.5*\pgfdecorationsegmentlength}
    \pgfmathsetmacro{\auxoffset}{2.5*\pgfdecorationsegmentlength}
  }]    { 
    % line in the back
    %
    \pgfsetstrokecolor{\TDCoilColor}
    \pgfsetfillcolor{\TDCoilColor}
    \pgfsetstrokeopacity{\TDCoilOpacity}
    \pgfsetlinewidth{\TDCoilWidth}     
    \ifcoil@closed
     \begingroup
      \def\generaloffset{\auxoffset}
      \pgfpathmoveto{\pgfpoint@onthreedcoil{1    }{ 1    }{15}}
      \pgfpathcurveto
      {\pgfpoint@onthreedcoil{1.555}{ 1    }{16}}
      {\pgfpoint@onthreedcoil{2    }{ 0.555}{17}}
      {\pgfpoint@onthreedcoil{2    }{ 0    }{18}}
      \pgfcoordinate{TD@coilast}{\pgfpoint@onthreedcoil{2    }{ 0    }{18}}
      \pgfcoordinate{TD@coilfirst}{\pgfpoint@onthreedcoil{1    }{ 1    }{15}}
      \pgfusepath{stroke} 
      \pgfsetstrokecolor{\TDCoilColor}
     \endgroup
    \fi
    \begingroup %
    \def\generaloffset{\initialoffset}
    \ifcoil@closed
     \pgfpathmoveto{\pgfpointanchor{TD@coilast}{center}}
    \else
     \pgfpathmoveto{\pgfpointorigin}
    \fi
    \pgfpathcurveto
    {\pgfpoint@onthreedcoil{2    }{-0.555}{7}}
    {\pgfpoint@onthreedcoil{1.555}{-1    }{8}}
    {\pgfpoint@onthreedcoil{1    }{-1    }{9}}
    \pgfusepath{stroke} 
    %
    % white background for front thick part
    %
    \pgfsetstrokeopacity{1}
    \pgfsetstrokecolor{white}
    \pgfsetfillcolor{white}
    \pgfsetlinewidth{1.5*\TDCoilWidth+1.5*\TDCoilDist}
    \pgfpathmoveto{\pgfpoint@onthreedcoil{1    }{-1    }{9}}
    % draw forward
    \pgfpathcurveto
    {\pgfpoint@onthreedcoil{0.445}{-1    }{10}}
    {\pgfpoint@onthreedcoil{0    }{-0.555}{11.25}}
    {\pgfpoint@onthreedcoil{0    }{ 0    }{12.5}}
    \pgfpathcurveto
    {\pgfpoint@onthreedcoil{0    }{ 0.555}{13.25}}
    {\pgfpoint@onthreedcoil{0.445}{ 1    }{14.25}}
    {\pgfpoint@onthreedcoil{1    }{ 1    }{15}}
    % draw the curve back
    \pgfpathcurveto
    {\pgfpoint@onthreedcoil{0.445}{ 1    }{14}}
    {\pgfpoint@onthreedcoil{0    }{ 0.555}{12.75}}
    {\pgfpoint@onthreedcoil{0    }{ 0    }{11.5}}
    \pgfpathcurveto
    {\pgfpoint@onthreedcoil{0    }{-0.555}{10.75}}
    {\pgfpoint@onthreedcoil{0.445}{-1    }{10}}
    {\pgfpoint@onthreedcoil{1    }{-1    }{9}}
    \pgfusepath{stroke,fill} 
    % 
    % draw the thick foreground path
    %
    \pgfsetstrokecolor{\TDCoilColor}
    \pgfsetfillcolor{\TDCoilColor}
    \pgfsetstrokeopacity{\TDCoilOpacity}
    \pgfpathmoveto{\pgfpoint@onthreedcoil{1    }{ 1    }{3}}
    \pgfsetlinewidth{\TDCoilWidth} 
    % forward shifted +
    \pgfpathmoveto{\pgfpoint@onthreedcoil{1    }{-1    }{9}}
    \pgfpathcurveto
    {\pgfpoint@onthreedcoil{0.445}{-1    }{10}}
    {\pgfpoint@onthreedcoil{0    }{-0.555}{11.25}}
    {\pgfpoint@onthreedcoil{0    }{ 0    }{12.5}}
    \pgfpathcurveto
    {\pgfpoint@onthreedcoil{0    }{ 0.555}{13.25}}
    {\pgfpoint@onthreedcoil{0.445}{ 1    }{14.25}}
    {\pgfpoint@onthreedcoil{1    }{ 1    }{15}}
    % draw the curve back shfted -
    \pgfpathcurveto
    {\pgfpoint@onthreedcoil{0.445}{ 1    }{14}}
    {\pgfpoint@onthreedcoil{0    }{ 0.555}{12.75}}
    {\pgfpoint@onthreedcoil{0    }{ 0    }{11.5}}
    \pgfpathcurveto
    {\pgfpoint@onthreedcoil{0    }{-0.555}{10.75}}
    {\pgfpoint@onthreedcoil{0.445}{-1    }{10}}
    {\pgfpoint@onthreedcoil{1    }{-1    }{9}}
    \pgfusepath{stroke,fill} 
    \pgfpathmoveto{\pgfpoint@onthreedcoil{1    }{ 1    }{15}}
    \pgfpathcurveto
    {\pgfpoint@onthreedcoil{1.555}{ 1    }{16}}
    {\pgfpoint@onthreedcoil{2    }{ 0.555}{17}}
    {\pgfpoint@onthreedcoil{2    }{ 0    }{18}}
    \pgfcoordinate{TD@coilast}{\pgfpoint@onthreedcoil{2    }{ 0    }{18}} 
    \pgfusepath{stroke}     
    \endgroup
  }
  \state{coil}[switch if less than=%
    1.9*\pgfdecorationsegmentlength  to last,
               width=+\pgfdecorationsegmentlength]
    { % line in the back
    %
    \pgfsetstrokecolor{\TDCoilColor}
    \pgfsetfillcolor{\TDCoilColor}
    \pgfsetstrokeopacity{\TDCoilOpacity}
    \pgfpathmoveto{\pgfpointanchor{TD@coilast}{center}}
    \pgfsetlinewidth{\TDCoilWidth} 
    \pgfpathcurveto
    {\pgfpoint@onthreedcoil{2    }{-0.555}{7}}
    {\pgfpoint@onthreedcoil{1.555}{-1    }{8}}
    {\pgfpoint@onthreedcoil{1    }{-1    }{9}}
    \pgfusepath{stroke} 
    %
    % white background for front thick part
    %
    \pgfsetstrokeopacity{1}
    \pgfsetstrokecolor{white}
    \pgfsetfillcolor{white}
    \pgfsetlinewidth{1.5*\TDCoilWidth+1.5*\TDCoilDist}
    \pgfpathmoveto{\pgfpoint@onthreedcoil{1    }{ 1    }{3}}
    \pgfpathmoveto{\pgfpoint@onthreedcoil{1    }{-1    }{9}}
    % draw forward
    \pgfpathcurveto
    {\pgfpoint@onthreedcoil{0.445}{-1    }{10}}
    {\pgfpoint@onthreedcoil{0    }{-0.555}{11.25}}
    {\pgfpoint@onthreedcoil{0    }{ 0    }{12.5}}
    \pgfpathcurveto
    {\pgfpoint@onthreedcoil{0    }{ 0.555}{13.25}}
    {\pgfpoint@onthreedcoil{0.445}{ 1    }{14.25}}
    {\pgfpoint@onthreedcoil{1    }{ 1    }{15}}
    % draw the curve back
    \pgfpathcurveto
    {\pgfpoint@onthreedcoil{0.445}{ 1    }{14}}
    {\pgfpoint@onthreedcoil{0    }{ 0.555}{12.75}}
    {\pgfpoint@onthreedcoil{0    }{ 0    }{11.5}}
    \pgfpathcurveto
    {\pgfpoint@onthreedcoil{0    }{-0.555}{10.75}}
    {\pgfpoint@onthreedcoil{0.445}{-1    }{10}}
    {\pgfpoint@onthreedcoil{1    }{-1    }{9}}
    \pgfusepath{stroke,fill} 
    % 
    % draw the thick foreground path
    %
    \pgfsetstrokecolor{\TDCoilColor}
    \pgfsetfillcolor{\TDCoilColor}
    \pgfsetstrokeopacity{\TDCoilOpacity}
    \pgfpathmoveto{\pgfpoint@onthreedcoil{1    }{ 1    }{3}}
    \pgfsetlinewidth{\TDCoilWidth} 
    % forward shifted +
    \pgfpathmoveto{\pgfpoint@onthreedcoil{1    }{-1    }{9}}
    \pgfpathcurveto
    {\pgfpoint@onthreedcoil{0.445}{-1    }{10}}
    {\pgfpoint@onthreedcoil{0    }{-0.555}{11.25}}
    {\pgfpoint@onthreedcoil{0    }{ 0    }{12.5}}
    \pgfpathcurveto
    {\pgfpoint@onthreedcoil{0    }{ 0.555}{13.25}}
    {\pgfpoint@onthreedcoil{0.445}{ 1    }{14.25}}
    {\pgfpoint@onthreedcoil{1    }{ 1    }{15}}
    % draw the curve back shfted -
    \pgfpathcurveto
    {\pgfpoint@onthreedcoil{0.445}{ 1    }{14}}
    {\pgfpoint@onthreedcoil{0    }{ 0.555}{12.75}}
    {\pgfpoint@onthreedcoil{0    }{ 0    }{11.5}}
    \pgfpathcurveto
    {\pgfpoint@onthreedcoil{0    }{-0.555}{10.75}}
    {\pgfpoint@onthreedcoil{0.445}{-1    }{10}}
    {\pgfpoint@onthreedcoil{1    }{-1    }{9}}
    \pgfusepath{stroke,fill} 
    \pgfpathmoveto{\pgfpoint@onthreedcoil{1    }{ 1    }{15}}
    \pgfpathcurveto
    {\pgfpoint@onthreedcoil{1.555}{ 1    }{16}}
    {\pgfpoint@onthreedcoil{2    }{ 0.555}{17}}
    {\pgfpoint@onthreedcoil{2    }{ 0    }{18}}
    \pgfusepath{stroke} 
    \pgfcoordinate{TD@coilast}{\pgfpoint@onthreedcoil{2    }{ 0    }{18}} 
  }
  \state{last}[next state=final]
    { % line in the back
    %
    \pgfsetstrokecolor{\TDCoilColor}
    \pgfsetfillcolor{\TDCoilColor}
    \pgfsetstrokeopacity{\TDCoilOpacity}
    \pgfpathmoveto{\pgfpointanchor{TD@coilast}{center}}
    \pgfsetlinewidth{\TDCoilWidth} 
    \pgfpathcurveto
    {\pgfpoint@onthreedcoil{2    }{-0.555}{7}}
    {\pgfpoint@onthreedcoil{1.555}{-1    }{8}}
    {\pgfpoint@onthreedcoil{1    }{-1    }{9}}
    \pgfusepath{stroke} 
    % 
    % draw the thick foreground path
    %
    \ifcoil@closed %\pgfpointanchor{TD@coilfirst}{center}
     %
     % white background for front thick part
     %
     \pgfsetstrokeopacity{1}
     \pgfsetstrokecolor{white}
     \pgfsetfillcolor{white}
     \pgfsetlinewidth{1.5*\TDCoilWidth+1.5*\TDCoilDist}
     \pgfpathmoveto{\pgfpoint@onthreedcoil{1    }{ 1    }{3}}
     \pgfpathmoveto{\pgfpoint@onthreedcoil{1    }{-1    }{9}}
     % draw forward
     \pgfpathcurveto
     {\pgfpoint@onthreedcoil{0.445}{-1    }{10}}
     {\pgfpoint@onthreedcoil{0    }{-0.555}{11.25}}
     {\pgfpoint@onthreedcoil{0    }{ 0    }{12.5}}
     \pgfpathcurveto
     {\pgfpoint@onthreedcoil{0    }{ 0.555}{13.25}}
     {\pgfpoint@onthreedcoil{0.445}{ 1    }{14.25}}
     {\pgfpointanchor{TD@coilfirst}{center}}
     % draw the curve back
     \pgfpathcurveto
     {\pgfpoint@onthreedcoil{0.445}{ 1    }{14}}
     {\pgfpoint@onthreedcoil{0    }{ 0.555}{12.75}}
     {\pgfpoint@onthreedcoil{0    }{ 0    }{11.5}}
     \pgfpathcurveto
     {\pgfpoint@onthreedcoil{0    }{-0.555}{10.75}}
     {\pgfpoint@onthreedcoil{0.445}{-1    }{10}}
     {\pgfpoint@onthreedcoil{1    }{-1    }{9}}
     \pgfusepath{stroke,fill} 
     \pgfsetstrokecolor{\TDCoilColor}
     \pgfsetfillcolor{\TDCoilColor}
     \pgfsetstrokeopacity{\TDCoilOpacity}
     \pgfpathmoveto{\pgfpoint@onthreedcoil{1    }{ 1    }{3}}
     \pgfsetlinewidth{\TDCoilWidth} 
     % forward shifted +
     \pgfpathmoveto{\pgfpoint@onthreedcoil{1    }{-1    }{9}}
     \pgfpathcurveto
     {\pgfpoint@onthreedcoil{0.445}{-1    }{10}}
     {\pgfpoint@onthreedcoil{0    }{-0.555}{11.25}}
     {\pgfpoint@onthreedcoil{0    }{ 0    }{12.5}}
     \pgfpathcurveto
     {\pgfpoint@onthreedcoil{0    }{ 0.555}{13.25}}
     {\pgfpoint@onthreedcoil{0.445}{ 1    }{14.25}}
     {\pgfpointanchor{TD@coilfirst}{center}}
     % draw the curve back shifted 
     \pgfpathcurveto
     {\pgfpoint@onthreedcoil{0.445}{ 1    }{14}}
     {\pgfpoint@onthreedcoil{0    }{ 0.555}{12.75}}
     {\pgfpoint@onthreedcoil{0    }{ 0    }{11.5}}
     \pgfpathcurveto
     {\pgfpoint@onthreedcoil{0    }{-0.555}{10.75}}
     {\pgfpoint@onthreedcoil{0.445}{-1    }{10}}
     {\pgfpoint@onthreedcoil{1    }{-1    }{9}}
     \pgfusepath{stroke,fill} 
    \else
     %
     % white background for front thick part
     %
     \pgfsetstrokeopacity{1}
     \pgfsetstrokecolor{white}
     \pgfsetfillcolor{white}
     \pgfsetlinewidth{1.5*\TDCoilWidth+1.5*\TDCoilDist}
     \pgfpathmoveto{\pgfpoint@onthreedcoil{1    }{ 1    }{3}}
     \pgfpathmoveto{\pgfpoint@onthreedcoil{1    }{-1    }{9}}
     % draw forward
     \pgfpathcurveto
     {\pgfpoint@onthreedcoil{0.445}{-1    }{10}}
     {\pgfpoint@onthreedcoil{0    }{-0.555}{11.25}}
     {\pgfpoint@onthreedcoil{0    }{ 0    }{12.5}}
     \pgfpathcurveto
     {\pgfpoint@onthreedcoil{0    }{ 0.555}{13.25}}
     {\pgfpoint@onthreedcoil{0.445}{ 1    }{14.25}}
     {\pgfpoint@onthreedcoil{1    }{ 1    }{15}}
     % draw the curve back
     \pgfpathcurveto
     {\pgfpoint@onthreedcoil{0.445}{ 1    }{14}}
     {\pgfpoint@onthreedcoil{0    }{ 0.555}{12.75}}
     {\pgfpoint@onthreedcoil{0    }{ 0    }{11.5}}
     \pgfpathcurveto
     {\pgfpoint@onthreedcoil{0    }{-0.555}{10.75}}
     {\pgfpoint@onthreedcoil{0.445}{-1    }{10}}
     {\pgfpoint@onthreedcoil{1    }{-1    }{9}}
     \pgfusepath{stroke,fill} 
     \pgfsetstrokecolor{\TDCoilColor}
     \pgfsetfillcolor{\TDCoilColor}
     \pgfsetstrokeopacity{\TDCoilOpacity}
     \pgfpathmoveto{\pgfpoint@onthreedcoil{1    }{ 1    }{3}}
     \pgfsetlinewidth{\TDCoilWidth} 
     % forward shifted +
     \pgfpathmoveto{\pgfpoint@onthreedcoil{1    }{-1    }{9}}
     \pgfpathcurveto
     {\pgfpoint@onthreedcoil{0.445}{-1    }{10}}
     {\pgfpoint@onthreedcoil{0    }{-0.555}{11.25}}
     {\pgfpoint@onthreedcoil{0    }{ 0    }{12.5}}
     \pgfpathcurveto
     {\pgfpoint@onthreedcoil{0    }{ 0.555}{13.25}}
     {\pgfpoint@onthreedcoil{0.445}{ 1    }{14.25}}
     {\pgfpoint@onthreedcoil{1    }{ 1    }{15}}
     % draw the curve back shifted 
     \pgfpathcurveto
     {\pgfpoint@onthreedcoil{0.445}{ 1    }{14}}
     {\pgfpoint@onthreedcoil{0    }{ 0.555}{12.75}}
     {\pgfpoint@onthreedcoil{0    }{ 0    }{11.5}}
     \pgfpathcurveto
     {\pgfpoint@onthreedcoil{0    }{-0.555}{10.75}}
     {\pgfpoint@onthreedcoil{0.445}{-1    }{10}}
     {\pgfpoint@onthreedcoil{1    }{-1    }{9}}
     \pgfusepath{stroke,fill} 
    \fi
    \pgfpathmoveto{\pgfpoint@onthreedcoil{1    }{ 1    }{15}}
    \ifcoil@closed %TD@coilfirst
    \else
     \pgfpathcurveto
     {\pgfpoint@onthreedcoil{1.555}{ 1    }{16}}
     {\pgfpoint@onthreedcoil{2    }{ 0.555}{17}}
     {\pgfpoint@onthreedcoil{2    }{ 0    }{18}}
    \fi
    \pgfusepath{stroke} 
    %\pgfcoordinate{TD@coilast}{\pgfpoint@onthreedcoil{2    }{ 0    }{18}} 
  }
  \state{final}
  {
    \pgfpathmoveto{\pgfpointdecoratedpathlast}
    \tikzset{restore stroke color/.expand once=\pgfsavedstrokecolor}
  }
}
\makeatother

\begin{document}
\begin{tikzpicture}[decoration={3d coil color=black,aspect=0.35, segment length=3mm, 
amplitude=3mm,3d complete  coil},thick,font=\sffamily]
% left
\fill[pattern=north east lines] (-1,7) rectangle (1,7.5);
\draw[very thick] (-1,7) -- (1,7);
\node[anchor=south] at (0,7.5) {Equilibrium};
\draw (0,4) -- (0,5) coordinate[midway](m1);
\draw (0,1) -- (0,0.5) coordinate(m2);
\fill (m1) circle (2pt) node[left] {$m_1$};
\fill (m2) circle (2pt) node[left] {$m_2$};
\draw[decorate,segment length=2mm] (0,5) -- (0,7);
\draw[decorate,segment length=3mm] (0,1) -- (0,4.1);
% right
\fill[pattern=north east lines] (2,7) rectangle (4,7.5);
\draw[very thick] (2,7) -- (4,7);
\node[anchor=south] at (3,7.5) {Motion};
\draw (3,3) -- (3,4) coordinate[midway](m1');
\draw (3,0) -- (3,-0.5) coordinate(m2');
\fill (m1') circle (2pt) (m2') circle (2pt);
\draw[decorate,segment length=3mm] (3,4) -- (3,7);
\draw[decorate,segment length=3mm] (3,0) -- (3,3);
% middle
\draw[dashed] (m1) -- (2.8,0 |- m1) coordinate[pos=0.9] (x1top);
\draw[-latex] (x1top) -- (x1top |-m1') node[left]{$x_1$};
\draw[dashed] (m2) -- (2.8,0 |- m2) coordinate[pos=0.9] (x2top);
\draw[-latex] (x2top) -- (x2top |-m2') node[left]{$x_2$};
\end{tikzpicture}
\end{document}

enter image description here

2

A less sophisticated solution inspired from @marmot answer:

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{decorations.pathmorphing,patterns}

\tikzset{
 spring/.style={very thick,
    decorate,
    decoration={coil,
      amplitude=1.5mm,
      segment length=2mm,
      pre length=3mm,
      post length=3mm,
      aspect=0.6,
    }},
  %
  equilibrium state/.style={spring},
  %
  motion state/.style={spring,/pgf/decoration/segment length=2.5mm},
 %
  ground/.style={pattern=north east lines},
}

\begin{document}
\begin{tikzpicture}
% left

\fill[ground] (-1,7) rectangle (1,7.5);
\draw[very thick] (-1,7) -- (1,7);
\node[anchor=south] at (0,7.5) {Equilibrium};

\draw[ equilibrium state] (0,4)coordinate(m1) -- (0,7);
\draw[ equilibrium state] (0,1)coordinate(m2) -- (m1);
\fill (m1) circle (2pt) node[left] {$m_1$};
\fill (m2) circle (2pt) node[left] {$m_2$};
% right
\fill[ground] (2,7) rectangle (4,7.5);
\draw[very thick] (2,7) -- (4,7);
\node[anchor=south] at (3,7.5) {Motion};
\draw[ motion state] (3,3.5)coordinate(m'1) -- (3,7);
\draw[ motion state] (3,0)coordinate(m'2) -- (m'1);
\fill (m'1) circle (2pt) node[right] {$m_1$};
\fill (m'2) circle (2pt) node[right] {$m_2$};


% middle
\draw[dashed] (m1) -- (2.8,0 |- m1) coordinate[pos=0.9] (x1top);
\draw[-latex] (x1top) -- (x1top |-m'1) node[left]{$x_1$};
\draw[dashed] (m2) -- (2.8,0 |- m2) coordinate[pos=0.9] (x2top);
\draw[-latex] (x2top) -- (x2top |-m'2) node[left]{$x_2$};
\end{tikzpicture}
\end{document}

enter image description here