I wish to have a plot as below one in which two rods with specified lengths and angles with x axis, are shown and a circle in the origin. Besides, two arrows that are shown in the origin. If I can plot this schematic picture with Tikz I will be able to provide several questions of my homework in a very picturesque style.
Asked
Active
Viewed 262 times
1
-
2Welcome to TeX.SE! Can you show us a code you have tried so far? – Mensch Feb 26 '19 at 02:41
-
Unfortunately, I am very beginner at this point. I do not know how I can plot that!! – user36028 Feb 26 '19 at 02:45
-
2Sorry, why did you delete the image? I took the liberty and made a rollback to get the image back! – Mensch Feb 26 '19 at 02:49
1 Answers
2
None of this is particularly complicated. The dimline stuff is from here. You could use siunitx to typeset the dimensions and the angle.
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{calc,decorations.pathreplacing,angles,quotes}
\newif\ifdrawdimlineleft
\newif\ifdrawdimlineright
\tikzset{dimlabel distance/.initial=5mm,
vertical lines extend/.initial=5mm,
vertical dim line/.style={gray,thin},
dim arrow line/.style={latex-latex,thin},
dim label/.style={},
left dimline/.is if=drawdimlineleft,
left dimline=true,
right dimline/.is if=drawdimlineright,
right dimline=true,
indicate dimensions/.style={decorate,decoration={
show path construction,
lineto code={
\draw[dim arrow line]
($ (\tikzinputsegmentfirst)!\pgfkeysvalueof{/tikz/dimlabel distance}!-90:(\tikzinputsegmentlast) $) -- ($ (\tikzinputsegmentlast)!\pgfkeysvalueof{/tikz/dimlabel distance}!90:(\tikzinputsegmentfirst) $)
\ifx#1\empty
\else
node[midway,sloped,fill=white,dim label]{#1}
\fi;
\ifdrawdimlineleft
\draw[vertical dim line] (\tikzinputsegmentfirst) --
($ (\tikzinputsegmentfirst)!\pgfkeysvalueof{/tikz/vertical lines
extend}!-90:(\tikzinputsegmentlast) $);
\fi
\ifdrawdimlineright
\draw[vertical dim line] (\tikzinputsegmentlast) --
($ (\tikzinputsegmentlast)!\pgfkeysvalueof{/tikz/vertical lines extend}!90:(\tikzinputsegmentfirst) $);
\fi
}}}}
\begin{document}
\begin{tikzpicture}
\draw[thick,-stealth] (-5,0) -- (5,0) coordinate(x) node[below]{$\mu$};
\draw[thick,-stealth] (0,-5) -- (0,3) node[left]{$y$};
\draw[dashed] (-30:3) coordinate(A) -- (0,0) coordinate(O) ;
\draw[dashed,postaction={indicate dimensions={$L_1=2.5\,$m},
dim arrow line/.append style={solid}}] (O) -- (-120:2.5) coordinate(B);
\draw[thick] (A) -- ++(-30:3);
\draw[thick,postaction={indicate dimensions={$L_2=3\,$m},
dim arrow line/.append style={solid}}] (B) -- ++ (-120:3);
\draw[thick,red,-stealth] (O) -- (60:1.5);
\draw[thick,red,-stealth] (O) -- (150:1.5);
\pic [draw,green!60!black,angle radius=1cm,angle eccentricity=1.4,
"$30^\circ$"] {angle = A--O--x};
\end{tikzpicture}
\end{document}
It might make sense here to rotate the whole thing in a scope.
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{calc,decorations.pathreplacing,angles,quotes}
\newif\ifdrawdimlineleft
\newif\ifdrawdimlineright
\tikzset{dimlabel distance/.initial=5mm,
vertical lines extend/.initial=5mm,
vertical dim line/.style={gray,thin},
dim arrow line/.style={latex-latex,thin},
dim label/.style={},
left dimline/.is if=drawdimlineleft,
left dimline=true,
right dimline/.is if=drawdimlineright,
right dimline=true,
indicate dimensions/.style={decorate,decoration={
show path construction,
lineto code={
\draw[dim arrow line]
($ (\tikzinputsegmentfirst)!\pgfkeysvalueof{/tikz/dimlabel distance}!-90:(\tikzinputsegmentlast) $) -- ($ (\tikzinputsegmentlast)!\pgfkeysvalueof{/tikz/dimlabel distance}!90:(\tikzinputsegmentfirst) $)
\ifx#1\empty
\else
node[midway,sloped,fill=white,dim label]{#1}
\fi;
\ifdrawdimlineleft
\draw[vertical dim line] (\tikzinputsegmentfirst) --
($ (\tikzinputsegmentfirst)!\pgfkeysvalueof{/tikz/vertical lines
extend}!-90:(\tikzinputsegmentlast) $);
\fi
\ifdrawdimlineright
\draw[vertical dim line] (\tikzinputsegmentlast) --
($ (\tikzinputsegmentlast)!\pgfkeysvalueof{/tikz/vertical lines extend}!90:(\tikzinputsegmentfirst) $);
\fi
}}}}
\begin{document}
\foreach \X in {30,33,...,60,57,54,...,33}
{\begin{tikzpicture}
\draw[thick,-stealth] (-5.5,0) -- (5,0) coordinate(x) node[below]{$\mu$};
\draw[thick,-stealth] (0,-6.5) coordinate (my) -- (0,3) node[left]{$y$};
\pgfmathsetmacro{\myangle}{\X}
\begin{scope}[rotate=-\myangle]
\draw[dashed] (2.5,0) coordinate(A) -- (0,0) coordinate(O);
\draw[dashed,postaction={indicate dimensions={$L_1=2.5\,$m},
dim arrow line/.append style={solid}}] (O) -- (0,-2.5) coordinate(B);
\draw[thick] (A) -- ++(2.5,0);
\draw[thick,postaction={indicate dimensions={$L_2=3\,$m},
dim arrow line/.append style={solid}}] (B) -- ++ (0,-3);
\draw[thick,red,stealth-stealth] (-1.5,0) -- (O) -- (0,1.5);
\pic [draw,green!60!black,angle radius=1cm,angle eccentricity=1.4,
"$\pgfmathprintnumber{\myangle}^\circ$"] {angle = A--O--x};
\pic [draw,green!60!black,angle radius=1cm,angle eccentricity=1.4,
"$\pgfmathparse{90-\myangle}\pgfmathprintnumber{\pgfmathresult}^\circ$"] {angle = my--O--A};
\end{scope}
\end{tikzpicture}}
\end{document}
-
Wonderful!!! It is amazing!!! I am trying to modify your code to be symmetric relative to y axis. I think the right rod must be more inclined. – user36028 Feb 26 '19 at 03:10
-
-
I just could not insert the angle between the right line and the (-y) instead of A--O--x. I added coordinate(y) in the suitable position but when I change A--O--x into A--O--y it show the angle with the positive y. I wish to show the angle to negative y!! – user36028 Feb 26 '19 at 03:28
-
@user36028 There is no problem in adding the second angle arc, and the slope was and is 30 degrees. – Feb 26 '19 at 04:26
-
Thanx, Also we can use: \draw (0,-1.4) arc (270:300:1.4) ; \node[] at (280:1.8) {$\theta$}; – user36028 Feb 26 '19 at 05:23


