This is a follow-up question to Drawing Mechanical Systems in LaTeX. I have tried to do similar things, i.e. to model simple mechanical systems.
For example:
\begin{tikzpicture}[M1/.style={rectangle,draw=black,minimum size=2cm,thick}]
\tikzstyle{spring}=[thick,decorate,decoration={zigzag,pre length=0.3cm,post length=0.3cm,segment length=5}]
\tikzstyle{ground}=[fill,pattern=north east lines,draw=none,minimum width=0.75cm,minimum height=0.3cm]
\node [M1] (M1) {};
\node (wall1) [ground, minimum width=3cm,yshift=-3cm] {};
\draw (wall1.north west) -- (wall1.north east);
\draw [spring] (wall1.170) -- ($(M1.south east)!(wall1.170)!(M1.south west)$) node[pos=.5,left] {$k_2$};
\draw [spring] (wall1.10) -- ($(M1.south west)!(wall1.10)!(M1.south east)$) node[pos=.5,right] {$k_3$};
\node (wall2) [ground, minimum width=3cm,yshift=3cm] {};
\draw (wall2.south west) -- (wall2.south east);
\draw [spring] (wall2.170) -- ($(M1.north east)!(wall2.170)!(M1.north west)$) node[pos=.5,left] {$k_1$};
\draw [-latex,thick] (1.5,0) -- (1.5,1) node [pos=.5,right] {$x$};
\filldraw circle (.05) node [pos=.5,below] {\tiny $CG$};
\node [rotate=90,above] at (M1.west) {Mass,$m$};
\node at (0,-3.5) {(a)};
\begin{scope}[xshift=5cm]
\node [M1] (M1) {};
\node (wall1) [ground, minimum width=3cm,yshift=-3cm] {};
\draw (wall1.north west) -- (wall1.north east);
\draw [spring] (wall1) -- ($(M1.south east)!(wall1)!(M1.south west)$) node[pos=.5,left] {$k_2^*$};
\node (wall2) [ground, minimum width=3cm,yshift=3cm] {};
\draw (wall2.south west) -- (wall2.south east);
\draw [spring] (wall2) -- ($(M1.north east)!(wall2)!(M1.north west)$) node[pos=.5,left] {$k_1$};
\draw [-latex,thick] (1.5,0) -- (1.5,1) node [pos=.5,right] {$x$};
\filldraw circle (.05) node [pos=.5,below] {\tiny $CG$};
\node [rotate=90,above] at (M1.west) {Mass,$m$};
\node at (0,-3.5) {(b)};
\end{scope}
\end{tikzpicture}
Now I have the following problem:
The spring k1 in part a is connected to the wall, but to the wrong side. I have tried several things, but nothing worked.
Link: Drawing Mechanical Systems in LaTeX
Figure here:
Best Answer
You should use
(wall2.190) -- ($(M1.north east)!(wall2.190)!(M1.north west)$)
(notice the use of190
instead of170
). The first expression specifies the starting point of the spring, which in this case is in the bottom left of the wall. The<node>.<number>
anchors specify points on the edge of a node, with the number specifying the angle at which the anchor is placed.0
is the middle of the right edge,90
is the middle of the top,170
is slightly higher than the middle of the left edge, and190
is slightly lower than the middle of the left edge. The second expression specifies the end point of the spring, which is at the projection of the starting point on the line from the top left of the rectangle to the top right (($(A)!(P)!(B)$)
is the projection ofP
onAB
).