Tikz: The common tangent and the shaded region












10















What are possible options to construct the tangent line (along with the shaded region) as shown below?



enter image description here



MWE:



documentclass[tikz, border=1cm]{standalone}
begin{document}
begin{tikzpicture}
coordinate (A) at (0,0);
coordinate (B) at (0,7);
coordinate (C) at (7,7);
coordinate (D) at (7,0);
coordinate (E) at (0,4);
coordinate (F) at (3,7);
coordinate (G) at (7,4);
coordinate (H) at (3,0);
coordinate (M) at (5,2);
coordinate (N) at (1.5,5.5);
draw (A)--(B)--(C)--(D)--cycle;
draw (E)--(G);
draw (F)--(H);
draw (N) circle [radius=1.5];
draw (M) circle [radius=2];
end{tikzpicture}
end{document}









share|improve this question





























    10















    What are possible options to construct the tangent line (along with the shaded region) as shown below?



    enter image description here



    MWE:



    documentclass[tikz, border=1cm]{standalone}
    begin{document}
    begin{tikzpicture}
    coordinate (A) at (0,0);
    coordinate (B) at (0,7);
    coordinate (C) at (7,7);
    coordinate (D) at (7,0);
    coordinate (E) at (0,4);
    coordinate (F) at (3,7);
    coordinate (G) at (7,4);
    coordinate (H) at (3,0);
    coordinate (M) at (5,2);
    coordinate (N) at (1.5,5.5);
    draw (A)--(B)--(C)--(D)--cycle;
    draw (E)--(G);
    draw (F)--(H);
    draw (N) circle [radius=1.5];
    draw (M) circle [radius=2];
    end{tikzpicture}
    end{document}









    share|improve this question



























      10












      10








      10


      6






      What are possible options to construct the tangent line (along with the shaded region) as shown below?



      enter image description here



      MWE:



      documentclass[tikz, border=1cm]{standalone}
      begin{document}
      begin{tikzpicture}
      coordinate (A) at (0,0);
      coordinate (B) at (0,7);
      coordinate (C) at (7,7);
      coordinate (D) at (7,0);
      coordinate (E) at (0,4);
      coordinate (F) at (3,7);
      coordinate (G) at (7,4);
      coordinate (H) at (3,0);
      coordinate (M) at (5,2);
      coordinate (N) at (1.5,5.5);
      draw (A)--(B)--(C)--(D)--cycle;
      draw (E)--(G);
      draw (F)--(H);
      draw (N) circle [radius=1.5];
      draw (M) circle [radius=2];
      end{tikzpicture}
      end{document}









      share|improve this question
















      What are possible options to construct the tangent line (along with the shaded region) as shown below?



      enter image description here



      MWE:



      documentclass[tikz, border=1cm]{standalone}
      begin{document}
      begin{tikzpicture}
      coordinate (A) at (0,0);
      coordinate (B) at (0,7);
      coordinate (C) at (7,7);
      coordinate (D) at (7,0);
      coordinate (E) at (0,4);
      coordinate (F) at (3,7);
      coordinate (G) at (7,4);
      coordinate (H) at (3,0);
      coordinate (M) at (5,2);
      coordinate (N) at (1.5,5.5);
      draw (A)--(B)--(C)--(D)--cycle;
      draw (E)--(G);
      draw (F)--(H);
      draw (N) circle [radius=1.5];
      draw (M) circle [radius=2];
      end{tikzpicture}
      end{document}






      tikz-pgf






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 10 '18 at 17:52







      blackened

















      asked Dec 10 '18 at 14:28









      blackenedblackened

      1,478714




      1,478714






















          2 Answers
          2






          active

          oldest

          votes


















          14














          Let me start by repeating the nice solution by LoopSpace, to whom I give full credit for the first part.



          documentclass[tikz, border=1cm]{standalone}
          usetikzlibrary{calc}
          begin{document}
          begin{tikzpicture}
          coordinate (A) at (0,0);
          coordinate (B) at (0,7);
          coordinate (C) at (7,7);
          coordinate (D) at (7,0);
          coordinate (E) at (0,4);
          coordinate (F) at (3,7);
          coordinate (G) at (7,4);
          coordinate (H) at (3,0);
          coordinate (M) at (5,2);
          coordinate (N) at (1.5,5.5);
          draw (A)--(B)--(C)--(D)--cycle;
          draw (E)--(G);
          draw (F)--(H);
          pgfmathsetmacro{rone}{1.5}
          pgfmathsetmacro{rtwo}{2}
          pgfmathsetmacro{mid}{rone/(rone + rtwo)}
          pgfmathsetmacro{out}{rone/(rone - rtwo)}
          node[circle,minimum size=2*rone*1cm,draw] (c1) at (N){};
          node[circle,minimum size=2*rtwo*1cm,draw] (c2) at (M){};
          path (c1.center) -- node[coordinate,pos=mid] (mid) {} (c2.center);
          path (c1.center) -- node[coordinate,pos=out] (out) {} (c2.center);
          foreach i in {1,2}
          {foreach j in {1,2}
          {foreach k in {mid,out}
          {coordinate (tijk) at (tangent cs:node=ci,point={(k)},solution=j);}}}
          foreach i in {2}
          {
          draw[red] ($(t1i out)!-1cm!(t2i out)$) -- ($(t2i out)!-1cm!(t1i out)$);
          }

          end{tikzpicture}
          end{document}


          enter image description here



          However, this setup is so simple that I cannot refrain from adding an analytic determination of the tangent. (The other possible tangents can be added completely analogously). The observations that go into the analytic determination are




          1. The slope of the tangent is given by the slope of the line connecting the centers of the circles plus the ratio of the difference of the radii and the distance of the centers.

          2. Given the slope, the respective points on the circle are uniquely determined (modulo 180).


          One thus arrives at



          documentclass[tikz, border=1cm]{standalone}
          usetikzlibrary{calc,backgrounds}
          begin{document}
          begin{tikzpicture}[tangent of circles/.style args={%
          at #1 and #2 with radii #3 and #4}{insert path={%
          let p1=($(#2)-(#1)$),n1={atan2(y1,x1)},n2={veclen(y1,x1)*1pt/1cm},
          n3={atan2(#4-#3,n2)}
          in ($(#1)+(n3+n1+90:#3)$) -- ($(#2)+(n3+n1+90:#4)$)}}]
          coordinate (A) at (0,0);
          coordinate (B) at (0,7);
          coordinate (C) at (7,7);
          coordinate (D) at (7,0);
          coordinate (E) at (0,4);
          coordinate (F) at (3,7);
          coordinate (G) at (7,4);
          coordinate (H) at (3,0);
          coordinate (M) at (5,2);
          coordinate (N) at (1.5,5.5);
          draw (A)--(B)--(C)--(D)--cycle;
          draw (E)--(G);
          draw (F)--(H);
          draw (N) circle [radius=1.5];
          draw (M) circle [radius=2];
          path[tangent of circles={at N and M with radii 1.5 and 2}]
          coordinate[pos=0] (aux0) coordinate[pos=1] (aux1);
          % extend the tangent
          draw (intersection cs:first line={(aux0)--(aux1)}, second line={(C)--(D)})
          -- (intersection cs:first line={(aux0)--(aux1)}, second line={(C)--(B)});
          % fill the region above right of the tangent
          begin{scope}[on background layer]
          fill[gray!50] (intersection cs:first line={(aux0)--(aux1)},
          second line={(E)--(G)}) -| (C) -|
          (intersection cs:first line={(aux0)--(aux1)}, second line={(F)--(H)})
          -- cycle;
          end{scope}
          % draw the little squares
          draw[fill=gray!20] (C) rectangle ++ (-0.4,-0.4)
          (F) rectangle ++ (0.4,-0.4)
          (G) rectangle ++ (-0.4,0.4)
          (intersection cs:first line={(E)--(G)}, second line={(F)--(H)})
          rectangle ++ (0.4,0.4);
          draw[fill,thick,-latex] (N) circle (1pt) -- ++(225:1.5) node[midway,above
          left]
          {$vec r_2$};
          draw[fill,thick,-latex] (M) circle (1pt) -- ++(225:2) node[midway,above
          left]
          {$vec r_1$};
          node at (barycentric cs:C=1,G=1,F=1) {$S_x$};
          end{tikzpicture}
          end{document}


          enter image description here



          Let me mention that I made no effort in shortening the code. One could kick out some coordinates, but I do not see any point in this. IMHO it would make the code just harder to understand.






          share|improve this answer


























          • The remaining annotation may be added with node at (barycentric cs:C=1,G=1,F=1) {$S_x$};.

            – marmot
            Dec 10 '18 at 17:22






          • 1





            @blackened I changed it (and also moved the labels, as suggested by Artificial Stupidity). However, I do not add an animation, if you want an animation, see here, and wait for a PSTricks variant ;-)

            – marmot
            Dec 10 '18 at 18:49





















          8














          A PSTricks solution only for comparison purposes.



          documentclass[pstricks,border=12pt,12pt]{standalone}
          usepackage{pstricks-add,pst-eucl}
          begin{document}
          pspicture[PointName=none,PointSymbol=none](8,8)
          pnodes(4,0){A}(4,8){B}(0,4){C}(8,4){D}(2,6){P}(6,2){Q}
          psCircleTangents(P){2}(Q){2}
          pstInterLL{CircleTO1}{CircleTO2}{A}{B}{X}
          pstInterLL{CircleTO1}{CircleTO2}{C}{D}{Y}
          pspolygon*[linecolor=lightgray](X)(B)(D|B)(D)(Y)
          pcline[nodesep=-1.2](CircleTO1)(CircleTO2)
          psframe(D|B)
          psline(A)(B)
          psline(C)(D)
          pscircle(P){2}
          pscircle(Q){2}
          rput(A|D){psframe(12pt,12pt)}
          rput{90}(D){psframe(12pt,12pt)}
          rput{-90}(B){psframe(12pt,12pt)}
          rput{180}(D|B){psframe(12pt,12pt)}
          rput(Q|P){$S_x$}
          pcline{<-}([angle=225,nodesep=2]P)(P)naput{$r_2$}
          pcline{<-}([angle=225,nodesep=2]Q)(Q)naput{$r_1$}
          endpspicture
          end{document}


          enter image description here



          Different Radii



          documentclass[pstricks,border=12pt,12pt]{standalone}
          usepackage{pstricks-add,pst-eucl,pst-calculate}

          begin{document}
          foreach x in {4,4.5,...,6.0}{%
          pspicture[PointName=none,PointSymbol=none](8,8)
          pnodes(x,0){A}(A|0,8){B}(!0 8 xspace sub){C}(8,0|C){D}(!xspace 2 div dup neg 8 add){P}(!xspace 2 div dup 4 add exch neg 4 add){Q}
          psCircleTangents(P){pscalculate{x/2}}(Q){pscalculate{(8-x)/2}}
          pstInterLL{CircleTO1}{CircleTO2}{A}{B}{X}
          pstInterLL{CircleTO1}{CircleTO2}{C}{D}{Y}
          pspolygon*[linecolor=lightgray](X)(B)(D|B)(D)(Y)
          pcline[nodesep=-2](CircleTO1)(CircleTO2)
          psframe(D|B)
          psline(A)(B)
          psline(C)(D)
          pscircle(P){pscalculate{x/2}}
          pscircle(Q){pscalculate{(8-x)/2}}
          rput(A|D){psframe(12pt,12pt)}
          rput{90}(D){psframe(12pt,12pt)}
          rput{-90}(B){psframe(12pt,12pt)}
          rput{180}(D|B){psframe(12pt,12pt)}
          rput(Q|P){$S_x$}
          pcline{<-}([angle=225,nodesep=pscalculate{x/2}]P)(P)naput{$r_2$}
          pcline{<-}([angle=225,nodesep=pscalculate{(8-x)/2}]Q)(Q)naput{$r_1$}
          endpspicture}
          end{document}


          enter image description here






          share|improve this answer

























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "85"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f464139%2ftikz-the-common-tangent-and-the-shaded-region%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            14














            Let me start by repeating the nice solution by LoopSpace, to whom I give full credit for the first part.



            documentclass[tikz, border=1cm]{standalone}
            usetikzlibrary{calc}
            begin{document}
            begin{tikzpicture}
            coordinate (A) at (0,0);
            coordinate (B) at (0,7);
            coordinate (C) at (7,7);
            coordinate (D) at (7,0);
            coordinate (E) at (0,4);
            coordinate (F) at (3,7);
            coordinate (G) at (7,4);
            coordinate (H) at (3,0);
            coordinate (M) at (5,2);
            coordinate (N) at (1.5,5.5);
            draw (A)--(B)--(C)--(D)--cycle;
            draw (E)--(G);
            draw (F)--(H);
            pgfmathsetmacro{rone}{1.5}
            pgfmathsetmacro{rtwo}{2}
            pgfmathsetmacro{mid}{rone/(rone + rtwo)}
            pgfmathsetmacro{out}{rone/(rone - rtwo)}
            node[circle,minimum size=2*rone*1cm,draw] (c1) at (N){};
            node[circle,minimum size=2*rtwo*1cm,draw] (c2) at (M){};
            path (c1.center) -- node[coordinate,pos=mid] (mid) {} (c2.center);
            path (c1.center) -- node[coordinate,pos=out] (out) {} (c2.center);
            foreach i in {1,2}
            {foreach j in {1,2}
            {foreach k in {mid,out}
            {coordinate (tijk) at (tangent cs:node=ci,point={(k)},solution=j);}}}
            foreach i in {2}
            {
            draw[red] ($(t1i out)!-1cm!(t2i out)$) -- ($(t2i out)!-1cm!(t1i out)$);
            }

            end{tikzpicture}
            end{document}


            enter image description here



            However, this setup is so simple that I cannot refrain from adding an analytic determination of the tangent. (The other possible tangents can be added completely analogously). The observations that go into the analytic determination are




            1. The slope of the tangent is given by the slope of the line connecting the centers of the circles plus the ratio of the difference of the radii and the distance of the centers.

            2. Given the slope, the respective points on the circle are uniquely determined (modulo 180).


            One thus arrives at



            documentclass[tikz, border=1cm]{standalone}
            usetikzlibrary{calc,backgrounds}
            begin{document}
            begin{tikzpicture}[tangent of circles/.style args={%
            at #1 and #2 with radii #3 and #4}{insert path={%
            let p1=($(#2)-(#1)$),n1={atan2(y1,x1)},n2={veclen(y1,x1)*1pt/1cm},
            n3={atan2(#4-#3,n2)}
            in ($(#1)+(n3+n1+90:#3)$) -- ($(#2)+(n3+n1+90:#4)$)}}]
            coordinate (A) at (0,0);
            coordinate (B) at (0,7);
            coordinate (C) at (7,7);
            coordinate (D) at (7,0);
            coordinate (E) at (0,4);
            coordinate (F) at (3,7);
            coordinate (G) at (7,4);
            coordinate (H) at (3,0);
            coordinate (M) at (5,2);
            coordinate (N) at (1.5,5.5);
            draw (A)--(B)--(C)--(D)--cycle;
            draw (E)--(G);
            draw (F)--(H);
            draw (N) circle [radius=1.5];
            draw (M) circle [radius=2];
            path[tangent of circles={at N and M with radii 1.5 and 2}]
            coordinate[pos=0] (aux0) coordinate[pos=1] (aux1);
            % extend the tangent
            draw (intersection cs:first line={(aux0)--(aux1)}, second line={(C)--(D)})
            -- (intersection cs:first line={(aux0)--(aux1)}, second line={(C)--(B)});
            % fill the region above right of the tangent
            begin{scope}[on background layer]
            fill[gray!50] (intersection cs:first line={(aux0)--(aux1)},
            second line={(E)--(G)}) -| (C) -|
            (intersection cs:first line={(aux0)--(aux1)}, second line={(F)--(H)})
            -- cycle;
            end{scope}
            % draw the little squares
            draw[fill=gray!20] (C) rectangle ++ (-0.4,-0.4)
            (F) rectangle ++ (0.4,-0.4)
            (G) rectangle ++ (-0.4,0.4)
            (intersection cs:first line={(E)--(G)}, second line={(F)--(H)})
            rectangle ++ (0.4,0.4);
            draw[fill,thick,-latex] (N) circle (1pt) -- ++(225:1.5) node[midway,above
            left]
            {$vec r_2$};
            draw[fill,thick,-latex] (M) circle (1pt) -- ++(225:2) node[midway,above
            left]
            {$vec r_1$};
            node at (barycentric cs:C=1,G=1,F=1) {$S_x$};
            end{tikzpicture}
            end{document}


            enter image description here



            Let me mention that I made no effort in shortening the code. One could kick out some coordinates, but I do not see any point in this. IMHO it would make the code just harder to understand.






            share|improve this answer


























            • The remaining annotation may be added with node at (barycentric cs:C=1,G=1,F=1) {$S_x$};.

              – marmot
              Dec 10 '18 at 17:22






            • 1





              @blackened I changed it (and also moved the labels, as suggested by Artificial Stupidity). However, I do not add an animation, if you want an animation, see here, and wait for a PSTricks variant ;-)

              – marmot
              Dec 10 '18 at 18:49


















            14














            Let me start by repeating the nice solution by LoopSpace, to whom I give full credit for the first part.



            documentclass[tikz, border=1cm]{standalone}
            usetikzlibrary{calc}
            begin{document}
            begin{tikzpicture}
            coordinate (A) at (0,0);
            coordinate (B) at (0,7);
            coordinate (C) at (7,7);
            coordinate (D) at (7,0);
            coordinate (E) at (0,4);
            coordinate (F) at (3,7);
            coordinate (G) at (7,4);
            coordinate (H) at (3,0);
            coordinate (M) at (5,2);
            coordinate (N) at (1.5,5.5);
            draw (A)--(B)--(C)--(D)--cycle;
            draw (E)--(G);
            draw (F)--(H);
            pgfmathsetmacro{rone}{1.5}
            pgfmathsetmacro{rtwo}{2}
            pgfmathsetmacro{mid}{rone/(rone + rtwo)}
            pgfmathsetmacro{out}{rone/(rone - rtwo)}
            node[circle,minimum size=2*rone*1cm,draw] (c1) at (N){};
            node[circle,minimum size=2*rtwo*1cm,draw] (c2) at (M){};
            path (c1.center) -- node[coordinate,pos=mid] (mid) {} (c2.center);
            path (c1.center) -- node[coordinate,pos=out] (out) {} (c2.center);
            foreach i in {1,2}
            {foreach j in {1,2}
            {foreach k in {mid,out}
            {coordinate (tijk) at (tangent cs:node=ci,point={(k)},solution=j);}}}
            foreach i in {2}
            {
            draw[red] ($(t1i out)!-1cm!(t2i out)$) -- ($(t2i out)!-1cm!(t1i out)$);
            }

            end{tikzpicture}
            end{document}


            enter image description here



            However, this setup is so simple that I cannot refrain from adding an analytic determination of the tangent. (The other possible tangents can be added completely analogously). The observations that go into the analytic determination are




            1. The slope of the tangent is given by the slope of the line connecting the centers of the circles plus the ratio of the difference of the radii and the distance of the centers.

            2. Given the slope, the respective points on the circle are uniquely determined (modulo 180).


            One thus arrives at



            documentclass[tikz, border=1cm]{standalone}
            usetikzlibrary{calc,backgrounds}
            begin{document}
            begin{tikzpicture}[tangent of circles/.style args={%
            at #1 and #2 with radii #3 and #4}{insert path={%
            let p1=($(#2)-(#1)$),n1={atan2(y1,x1)},n2={veclen(y1,x1)*1pt/1cm},
            n3={atan2(#4-#3,n2)}
            in ($(#1)+(n3+n1+90:#3)$) -- ($(#2)+(n3+n1+90:#4)$)}}]
            coordinate (A) at (0,0);
            coordinate (B) at (0,7);
            coordinate (C) at (7,7);
            coordinate (D) at (7,0);
            coordinate (E) at (0,4);
            coordinate (F) at (3,7);
            coordinate (G) at (7,4);
            coordinate (H) at (3,0);
            coordinate (M) at (5,2);
            coordinate (N) at (1.5,5.5);
            draw (A)--(B)--(C)--(D)--cycle;
            draw (E)--(G);
            draw (F)--(H);
            draw (N) circle [radius=1.5];
            draw (M) circle [radius=2];
            path[tangent of circles={at N and M with radii 1.5 and 2}]
            coordinate[pos=0] (aux0) coordinate[pos=1] (aux1);
            % extend the tangent
            draw (intersection cs:first line={(aux0)--(aux1)}, second line={(C)--(D)})
            -- (intersection cs:first line={(aux0)--(aux1)}, second line={(C)--(B)});
            % fill the region above right of the tangent
            begin{scope}[on background layer]
            fill[gray!50] (intersection cs:first line={(aux0)--(aux1)},
            second line={(E)--(G)}) -| (C) -|
            (intersection cs:first line={(aux0)--(aux1)}, second line={(F)--(H)})
            -- cycle;
            end{scope}
            % draw the little squares
            draw[fill=gray!20] (C) rectangle ++ (-0.4,-0.4)
            (F) rectangle ++ (0.4,-0.4)
            (G) rectangle ++ (-0.4,0.4)
            (intersection cs:first line={(E)--(G)}, second line={(F)--(H)})
            rectangle ++ (0.4,0.4);
            draw[fill,thick,-latex] (N) circle (1pt) -- ++(225:1.5) node[midway,above
            left]
            {$vec r_2$};
            draw[fill,thick,-latex] (M) circle (1pt) -- ++(225:2) node[midway,above
            left]
            {$vec r_1$};
            node at (barycentric cs:C=1,G=1,F=1) {$S_x$};
            end{tikzpicture}
            end{document}


            enter image description here



            Let me mention that I made no effort in shortening the code. One could kick out some coordinates, but I do not see any point in this. IMHO it would make the code just harder to understand.






            share|improve this answer


























            • The remaining annotation may be added with node at (barycentric cs:C=1,G=1,F=1) {$S_x$};.

              – marmot
              Dec 10 '18 at 17:22






            • 1





              @blackened I changed it (and also moved the labels, as suggested by Artificial Stupidity). However, I do not add an animation, if you want an animation, see here, and wait for a PSTricks variant ;-)

              – marmot
              Dec 10 '18 at 18:49
















            14












            14








            14







            Let me start by repeating the nice solution by LoopSpace, to whom I give full credit for the first part.



            documentclass[tikz, border=1cm]{standalone}
            usetikzlibrary{calc}
            begin{document}
            begin{tikzpicture}
            coordinate (A) at (0,0);
            coordinate (B) at (0,7);
            coordinate (C) at (7,7);
            coordinate (D) at (7,0);
            coordinate (E) at (0,4);
            coordinate (F) at (3,7);
            coordinate (G) at (7,4);
            coordinate (H) at (3,0);
            coordinate (M) at (5,2);
            coordinate (N) at (1.5,5.5);
            draw (A)--(B)--(C)--(D)--cycle;
            draw (E)--(G);
            draw (F)--(H);
            pgfmathsetmacro{rone}{1.5}
            pgfmathsetmacro{rtwo}{2}
            pgfmathsetmacro{mid}{rone/(rone + rtwo)}
            pgfmathsetmacro{out}{rone/(rone - rtwo)}
            node[circle,minimum size=2*rone*1cm,draw] (c1) at (N){};
            node[circle,minimum size=2*rtwo*1cm,draw] (c2) at (M){};
            path (c1.center) -- node[coordinate,pos=mid] (mid) {} (c2.center);
            path (c1.center) -- node[coordinate,pos=out] (out) {} (c2.center);
            foreach i in {1,2}
            {foreach j in {1,2}
            {foreach k in {mid,out}
            {coordinate (tijk) at (tangent cs:node=ci,point={(k)},solution=j);}}}
            foreach i in {2}
            {
            draw[red] ($(t1i out)!-1cm!(t2i out)$) -- ($(t2i out)!-1cm!(t1i out)$);
            }

            end{tikzpicture}
            end{document}


            enter image description here



            However, this setup is so simple that I cannot refrain from adding an analytic determination of the tangent. (The other possible tangents can be added completely analogously). The observations that go into the analytic determination are




            1. The slope of the tangent is given by the slope of the line connecting the centers of the circles plus the ratio of the difference of the radii and the distance of the centers.

            2. Given the slope, the respective points on the circle are uniquely determined (modulo 180).


            One thus arrives at



            documentclass[tikz, border=1cm]{standalone}
            usetikzlibrary{calc,backgrounds}
            begin{document}
            begin{tikzpicture}[tangent of circles/.style args={%
            at #1 and #2 with radii #3 and #4}{insert path={%
            let p1=($(#2)-(#1)$),n1={atan2(y1,x1)},n2={veclen(y1,x1)*1pt/1cm},
            n3={atan2(#4-#3,n2)}
            in ($(#1)+(n3+n1+90:#3)$) -- ($(#2)+(n3+n1+90:#4)$)}}]
            coordinate (A) at (0,0);
            coordinate (B) at (0,7);
            coordinate (C) at (7,7);
            coordinate (D) at (7,0);
            coordinate (E) at (0,4);
            coordinate (F) at (3,7);
            coordinate (G) at (7,4);
            coordinate (H) at (3,0);
            coordinate (M) at (5,2);
            coordinate (N) at (1.5,5.5);
            draw (A)--(B)--(C)--(D)--cycle;
            draw (E)--(G);
            draw (F)--(H);
            draw (N) circle [radius=1.5];
            draw (M) circle [radius=2];
            path[tangent of circles={at N and M with radii 1.5 and 2}]
            coordinate[pos=0] (aux0) coordinate[pos=1] (aux1);
            % extend the tangent
            draw (intersection cs:first line={(aux0)--(aux1)}, second line={(C)--(D)})
            -- (intersection cs:first line={(aux0)--(aux1)}, second line={(C)--(B)});
            % fill the region above right of the tangent
            begin{scope}[on background layer]
            fill[gray!50] (intersection cs:first line={(aux0)--(aux1)},
            second line={(E)--(G)}) -| (C) -|
            (intersection cs:first line={(aux0)--(aux1)}, second line={(F)--(H)})
            -- cycle;
            end{scope}
            % draw the little squares
            draw[fill=gray!20] (C) rectangle ++ (-0.4,-0.4)
            (F) rectangle ++ (0.4,-0.4)
            (G) rectangle ++ (-0.4,0.4)
            (intersection cs:first line={(E)--(G)}, second line={(F)--(H)})
            rectangle ++ (0.4,0.4);
            draw[fill,thick,-latex] (N) circle (1pt) -- ++(225:1.5) node[midway,above
            left]
            {$vec r_2$};
            draw[fill,thick,-latex] (M) circle (1pt) -- ++(225:2) node[midway,above
            left]
            {$vec r_1$};
            node at (barycentric cs:C=1,G=1,F=1) {$S_x$};
            end{tikzpicture}
            end{document}


            enter image description here



            Let me mention that I made no effort in shortening the code. One could kick out some coordinates, but I do not see any point in this. IMHO it would make the code just harder to understand.






            share|improve this answer















            Let me start by repeating the nice solution by LoopSpace, to whom I give full credit for the first part.



            documentclass[tikz, border=1cm]{standalone}
            usetikzlibrary{calc}
            begin{document}
            begin{tikzpicture}
            coordinate (A) at (0,0);
            coordinate (B) at (0,7);
            coordinate (C) at (7,7);
            coordinate (D) at (7,0);
            coordinate (E) at (0,4);
            coordinate (F) at (3,7);
            coordinate (G) at (7,4);
            coordinate (H) at (3,0);
            coordinate (M) at (5,2);
            coordinate (N) at (1.5,5.5);
            draw (A)--(B)--(C)--(D)--cycle;
            draw (E)--(G);
            draw (F)--(H);
            pgfmathsetmacro{rone}{1.5}
            pgfmathsetmacro{rtwo}{2}
            pgfmathsetmacro{mid}{rone/(rone + rtwo)}
            pgfmathsetmacro{out}{rone/(rone - rtwo)}
            node[circle,minimum size=2*rone*1cm,draw] (c1) at (N){};
            node[circle,minimum size=2*rtwo*1cm,draw] (c2) at (M){};
            path (c1.center) -- node[coordinate,pos=mid] (mid) {} (c2.center);
            path (c1.center) -- node[coordinate,pos=out] (out) {} (c2.center);
            foreach i in {1,2}
            {foreach j in {1,2}
            {foreach k in {mid,out}
            {coordinate (tijk) at (tangent cs:node=ci,point={(k)},solution=j);}}}
            foreach i in {2}
            {
            draw[red] ($(t1i out)!-1cm!(t2i out)$) -- ($(t2i out)!-1cm!(t1i out)$);
            }

            end{tikzpicture}
            end{document}


            enter image description here



            However, this setup is so simple that I cannot refrain from adding an analytic determination of the tangent. (The other possible tangents can be added completely analogously). The observations that go into the analytic determination are




            1. The slope of the tangent is given by the slope of the line connecting the centers of the circles plus the ratio of the difference of the radii and the distance of the centers.

            2. Given the slope, the respective points on the circle are uniquely determined (modulo 180).


            One thus arrives at



            documentclass[tikz, border=1cm]{standalone}
            usetikzlibrary{calc,backgrounds}
            begin{document}
            begin{tikzpicture}[tangent of circles/.style args={%
            at #1 and #2 with radii #3 and #4}{insert path={%
            let p1=($(#2)-(#1)$),n1={atan2(y1,x1)},n2={veclen(y1,x1)*1pt/1cm},
            n3={atan2(#4-#3,n2)}
            in ($(#1)+(n3+n1+90:#3)$) -- ($(#2)+(n3+n1+90:#4)$)}}]
            coordinate (A) at (0,0);
            coordinate (B) at (0,7);
            coordinate (C) at (7,7);
            coordinate (D) at (7,0);
            coordinate (E) at (0,4);
            coordinate (F) at (3,7);
            coordinate (G) at (7,4);
            coordinate (H) at (3,0);
            coordinate (M) at (5,2);
            coordinate (N) at (1.5,5.5);
            draw (A)--(B)--(C)--(D)--cycle;
            draw (E)--(G);
            draw (F)--(H);
            draw (N) circle [radius=1.5];
            draw (M) circle [radius=2];
            path[tangent of circles={at N and M with radii 1.5 and 2}]
            coordinate[pos=0] (aux0) coordinate[pos=1] (aux1);
            % extend the tangent
            draw (intersection cs:first line={(aux0)--(aux1)}, second line={(C)--(D)})
            -- (intersection cs:first line={(aux0)--(aux1)}, second line={(C)--(B)});
            % fill the region above right of the tangent
            begin{scope}[on background layer]
            fill[gray!50] (intersection cs:first line={(aux0)--(aux1)},
            second line={(E)--(G)}) -| (C) -|
            (intersection cs:first line={(aux0)--(aux1)}, second line={(F)--(H)})
            -- cycle;
            end{scope}
            % draw the little squares
            draw[fill=gray!20] (C) rectangle ++ (-0.4,-0.4)
            (F) rectangle ++ (0.4,-0.4)
            (G) rectangle ++ (-0.4,0.4)
            (intersection cs:first line={(E)--(G)}, second line={(F)--(H)})
            rectangle ++ (0.4,0.4);
            draw[fill,thick,-latex] (N) circle (1pt) -- ++(225:1.5) node[midway,above
            left]
            {$vec r_2$};
            draw[fill,thick,-latex] (M) circle (1pt) -- ++(225:2) node[midway,above
            left]
            {$vec r_1$};
            node at (barycentric cs:C=1,G=1,F=1) {$S_x$};
            end{tikzpicture}
            end{document}


            enter image description here



            Let me mention that I made no effort in shortening the code. One could kick out some coordinates, but I do not see any point in this. IMHO it would make the code just harder to understand.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Dec 10 '18 at 18:47

























            answered Dec 10 '18 at 14:43









            marmotmarmot

            101k4116223




            101k4116223













            • The remaining annotation may be added with node at (barycentric cs:C=1,G=1,F=1) {$S_x$};.

              – marmot
              Dec 10 '18 at 17:22






            • 1





              @blackened I changed it (and also moved the labels, as suggested by Artificial Stupidity). However, I do not add an animation, if you want an animation, see here, and wait for a PSTricks variant ;-)

              – marmot
              Dec 10 '18 at 18:49





















            • The remaining annotation may be added with node at (barycentric cs:C=1,G=1,F=1) {$S_x$};.

              – marmot
              Dec 10 '18 at 17:22






            • 1





              @blackened I changed it (and also moved the labels, as suggested by Artificial Stupidity). However, I do not add an animation, if you want an animation, see here, and wait for a PSTricks variant ;-)

              – marmot
              Dec 10 '18 at 18:49



















            The remaining annotation may be added with node at (barycentric cs:C=1,G=1,F=1) {$S_x$};.

            – marmot
            Dec 10 '18 at 17:22





            The remaining annotation may be added with node at (barycentric cs:C=1,G=1,F=1) {$S_x$};.

            – marmot
            Dec 10 '18 at 17:22




            1




            1





            @blackened I changed it (and also moved the labels, as suggested by Artificial Stupidity). However, I do not add an animation, if you want an animation, see here, and wait for a PSTricks variant ;-)

            – marmot
            Dec 10 '18 at 18:49







            @blackened I changed it (and also moved the labels, as suggested by Artificial Stupidity). However, I do not add an animation, if you want an animation, see here, and wait for a PSTricks variant ;-)

            – marmot
            Dec 10 '18 at 18:49













            8














            A PSTricks solution only for comparison purposes.



            documentclass[pstricks,border=12pt,12pt]{standalone}
            usepackage{pstricks-add,pst-eucl}
            begin{document}
            pspicture[PointName=none,PointSymbol=none](8,8)
            pnodes(4,0){A}(4,8){B}(0,4){C}(8,4){D}(2,6){P}(6,2){Q}
            psCircleTangents(P){2}(Q){2}
            pstInterLL{CircleTO1}{CircleTO2}{A}{B}{X}
            pstInterLL{CircleTO1}{CircleTO2}{C}{D}{Y}
            pspolygon*[linecolor=lightgray](X)(B)(D|B)(D)(Y)
            pcline[nodesep=-1.2](CircleTO1)(CircleTO2)
            psframe(D|B)
            psline(A)(B)
            psline(C)(D)
            pscircle(P){2}
            pscircle(Q){2}
            rput(A|D){psframe(12pt,12pt)}
            rput{90}(D){psframe(12pt,12pt)}
            rput{-90}(B){psframe(12pt,12pt)}
            rput{180}(D|B){psframe(12pt,12pt)}
            rput(Q|P){$S_x$}
            pcline{<-}([angle=225,nodesep=2]P)(P)naput{$r_2$}
            pcline{<-}([angle=225,nodesep=2]Q)(Q)naput{$r_1$}
            endpspicture
            end{document}


            enter image description here



            Different Radii



            documentclass[pstricks,border=12pt,12pt]{standalone}
            usepackage{pstricks-add,pst-eucl,pst-calculate}

            begin{document}
            foreach x in {4,4.5,...,6.0}{%
            pspicture[PointName=none,PointSymbol=none](8,8)
            pnodes(x,0){A}(A|0,8){B}(!0 8 xspace sub){C}(8,0|C){D}(!xspace 2 div dup neg 8 add){P}(!xspace 2 div dup 4 add exch neg 4 add){Q}
            psCircleTangents(P){pscalculate{x/2}}(Q){pscalculate{(8-x)/2}}
            pstInterLL{CircleTO1}{CircleTO2}{A}{B}{X}
            pstInterLL{CircleTO1}{CircleTO2}{C}{D}{Y}
            pspolygon*[linecolor=lightgray](X)(B)(D|B)(D)(Y)
            pcline[nodesep=-2](CircleTO1)(CircleTO2)
            psframe(D|B)
            psline(A)(B)
            psline(C)(D)
            pscircle(P){pscalculate{x/2}}
            pscircle(Q){pscalculate{(8-x)/2}}
            rput(A|D){psframe(12pt,12pt)}
            rput{90}(D){psframe(12pt,12pt)}
            rput{-90}(B){psframe(12pt,12pt)}
            rput{180}(D|B){psframe(12pt,12pt)}
            rput(Q|P){$S_x$}
            pcline{<-}([angle=225,nodesep=pscalculate{x/2}]P)(P)naput{$r_2$}
            pcline{<-}([angle=225,nodesep=pscalculate{(8-x)/2}]Q)(Q)naput{$r_1$}
            endpspicture}
            end{document}


            enter image description here






            share|improve this answer






























              8














              A PSTricks solution only for comparison purposes.



              documentclass[pstricks,border=12pt,12pt]{standalone}
              usepackage{pstricks-add,pst-eucl}
              begin{document}
              pspicture[PointName=none,PointSymbol=none](8,8)
              pnodes(4,0){A}(4,8){B}(0,4){C}(8,4){D}(2,6){P}(6,2){Q}
              psCircleTangents(P){2}(Q){2}
              pstInterLL{CircleTO1}{CircleTO2}{A}{B}{X}
              pstInterLL{CircleTO1}{CircleTO2}{C}{D}{Y}
              pspolygon*[linecolor=lightgray](X)(B)(D|B)(D)(Y)
              pcline[nodesep=-1.2](CircleTO1)(CircleTO2)
              psframe(D|B)
              psline(A)(B)
              psline(C)(D)
              pscircle(P){2}
              pscircle(Q){2}
              rput(A|D){psframe(12pt,12pt)}
              rput{90}(D){psframe(12pt,12pt)}
              rput{-90}(B){psframe(12pt,12pt)}
              rput{180}(D|B){psframe(12pt,12pt)}
              rput(Q|P){$S_x$}
              pcline{<-}([angle=225,nodesep=2]P)(P)naput{$r_2$}
              pcline{<-}([angle=225,nodesep=2]Q)(Q)naput{$r_1$}
              endpspicture
              end{document}


              enter image description here



              Different Radii



              documentclass[pstricks,border=12pt,12pt]{standalone}
              usepackage{pstricks-add,pst-eucl,pst-calculate}

              begin{document}
              foreach x in {4,4.5,...,6.0}{%
              pspicture[PointName=none,PointSymbol=none](8,8)
              pnodes(x,0){A}(A|0,8){B}(!0 8 xspace sub){C}(8,0|C){D}(!xspace 2 div dup neg 8 add){P}(!xspace 2 div dup 4 add exch neg 4 add){Q}
              psCircleTangents(P){pscalculate{x/2}}(Q){pscalculate{(8-x)/2}}
              pstInterLL{CircleTO1}{CircleTO2}{A}{B}{X}
              pstInterLL{CircleTO1}{CircleTO2}{C}{D}{Y}
              pspolygon*[linecolor=lightgray](X)(B)(D|B)(D)(Y)
              pcline[nodesep=-2](CircleTO1)(CircleTO2)
              psframe(D|B)
              psline(A)(B)
              psline(C)(D)
              pscircle(P){pscalculate{x/2}}
              pscircle(Q){pscalculate{(8-x)/2}}
              rput(A|D){psframe(12pt,12pt)}
              rput{90}(D){psframe(12pt,12pt)}
              rput{-90}(B){psframe(12pt,12pt)}
              rput{180}(D|B){psframe(12pt,12pt)}
              rput(Q|P){$S_x$}
              pcline{<-}([angle=225,nodesep=pscalculate{x/2}]P)(P)naput{$r_2$}
              pcline{<-}([angle=225,nodesep=pscalculate{(8-x)/2}]Q)(Q)naput{$r_1$}
              endpspicture}
              end{document}


              enter image description here






              share|improve this answer




























                8












                8








                8







                A PSTricks solution only for comparison purposes.



                documentclass[pstricks,border=12pt,12pt]{standalone}
                usepackage{pstricks-add,pst-eucl}
                begin{document}
                pspicture[PointName=none,PointSymbol=none](8,8)
                pnodes(4,0){A}(4,8){B}(0,4){C}(8,4){D}(2,6){P}(6,2){Q}
                psCircleTangents(P){2}(Q){2}
                pstInterLL{CircleTO1}{CircleTO2}{A}{B}{X}
                pstInterLL{CircleTO1}{CircleTO2}{C}{D}{Y}
                pspolygon*[linecolor=lightgray](X)(B)(D|B)(D)(Y)
                pcline[nodesep=-1.2](CircleTO1)(CircleTO2)
                psframe(D|B)
                psline(A)(B)
                psline(C)(D)
                pscircle(P){2}
                pscircle(Q){2}
                rput(A|D){psframe(12pt,12pt)}
                rput{90}(D){psframe(12pt,12pt)}
                rput{-90}(B){psframe(12pt,12pt)}
                rput{180}(D|B){psframe(12pt,12pt)}
                rput(Q|P){$S_x$}
                pcline{<-}([angle=225,nodesep=2]P)(P)naput{$r_2$}
                pcline{<-}([angle=225,nodesep=2]Q)(Q)naput{$r_1$}
                endpspicture
                end{document}


                enter image description here



                Different Radii



                documentclass[pstricks,border=12pt,12pt]{standalone}
                usepackage{pstricks-add,pst-eucl,pst-calculate}

                begin{document}
                foreach x in {4,4.5,...,6.0}{%
                pspicture[PointName=none,PointSymbol=none](8,8)
                pnodes(x,0){A}(A|0,8){B}(!0 8 xspace sub){C}(8,0|C){D}(!xspace 2 div dup neg 8 add){P}(!xspace 2 div dup 4 add exch neg 4 add){Q}
                psCircleTangents(P){pscalculate{x/2}}(Q){pscalculate{(8-x)/2}}
                pstInterLL{CircleTO1}{CircleTO2}{A}{B}{X}
                pstInterLL{CircleTO1}{CircleTO2}{C}{D}{Y}
                pspolygon*[linecolor=lightgray](X)(B)(D|B)(D)(Y)
                pcline[nodesep=-2](CircleTO1)(CircleTO2)
                psframe(D|B)
                psline(A)(B)
                psline(C)(D)
                pscircle(P){pscalculate{x/2}}
                pscircle(Q){pscalculate{(8-x)/2}}
                rput(A|D){psframe(12pt,12pt)}
                rput{90}(D){psframe(12pt,12pt)}
                rput{-90}(B){psframe(12pt,12pt)}
                rput{180}(D|B){psframe(12pt,12pt)}
                rput(Q|P){$S_x$}
                pcline{<-}([angle=225,nodesep=pscalculate{x/2}]P)(P)naput{$r_2$}
                pcline{<-}([angle=225,nodesep=pscalculate{(8-x)/2}]Q)(Q)naput{$r_1$}
                endpspicture}
                end{document}


                enter image description here






                share|improve this answer















                A PSTricks solution only for comparison purposes.



                documentclass[pstricks,border=12pt,12pt]{standalone}
                usepackage{pstricks-add,pst-eucl}
                begin{document}
                pspicture[PointName=none,PointSymbol=none](8,8)
                pnodes(4,0){A}(4,8){B}(0,4){C}(8,4){D}(2,6){P}(6,2){Q}
                psCircleTangents(P){2}(Q){2}
                pstInterLL{CircleTO1}{CircleTO2}{A}{B}{X}
                pstInterLL{CircleTO1}{CircleTO2}{C}{D}{Y}
                pspolygon*[linecolor=lightgray](X)(B)(D|B)(D)(Y)
                pcline[nodesep=-1.2](CircleTO1)(CircleTO2)
                psframe(D|B)
                psline(A)(B)
                psline(C)(D)
                pscircle(P){2}
                pscircle(Q){2}
                rput(A|D){psframe(12pt,12pt)}
                rput{90}(D){psframe(12pt,12pt)}
                rput{-90}(B){psframe(12pt,12pt)}
                rput{180}(D|B){psframe(12pt,12pt)}
                rput(Q|P){$S_x$}
                pcline{<-}([angle=225,nodesep=2]P)(P)naput{$r_2$}
                pcline{<-}([angle=225,nodesep=2]Q)(Q)naput{$r_1$}
                endpspicture
                end{document}


                enter image description here



                Different Radii



                documentclass[pstricks,border=12pt,12pt]{standalone}
                usepackage{pstricks-add,pst-eucl,pst-calculate}

                begin{document}
                foreach x in {4,4.5,...,6.0}{%
                pspicture[PointName=none,PointSymbol=none](8,8)
                pnodes(x,0){A}(A|0,8){B}(!0 8 xspace sub){C}(8,0|C){D}(!xspace 2 div dup neg 8 add){P}(!xspace 2 div dup 4 add exch neg 4 add){Q}
                psCircleTangents(P){pscalculate{x/2}}(Q){pscalculate{(8-x)/2}}
                pstInterLL{CircleTO1}{CircleTO2}{A}{B}{X}
                pstInterLL{CircleTO1}{CircleTO2}{C}{D}{Y}
                pspolygon*[linecolor=lightgray](X)(B)(D|B)(D)(Y)
                pcline[nodesep=-2](CircleTO1)(CircleTO2)
                psframe(D|B)
                psline(A)(B)
                psline(C)(D)
                pscircle(P){pscalculate{x/2}}
                pscircle(Q){pscalculate{(8-x)/2}}
                rput(A|D){psframe(12pt,12pt)}
                rput{90}(D){psframe(12pt,12pt)}
                rput{-90}(B){psframe(12pt,12pt)}
                rput{180}(D|B){psframe(12pt,12pt)}
                rput(Q|P){$S_x$}
                pcline{<-}([angle=225,nodesep=pscalculate{x/2}]P)(P)naput{$r_2$}
                pcline{<-}([angle=225,nodesep=pscalculate{(8-x)/2}]Q)(Q)naput{$r_1$}
                endpspicture}
                end{document}


                enter image description here







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Dec 10 '18 at 17:35

























                answered Dec 10 '18 at 14:59









                Artificial StupidityArtificial Stupidity

                5,35711041




                5,35711041






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f464139%2ftikz-the-common-tangent-and-the-shaded-region%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Bundesstraße 106

                    Verónica Boquete

                    Ida-Boy-Ed-Garten