2

This question is based off of the drawing in this link.

Code:

\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepackage{tikz}
\usepackage{float}
\usetikzlibrary{calc, patterns, angles, intersections, quotes}
\usepackage[margin=1in]{geometry} 
\begin{document} 
    \begin{figure}[H]
        \begin{tikzpicture}[thick,>=latex]
            \begin{scope}
                \clip(-5,2) rectangle (5,-5);
                \pgfmathsetmacro{\leftPendPart}{-0.8/sqrt(2)}
                %\draw[dashed] (-4.24cm,0) arc(180:360:4.24cm);
                %\filldraw[white] (-4.3,4.3) rectangle (4.3,0);
                \draw[double distance=1.6mm] (0,0) -- (3,-3) node[midway,xshift=4mm,yshift=2mm]{$\ell$};
                \path[draw = none] (\leftPendPart mm, 0) -- ++ (-45:3) coordinate(pendTipLeft);
                \draw[->] (3,-3) -- (3,-4.5) node[below]{$mg$};
                \draw[fill=white] (-1.2,1.0) -- (-.5,0) arc(180:360:0.5) -- (1.2,1.0) -- cycle;
                \draw[draw=black,fill=white] (0, 0) circle circle (.3cm);
                \draw[draw=black,fill=white] (3,-3) circle circle (.3cm);
                \draw[dashed] (0, -0.5) coordinate (jointEdge) -- ++(270:3) coordinate(jointEdgeOut);
                \draw[->] (-0.7cm, 0) arc(180:360:0.7) node[pos = 0.4, xshift = -0.2cm, yshift = -0.2cm]{$bu$};
                \draw[->] (1.3, 0) arc(0:-45:1.3) node[pos = 0.2, xshift = 0.3cm, yshift = -0.2cm]{$c^*\dot{\theta}$};
                %\draw[->] (.6,0) -- (2,0) node[below]{$x$};
                %\draw[->] (0,-.6) -- (0,-2) node[below]{$y$};
                \draw[pattern=north east lines] (-1.4,1.3) rectangle (1.4,1);
                \pic[draw, ->, "$\theta$", angle eccentricity = 1.25, angle radius = 1.5cm]{angle=jointEdgeOut--jointEdge--pendTipLeft};   
            \end{scope}
        \end{tikzpicture}
    \end{figure}
\end{document}

Output:

enter image description here

I would like the arcs to stop right at the edge of the straight lines that has slope of -1. That is, the arcs coming from either side stop right at the line. Here's what I mean:

Desired (red arrows):

enter image description here

How to get something like that in the second pic (arcs don't have to be necessarily on the same location as the red arrows)?

Superman
  • 1,615

1 Answers1

2

A double line is just a thick line with a thinner (usually white) line on top. You may want to construct the double line as two separate lines, so that the angles can stop at them. This can be done with the shift right key and a couple of intersections.

\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage{float}
\usetikzlibrary{arrows.meta,bending,calc, patterns, angles, intersections, quotes}
\usepackage[margin=1in]{geometry} 
\begin{document} 
    \begin{figure}[H]
        \begin{tikzpicture}[thick,>={Latex[bend]},
            bcirc/.style={circle,draw,inner sep=0pt,minimum size=0.6cm,fill=white},
            shift right/.style={to path={
             ($(\tikztostart)!#1!270:(\tikztotarget)$)
             --($(\tikztotarget)!#1!90:(\tikztostart)$) }}]
            \begin{scope}
                \clip(-5,2) rectangle (5,-5);
                \pgfmathsetmacro{\leftPendPart}{-0.8/sqrt(2)}
                %\draw[dashed] (-4.24cm,0) arc(180:360:4.24cm);
                %\filldraw[white] (-4.3,4.3) rectangle (4.3,0);
                \path[draw = none] (\leftPendPart mm, 0) -- ++ (-45:3) coordinate(pendTipLeft);
                \draw[->] (3,-3) -- (3,-4.5) node[below]{$mg$};
                \draw[fill=white,name path=arc] (-1.2,1.0) -- (-.5,0) 
                    arc(180:360:0.5) -- (1.2,1.0) -- cycle;
                \path (0,0) node[bcirc,name path=patha] (a){} 
                    (3,-3) node[bcirc,name path=pathb] (b){};
                \path[shift right=0.8mm,name path=ab1] (a) to (b);
                \path[shift right=-0.8mm,name path=ab2] (a) to (b);
                \draw[name intersections={of=pathb and ab1,by=i1},
                name intersections={of=pathb and ab2,by=i2},
                name intersections={of=patha and ab1,by=i1'},
                name intersections={of=patha and ab2,by=i2'},
                name intersections={of=arc and ab1,by=i3},
                name intersections={of=arc and ab2,by=i4}]
                 (i1) -- (i3) (i2) -- node[auto,swap] {$\ell$}(i4);
                \draw[dashed] (0, -0.5) coordinate (jointEdge) -- ++(270:3) 
                coordinate(jointEdgeOut);
                \draw[->] (-0.7cm, 0) arc(180:360:0.7) node[pos = 0.4, xshift = -0.2cm, yshift = -0.2cm]{$bu$};
                \draw[pattern=north east lines] (-1.4,1.3) rectangle (1.4,1);
                \path (i4) ++ (1,0) coordinate (aux);
                \pic[draw, <-, "$c^*\dot{\theta}$", angle eccentricity = 1.6, 
                    angle radius = 0.8cm,pic text options={yshift=2mm}]{angle=i2--i4--aux};   
                \path (intersection of jointEdgeOut--a and i1--i3) coordinate 
                 (aux2);
                \pic[draw, ->, "$\theta$", angle eccentricity = 1.25, 
                    angle radius = 1.5cm]{angle=jointEdgeOut--aux2--i1};   
            \end{scope}
        \end{tikzpicture}
    \end{figure}
\end{document}

enter image description here

  • Nice solution! Thank you so much! Oh god, I felt that I had to put this diagram in one of my final projects that is due tomorrow. Thank you for helping me! – Superman Jun 08 '20 at 05:39
  • 1
    @Superman You are welcome! –  Jun 08 '20 at 05:40
  • Actually, I am getting an illegal parameter number, as I am using beamer. Let me make another query. – Superman Jun 08 '20 at 05:43
  • 2
    @Superman You only need to add fragile, \begin{frame}[fragile], move shift right/.style={to path={ ($(\tikztostart)!#1!270:(\tikztotarget)$) --($(\tikztotarget)!#1!90:(\tikztostart)$) }} out of the frame with \tikzset{shift right/.style={to path={ ($(\tikztostart)!#1!270:(\tikztotarget)$) --($(\tikztotarget)!#1!90:(\tikztostart)$) }}}, or use four (!) #, shift right/.style={to path={ ($(\tikztostart)!####1!270:(\tikztotarget)$) --($(\tikztotarget)!####1!90:(\tikztostart)$) }}, I believe. –  Jun 08 '20 at 05:43
  • Hmmm, it worked. Interesting. I wonder why I had to do that for beamer, but not in article. – Superman Jun 08 '20 at 05:47
  • 2
    @Superman Because technically a non-fragile frame is a nested macro. If you would put the stuff in a macro in an article document, you would need to double the #, and if the macro goes into another macro, you need four #. You just do not do that usually in article documents. –  Jun 08 '20 at 05:49
  • This sounds quite interesting... looks tough to understand why one needs to double up the number of # for each nested macro – Superman Jun 08 '20 at 05:53
  • 2
    @Superman This is a design choice of TeX, see e.g. https://tex.stackexchange.com/q/42463. Clearly there must be some way to distinguish the parameters of the inner and outer macros, and the author of TeX chose this way. –  Jun 08 '20 at 05:56
  • Oh, ok, I will need to take some time to understand more. Thank you, though! – Superman Jun 08 '20 at 05:56