I am new with Tikz and I managed to combine several Tikz code samples [x] to represent a 3-degree of freedom system. However, I would like to 'translate'/move the pendulum from mass M to the second mass M2 but it doesn't work. The center of the pdf content seems to be defined at the M.center and the "definition" of angle as well. I did not achieve to change that as I tried to move the pendulum, the angle won't translate to the next mass M2.
See the code below:
\documentclass[tikz]{standalone}
\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings}
\usepackage{physics}
\usepackage{siunitx}
\sisetup{detect-all} % to allow \pi in \SI
\usepackage{tikz,pgfplots}
\usepackage[outline]{contour} % glow around text
\usetikzlibrary{calc}
\usetikzlibrary{angles,quotes} % for pic
\usetikzlibrary{arrows.meta}
\tikzset{>=latex} % for LaTeX arrow head
\contourlength{1.2pt}
\colorlet{xcol}{blue!70!black}
\colorlet{vcol}{green!60!black}
\colorlet{myred}{red!70!black}
\colorlet{myblue}{blue!70!black}
\colorlet{mygreen}{green!70!black}
\colorlet{mydarkred}{myred!70!black}
\colorlet{mydarkblue}{myblue!60!black}
\colorlet{mydarkgreen}{mygreen!60!black}
\colorlet{acol}{red!50!blue!80!black!80}
\tikzstyle{CM}=[red!40!black,fill=red!80!black!80]
\tikzstyle{xline}=[xcol,thick,smooth]
\tikzstyle{mass}=[line width=0.6,red!30!black,fill=red!40!black!10,rounded corners=1,top color=red!40!black!20,bottom color=red!40!black!10,shading angle=20]
\tikzstyle{faded mass}=[dashed,linewidth=0.1,red!30!black!40,fill=red!40!black!10,rounded corners=1,top color=red!40!black!10,bottom color=red!40!black!10,shading angle=20]
\tikzstyle{rope}=[black!70!black,thick,line cap=round]
\def\rope#1{ \draw[black,line width=0.8] #1; \draw[rope,line width=1.1] #1; }
\tikzstyle{force}=[->,myred,very thick,line cap=round]
\tikzstyle{velocity}=[->,vcol,very thick,line cap=round]
\tikzstyle{Fproj}=[force,myred!40]
\tikzstyle{myarr}=[-{Latex[length=3,width=2]},ultra thick]
\def\tick#1#2{\draw[thick] (#1)++(#2:0.12) --++ (#2-180:0.24)}
\DeclareMathOperator{\sn}{sn}
\DeclareMathOperator{\cn}{cn}
\DeclareMathOperator{\dn}{dn}
\def\N{80} % number of samples in plots
\tikzstyle{axis}=[->,thick] %line width=0.6
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\tikzstyle{spring}=[thick,decorate,decoration={zigzag,pre length=0.3cm,post length=0.3cm,segment length=6,amplitude=1.75mm}] %amplitude=1.75mm
\tikzstyle{damper}=[thick,decoration={markings,
mark connection node=dmp,
mark=at position 0.5 with
{
\node (dmp) [thick,inner sep=0pt,transform shape,rotate=-90,minimum width=15pt,minimum height=3pt,draw=none] {};
\draw [thick] ($(dmp.north east)+(2pt,0)$) -- (dmp.south east) -- (dmp.south west) -- ($(dmp.north west)+(2pt,0)$);
\draw [thick] ($(dmp.north)+(0,-5pt)$) -- ($(dmp.north)+(0,5pt)$);
}
}, decorate]
\tikzstyle{ground}=[fill,pattern=north east lines,draw=none,minimum width=0.75cm,minimum height=0.3cm,inner sep=0pt,outer sep=0pt]
\definecolor{monOrange}{RGB}{255,157,0}
\definecolor{monBleu}{rgb}{0.2,0.4,0.6}
\definecolor{monCyan}{RGB}{74,181,247}
\definecolor{monGris}{RGB}{100,100,100}
\definecolor{monRed}{RGB}{255, 36, 0}
\tikzset{
seisme/.style={color=cyan,ultra thick,->},
vent/.style={color=monRed,ultra thick,->},
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
%%%%%%%%%%%%%%% SHEMA MODAL 3DDL %%%%%%%%%%%%%%%
\begin{tikzpicture}[scale=1.1, every node/.style={scale=1.3}]
% Rectangle masse m1 + petites roues
\node [draw, outer sep=0pt, thick] (M) [minimum width=2cm, minimum height=1.5cm] {$M$};
\draw [thick, fill=white] (M.south west) ++(0.2cm,-0.125cm) circle (0.125cm) (M.south east) ++(-0.2cm,-0.125cm) circle (0.125cm);
% Rectangle masse m2 + petites roues
\node [draw, outer sep=0pt, thick] (M2) [minimum width=2cm, minimum height=1.5cm, xshift = 4cm] {$M_2$}; % rectangle entourant la masse m2
\draw [thick, fill=white] (M2.south west) ++(0.2cm,-0.125cm) circle (0.125cm) (M2.south east) ++(-0.2cm,-0.125cm) circle (0.125cm); % 2 petits cercles sous la masse m2
% Ground bas
\node (ground) [ground,anchor=north,yshift=-0.2cm,minimum width=10cm,xshift=2.03cm] at (M.south) {}; % ground bas hachurage
\draw (ground.north west) -- (ground.north east) -- (ground.south east) -- (ground.south west); %traits horizontaux entourant le ground bas
\node (fill) [ground,xshift=-0.15cm,minimum height = 0.3cm, minimum width = 0.3cm] at (ground.west) {}; %petit ajout de ground bas tout à gauche
\draw (fill.north west) -- (fill.south west) -- (fill.south east);
% Ground vertical
\node (wall) [ground, rotate=-90, minimum width=3cm,anchor=south east] at (fill.north west) {}; % ground vertical hachurage
\draw (wall.north east) -- (wall.north west) -- (wall.south west) -- (wall.south east); %traits horizontaux entourant le ground vertical
% % Ressort k
\draw [spring] (M.east) -- (M2.west) node (k) [midway,yshift=0.4cm] {$k$};
% Ressort k
\draw [spring] (wall.15) node[left= 0.3cm]{$O$} -- ($(M.north west)!(wall.15)!(M.south west)$) node [midway,yshift=0.4cm] {$k$};
% Force d'excitation sur la masse m2
%\draw [-latex,ultra thick] (M2.east) -- +(1cm,0cm) node [right] (u) {$F(t) = F_0 \sin{\omega t}$};
%Déplacement de la masse m1 noté y1
\draw [-latex,ultra thick] (M.center) ++(0cm, 1.4cm) -- +(1cm,0cm) node [above] (y1) {$x(t)$}; % flèche déplacement x(t)
\draw [dashed] (M.center) -- +(0cm,1.4cm); % trait pointillés y1
% Déplacement de la masse m2 noté y2
\draw [-latex,ultra thick] (M2.center) ++(0cm, 1.4cm) -- +(1cm,0cm) node [above] (y2) {$x_2(t)$}; % flèche déplacement x(t)
\draw [dashed] (M2.center) -- +(0cm,1.4cm); % trait pointillés y2
% Axes (x,y) et centre 0 du repère cartésien
%\draw[axis] (0,0)--(5.7,0) node[right] {$\overrightarrow{x}$}
\drawdashed,->--(7.7,0) node[right]{$\overrightarrow{x}$};
\drawdashed,->--(-3.5,5) node[left]{$\overrightarrow{y}$};
% PENDULUM
\def\L{5} % string length
\def\ang{28} % angle string
\def\R{0.4} % ball radius
\def\F{1.0} % force magnitude
\coordinate (M) at (\ang-90:\L);
\coordinate (M') at (0,-\L);
\coordinate (O) at (0,0);
\coordinate (B) at (0,-\L-2.2\R);
\coordinate (FT) at ($(M)+(90+\ang:{\Fcos(\ang)+\R})$);
\coordinate (FG) at ($(M)+(-90:{\F+\R})$);
\coordinate (FGx) at ($(M)+(-90+\ang:{0.55\F+\R})$);
\coordinate (MA) at ($(M)+(180+\ang:{\Fsin(\ang)+\R})$);
%\draw[faded mass] (M') circle(\R);
\draw[dashed] (O) -- (B);
\draw[dashed] (-90+\ang+10:\L) arc(-90+\ang+10:-110:\L) (B);
\rope{(O) -- (M)} \path (O) -- (M) node[midway,above right=-1] {$L$};
\fill[black] (O) circle(0.04);
\draw[mass] (M) circle(\R) node {$m$};
\draw pic[myarr,"$\theta$",xcol,draw=xcol,angle radius=43,angle eccentricity=1.30] {angle=B--O--M};
\end{tikzpicture}
\end{document}
Any sugestion would be welcome!




pgfplotspackage loadstikz, but requires to set thecompatoption. Do you needpgfplotsat all? You should use\tikzsetinstead of\tikzstyle. Also, you should probably not (re)define short commands like\Nin the global scope. – Jasper Habicht Dec 21 '23 at 10:03\picstatements, see https://tikz.dev/tikz-pics . Think of the as macros for Tikz. – MS-SPO Dec 21 '23 at 17:30pics as @MS-SPO suggested, but I'm not sure I'd recommend it if you've just started using TikZ.picshave some idiosyncrasies which may just introduce unnecessary confusion at this point. Better, I think, to work through the tutorials at the start of the TikZ manual first and draw some simple pictures with basic building blocks so you get a 'feel' for how things work first. – cfr Dec 21 '23 at 17:37