Tikz picture using two “foreach” loops












9















I am making a picture using foreach. MWE is appended below



documentclass{article}

usepackage[svgnames]{xcolor}
usepackage{tikz}

begin{document}

begin{tikzpicture}

foreach x in {0,...,5}
draw [DodgerBlue](x,-1) circle (0.25);

foreach x in {0,...,5}
draw [-latex,red](x,-1) -- (x,-1.5);

foreach x in {0,...,5}
draw [-latex,DarkGreen](x,-1) -- (x,-0.5);

draw [ultra thin] (5,-0.5) -- (0,-1);

end{tikzpicture}

end{document}


The resulting picture is attached below



enter image description here



Now what I want is that the green arrows on the top should be limited by the black line diagonal line. That is for the first circle there should be no green arrow, and its length should increase until it becomes equal to the red arrow in the last circle. How can this be done using foreach using the variable y. Is there a way such that the intersection of the black diagonal line with the green arrows can be used to limit the length of the green arrows to the desired values? Or is there any other way to achieve this?










share|improve this question



























    9















    I am making a picture using foreach. MWE is appended below



    documentclass{article}

    usepackage[svgnames]{xcolor}
    usepackage{tikz}

    begin{document}

    begin{tikzpicture}

    foreach x in {0,...,5}
    draw [DodgerBlue](x,-1) circle (0.25);

    foreach x in {0,...,5}
    draw [-latex,red](x,-1) -- (x,-1.5);

    foreach x in {0,...,5}
    draw [-latex,DarkGreen](x,-1) -- (x,-0.5);

    draw [ultra thin] (5,-0.5) -- (0,-1);

    end{tikzpicture}

    end{document}


    The resulting picture is attached below



    enter image description here



    Now what I want is that the green arrows on the top should be limited by the black line diagonal line. That is for the first circle there should be no green arrow, and its length should increase until it becomes equal to the red arrow in the last circle. How can this be done using foreach using the variable y. Is there a way such that the intersection of the black diagonal line with the green arrows can be used to limit the length of the green arrows to the desired values? Or is there any other way to achieve this?










    share|improve this question

























      9












      9








      9








      I am making a picture using foreach. MWE is appended below



      documentclass{article}

      usepackage[svgnames]{xcolor}
      usepackage{tikz}

      begin{document}

      begin{tikzpicture}

      foreach x in {0,...,5}
      draw [DodgerBlue](x,-1) circle (0.25);

      foreach x in {0,...,5}
      draw [-latex,red](x,-1) -- (x,-1.5);

      foreach x in {0,...,5}
      draw [-latex,DarkGreen](x,-1) -- (x,-0.5);

      draw [ultra thin] (5,-0.5) -- (0,-1);

      end{tikzpicture}

      end{document}


      The resulting picture is attached below



      enter image description here



      Now what I want is that the green arrows on the top should be limited by the black line diagonal line. That is for the first circle there should be no green arrow, and its length should increase until it becomes equal to the red arrow in the last circle. How can this be done using foreach using the variable y. Is there a way such that the intersection of the black diagonal line with the green arrows can be used to limit the length of the green arrows to the desired values? Or is there any other way to achieve this?










      share|improve this question














      I am making a picture using foreach. MWE is appended below



      documentclass{article}

      usepackage[svgnames]{xcolor}
      usepackage{tikz}

      begin{document}

      begin{tikzpicture}

      foreach x in {0,...,5}
      draw [DodgerBlue](x,-1) circle (0.25);

      foreach x in {0,...,5}
      draw [-latex,red](x,-1) -- (x,-1.5);

      foreach x in {0,...,5}
      draw [-latex,DarkGreen](x,-1) -- (x,-0.5);

      draw [ultra thin] (5,-0.5) -- (0,-1);

      end{tikzpicture}

      end{document}


      The resulting picture is attached below



      enter image description here



      Now what I want is that the green arrows on the top should be limited by the black line diagonal line. That is for the first circle there should be no green arrow, and its length should increase until it becomes equal to the red arrow in the last circle. How can this be done using foreach using the variable y. Is there a way such that the intersection of the black diagonal line with the green arrows can be used to limit the length of the green arrows to the desired values? Or is there any other way to achieve this?







      tikz-pgf foreach






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 12 '18 at 10:49









      DamitrDamitr

      607413




      607413






















          5 Answers
          5






          active

          oldest

          votes


















          11














          In case you do not want to do analytic computations (or if you do not have a simple parametrization for the line).



          documentclass{article}

          usepackage[svgnames]{xcolor}
          usepackage{tikz}
          usetikzlibrary{calc}
          begin{document}

          begin{tikzpicture}

          foreach x in {0,...,5}
          draw [DodgerBlue](x,-1) circle (0.25);

          foreach x in {0,...,5}
          draw [-latex,red](x,-1) -- (x,-1.5) ;

          draw [ultra thin] (5,-0.5) coordinate(aux0) -- (0,-1) coordinate(aux1);

          foreach x in {1,...,5}
          draw [-latex,DarkGreen] (x,-1) coordinate(aux2) (x,-0.5) coordinate(aux3)
          (aux2) -- (intersection cs:first line={(aux2)--(aux3)},
          second line={(aux0)--(aux1)});


          end{tikzpicture}

          end{document}


          enter image description here



          To make @ArtificialStupidity happy (?) one loop...



          documentclass[border=3.14mm]{standalone}
          usepackage[svgnames]{xcolor}
          usepackage{tikz}
          usetikzlibrary{calc}
          begin{document}
          begin{tikzpicture}
          draw [ultra thin] (5,-0.5) coordinate(aux0) -- (0,-1) coordinate(aux1);
          foreach x in {0,...,5}
          { draw [DodgerBlue](x,-1) circle (0.25);
          draw [-latex,red](x,-1) -- (x,-1.5) ;
          unlessifnumx=0%
          draw [-latex,DarkGreen] (x,-1) coordinate(aux2) (x,-0.5) coordinate(aux3)
          (aux2) -- (intersection cs:first line={(aux2)--(aux3)},
          second line={(aux0)--(aux1)});
          fi
          }
          end{tikzpicture}
          end{document}





          share|improve this answer


























          • Using intersections is an interesting idea :)

            – TeXnician
            Dec 12 '18 at 11:11











          • @TeXnician These are actually those intersections that come with calc and do not require the intersections library. They are restricted to intersections of straight lines, though. (+1 to your analytic solution ;-)

            – marmot
            Dec 12 '18 at 11:13











          • I have used these "calc intersections" before, but I would not have thought of them in this case…

            – TeXnician
            Dec 12 '18 at 11:22






          • 1





            I am almost happy. The code is not so short and cryptic as mentioned before. :-)

            – Artificial Stupidity
            Dec 12 '18 at 16:07






          • 2





            @ArtificialStupidity Yes, but of course now it is no longer a valid answer to the question which in its title asks for two loops. (3 loops includes 2, of course ;-)

            – marmot
            Dec 12 '18 at 16:12



















          8














          You can use a simple linear function. Please note that your arrow heads are quite large in your scale. It might be a good idea to choose a larger scale or use another arrow tip to have a better representation of the second case.



          linear function



          documentclass{article}

          usepackage[svgnames]{xcolor}
          usepackage{tikz}

          begin{document}

          begin{tikzpicture}

          foreach x in {0,...,5}{
          draw [DodgerBlue](x,0) circle (0.25);
          draw [-latex,red](x,0) -- (x,-.5);
          }
          foreach x in {1,...,5}{
          draw [-latex,DarkGreen](x,0) -- (x,{0.1*x});
          }

          draw [ultra thin] (5,.5) -- (0,0);

          end{tikzpicture}

          end{document}





          share|improve this answer































            7














            A PSTricks solution with just one loop only for comparison purposes.



            documentclass[pstricks]{standalone}
            usepackage{pst-calculate}
            begin{document}
            begin{pspicture}[arrowsize=.2,arrowinset=0,linewidth=1pt](8.5,pscalculate{8/3})
            foreach i in {0,1,...,5}{%
            pstVerb{/x {ispace 1.5 mul .5 add} def}%
            pscircle[linecolor=blue](!x 1){.5}
            psline[linecolor=red]{->}(!x 1)(!x 0)
            ifnumi=0relaxelsepsline[linecolor=green]{->}(!x 1)(!x ispace 3 div 1 add)fi
            }
            psline[linestyle=dashed](.5,1)(!8 dup 3 div)
            end{pspicture}
            end{document}


            enter image description here






            share|improve this answer
























            • Thanks for upvoting my answer. Now I got a nice hat.

              – Artificial Stupidity
              Dec 12 '18 at 15:55



















            5














            one more with use of lines intersections, but defined with help of the package intersections:



            documentclass[tikz, svgnames, margin=3]{standalone}
            usetikzlibrary{intersections}

            begin{document}
            begin{tikzpicture}
            foreach x in {0,...,5}{
            draw [DodgerBlue](x,0) circle (0.25);
            draw [-latex,red](x,0) -- (x,-.5);
            }
            draw [ultra thin, name path=A] (5,.5) -- (0,0);
            foreach x in {1,...,5}
            {
            path[name path=Bx] (x,0) -- ++ (0,0.5);
            draw[-latex,DarkGreen,
            name intersections={of=A and Bx,by={Bx}}] (x,0) -- (Bx);
            }
            end{tikzpicture}
            end{document}


            enter image description here






            share|improve this answer































              4














              Like this (please observe foreach x in {1,...,5} instead of foreach x in {0,...,5}?



              documentclass{article}

              usepackage[svgnames]{xcolor}
              usepackage{tikz}

              begin{document}

              begin{tikzpicture}

              foreach x in {0,...,5}
              draw [DodgerBlue](x,-1) circle (0.25);

              foreach x in {0,...,5}
              draw [-latex,red](x,-1) -- (x,-1.5);

              %foreach x in {0,...,5}
              % draw [-latex,DarkGreen](x,-1) -- (x,-0.5);
              foreach x in {1,...,5}
              draw [-latex,DarkGreen](x,-1) -- (x,-1+0.1*x);

              draw [ultra thin] (5,-0.5) -- (0,-1);

              end{tikzpicture}

              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%2f464497%2ftikz-picture-using-two-foreach-loops%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                5 Answers
                5






                active

                oldest

                votes








                5 Answers
                5






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                11














                In case you do not want to do analytic computations (or if you do not have a simple parametrization for the line).



                documentclass{article}

                usepackage[svgnames]{xcolor}
                usepackage{tikz}
                usetikzlibrary{calc}
                begin{document}

                begin{tikzpicture}

                foreach x in {0,...,5}
                draw [DodgerBlue](x,-1) circle (0.25);

                foreach x in {0,...,5}
                draw [-latex,red](x,-1) -- (x,-1.5) ;

                draw [ultra thin] (5,-0.5) coordinate(aux0) -- (0,-1) coordinate(aux1);

                foreach x in {1,...,5}
                draw [-latex,DarkGreen] (x,-1) coordinate(aux2) (x,-0.5) coordinate(aux3)
                (aux2) -- (intersection cs:first line={(aux2)--(aux3)},
                second line={(aux0)--(aux1)});


                end{tikzpicture}

                end{document}


                enter image description here



                To make @ArtificialStupidity happy (?) one loop...



                documentclass[border=3.14mm]{standalone}
                usepackage[svgnames]{xcolor}
                usepackage{tikz}
                usetikzlibrary{calc}
                begin{document}
                begin{tikzpicture}
                draw [ultra thin] (5,-0.5) coordinate(aux0) -- (0,-1) coordinate(aux1);
                foreach x in {0,...,5}
                { draw [DodgerBlue](x,-1) circle (0.25);
                draw [-latex,red](x,-1) -- (x,-1.5) ;
                unlessifnumx=0%
                draw [-latex,DarkGreen] (x,-1) coordinate(aux2) (x,-0.5) coordinate(aux3)
                (aux2) -- (intersection cs:first line={(aux2)--(aux3)},
                second line={(aux0)--(aux1)});
                fi
                }
                end{tikzpicture}
                end{document}





                share|improve this answer


























                • Using intersections is an interesting idea :)

                  – TeXnician
                  Dec 12 '18 at 11:11











                • @TeXnician These are actually those intersections that come with calc and do not require the intersections library. They are restricted to intersections of straight lines, though. (+1 to your analytic solution ;-)

                  – marmot
                  Dec 12 '18 at 11:13











                • I have used these "calc intersections" before, but I would not have thought of them in this case…

                  – TeXnician
                  Dec 12 '18 at 11:22






                • 1





                  I am almost happy. The code is not so short and cryptic as mentioned before. :-)

                  – Artificial Stupidity
                  Dec 12 '18 at 16:07






                • 2





                  @ArtificialStupidity Yes, but of course now it is no longer a valid answer to the question which in its title asks for two loops. (3 loops includes 2, of course ;-)

                  – marmot
                  Dec 12 '18 at 16:12
















                11














                In case you do not want to do analytic computations (or if you do not have a simple parametrization for the line).



                documentclass{article}

                usepackage[svgnames]{xcolor}
                usepackage{tikz}
                usetikzlibrary{calc}
                begin{document}

                begin{tikzpicture}

                foreach x in {0,...,5}
                draw [DodgerBlue](x,-1) circle (0.25);

                foreach x in {0,...,5}
                draw [-latex,red](x,-1) -- (x,-1.5) ;

                draw [ultra thin] (5,-0.5) coordinate(aux0) -- (0,-1) coordinate(aux1);

                foreach x in {1,...,5}
                draw [-latex,DarkGreen] (x,-1) coordinate(aux2) (x,-0.5) coordinate(aux3)
                (aux2) -- (intersection cs:first line={(aux2)--(aux3)},
                second line={(aux0)--(aux1)});


                end{tikzpicture}

                end{document}


                enter image description here



                To make @ArtificialStupidity happy (?) one loop...



                documentclass[border=3.14mm]{standalone}
                usepackage[svgnames]{xcolor}
                usepackage{tikz}
                usetikzlibrary{calc}
                begin{document}
                begin{tikzpicture}
                draw [ultra thin] (5,-0.5) coordinate(aux0) -- (0,-1) coordinate(aux1);
                foreach x in {0,...,5}
                { draw [DodgerBlue](x,-1) circle (0.25);
                draw [-latex,red](x,-1) -- (x,-1.5) ;
                unlessifnumx=0%
                draw [-latex,DarkGreen] (x,-1) coordinate(aux2) (x,-0.5) coordinate(aux3)
                (aux2) -- (intersection cs:first line={(aux2)--(aux3)},
                second line={(aux0)--(aux1)});
                fi
                }
                end{tikzpicture}
                end{document}





                share|improve this answer


























                • Using intersections is an interesting idea :)

                  – TeXnician
                  Dec 12 '18 at 11:11











                • @TeXnician These are actually those intersections that come with calc and do not require the intersections library. They are restricted to intersections of straight lines, though. (+1 to your analytic solution ;-)

                  – marmot
                  Dec 12 '18 at 11:13











                • I have used these "calc intersections" before, but I would not have thought of them in this case…

                  – TeXnician
                  Dec 12 '18 at 11:22






                • 1





                  I am almost happy. The code is not so short and cryptic as mentioned before. :-)

                  – Artificial Stupidity
                  Dec 12 '18 at 16:07






                • 2





                  @ArtificialStupidity Yes, but of course now it is no longer a valid answer to the question which in its title asks for two loops. (3 loops includes 2, of course ;-)

                  – marmot
                  Dec 12 '18 at 16:12














                11












                11








                11







                In case you do not want to do analytic computations (or if you do not have a simple parametrization for the line).



                documentclass{article}

                usepackage[svgnames]{xcolor}
                usepackage{tikz}
                usetikzlibrary{calc}
                begin{document}

                begin{tikzpicture}

                foreach x in {0,...,5}
                draw [DodgerBlue](x,-1) circle (0.25);

                foreach x in {0,...,5}
                draw [-latex,red](x,-1) -- (x,-1.5) ;

                draw [ultra thin] (5,-0.5) coordinate(aux0) -- (0,-1) coordinate(aux1);

                foreach x in {1,...,5}
                draw [-latex,DarkGreen] (x,-1) coordinate(aux2) (x,-0.5) coordinate(aux3)
                (aux2) -- (intersection cs:first line={(aux2)--(aux3)},
                second line={(aux0)--(aux1)});


                end{tikzpicture}

                end{document}


                enter image description here



                To make @ArtificialStupidity happy (?) one loop...



                documentclass[border=3.14mm]{standalone}
                usepackage[svgnames]{xcolor}
                usepackage{tikz}
                usetikzlibrary{calc}
                begin{document}
                begin{tikzpicture}
                draw [ultra thin] (5,-0.5) coordinate(aux0) -- (0,-1) coordinate(aux1);
                foreach x in {0,...,5}
                { draw [DodgerBlue](x,-1) circle (0.25);
                draw [-latex,red](x,-1) -- (x,-1.5) ;
                unlessifnumx=0%
                draw [-latex,DarkGreen] (x,-1) coordinate(aux2) (x,-0.5) coordinate(aux3)
                (aux2) -- (intersection cs:first line={(aux2)--(aux3)},
                second line={(aux0)--(aux1)});
                fi
                }
                end{tikzpicture}
                end{document}





                share|improve this answer















                In case you do not want to do analytic computations (or if you do not have a simple parametrization for the line).



                documentclass{article}

                usepackage[svgnames]{xcolor}
                usepackage{tikz}
                usetikzlibrary{calc}
                begin{document}

                begin{tikzpicture}

                foreach x in {0,...,5}
                draw [DodgerBlue](x,-1) circle (0.25);

                foreach x in {0,...,5}
                draw [-latex,red](x,-1) -- (x,-1.5) ;

                draw [ultra thin] (5,-0.5) coordinate(aux0) -- (0,-1) coordinate(aux1);

                foreach x in {1,...,5}
                draw [-latex,DarkGreen] (x,-1) coordinate(aux2) (x,-0.5) coordinate(aux3)
                (aux2) -- (intersection cs:first line={(aux2)--(aux3)},
                second line={(aux0)--(aux1)});


                end{tikzpicture}

                end{document}


                enter image description here



                To make @ArtificialStupidity happy (?) one loop...



                documentclass[border=3.14mm]{standalone}
                usepackage[svgnames]{xcolor}
                usepackage{tikz}
                usetikzlibrary{calc}
                begin{document}
                begin{tikzpicture}
                draw [ultra thin] (5,-0.5) coordinate(aux0) -- (0,-1) coordinate(aux1);
                foreach x in {0,...,5}
                { draw [DodgerBlue](x,-1) circle (0.25);
                draw [-latex,red](x,-1) -- (x,-1.5) ;
                unlessifnumx=0%
                draw [-latex,DarkGreen] (x,-1) coordinate(aux2) (x,-0.5) coordinate(aux3)
                (aux2) -- (intersection cs:first line={(aux2)--(aux3)},
                second line={(aux0)--(aux1)});
                fi
                }
                end{tikzpicture}
                end{document}






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Dec 12 '18 at 16:06

























                answered Dec 12 '18 at 11:09









                marmotmarmot

                99.2k4115220




                99.2k4115220













                • Using intersections is an interesting idea :)

                  – TeXnician
                  Dec 12 '18 at 11:11











                • @TeXnician These are actually those intersections that come with calc and do not require the intersections library. They are restricted to intersections of straight lines, though. (+1 to your analytic solution ;-)

                  – marmot
                  Dec 12 '18 at 11:13











                • I have used these "calc intersections" before, but I would not have thought of them in this case…

                  – TeXnician
                  Dec 12 '18 at 11:22






                • 1





                  I am almost happy. The code is not so short and cryptic as mentioned before. :-)

                  – Artificial Stupidity
                  Dec 12 '18 at 16:07






                • 2





                  @ArtificialStupidity Yes, but of course now it is no longer a valid answer to the question which in its title asks for two loops. (3 loops includes 2, of course ;-)

                  – marmot
                  Dec 12 '18 at 16:12



















                • Using intersections is an interesting idea :)

                  – TeXnician
                  Dec 12 '18 at 11:11











                • @TeXnician These are actually those intersections that come with calc and do not require the intersections library. They are restricted to intersections of straight lines, though. (+1 to your analytic solution ;-)

                  – marmot
                  Dec 12 '18 at 11:13











                • I have used these "calc intersections" before, but I would not have thought of them in this case…

                  – TeXnician
                  Dec 12 '18 at 11:22






                • 1





                  I am almost happy. The code is not so short and cryptic as mentioned before. :-)

                  – Artificial Stupidity
                  Dec 12 '18 at 16:07






                • 2





                  @ArtificialStupidity Yes, but of course now it is no longer a valid answer to the question which in its title asks for two loops. (3 loops includes 2, of course ;-)

                  – marmot
                  Dec 12 '18 at 16:12

















                Using intersections is an interesting idea :)

                – TeXnician
                Dec 12 '18 at 11:11





                Using intersections is an interesting idea :)

                – TeXnician
                Dec 12 '18 at 11:11













                @TeXnician These are actually those intersections that come with calc and do not require the intersections library. They are restricted to intersections of straight lines, though. (+1 to your analytic solution ;-)

                – marmot
                Dec 12 '18 at 11:13





                @TeXnician These are actually those intersections that come with calc and do not require the intersections library. They are restricted to intersections of straight lines, though. (+1 to your analytic solution ;-)

                – marmot
                Dec 12 '18 at 11:13













                I have used these "calc intersections" before, but I would not have thought of them in this case…

                – TeXnician
                Dec 12 '18 at 11:22





                I have used these "calc intersections" before, but I would not have thought of them in this case…

                – TeXnician
                Dec 12 '18 at 11:22




                1




                1





                I am almost happy. The code is not so short and cryptic as mentioned before. :-)

                – Artificial Stupidity
                Dec 12 '18 at 16:07





                I am almost happy. The code is not so short and cryptic as mentioned before. :-)

                – Artificial Stupidity
                Dec 12 '18 at 16:07




                2




                2





                @ArtificialStupidity Yes, but of course now it is no longer a valid answer to the question which in its title asks for two loops. (3 loops includes 2, of course ;-)

                – marmot
                Dec 12 '18 at 16:12





                @ArtificialStupidity Yes, but of course now it is no longer a valid answer to the question which in its title asks for two loops. (3 loops includes 2, of course ;-)

                – marmot
                Dec 12 '18 at 16:12











                8














                You can use a simple linear function. Please note that your arrow heads are quite large in your scale. It might be a good idea to choose a larger scale or use another arrow tip to have a better representation of the second case.



                linear function



                documentclass{article}

                usepackage[svgnames]{xcolor}
                usepackage{tikz}

                begin{document}

                begin{tikzpicture}

                foreach x in {0,...,5}{
                draw [DodgerBlue](x,0) circle (0.25);
                draw [-latex,red](x,0) -- (x,-.5);
                }
                foreach x in {1,...,5}{
                draw [-latex,DarkGreen](x,0) -- (x,{0.1*x});
                }

                draw [ultra thin] (5,.5) -- (0,0);

                end{tikzpicture}

                end{document}





                share|improve this answer




























                  8














                  You can use a simple linear function. Please note that your arrow heads are quite large in your scale. It might be a good idea to choose a larger scale or use another arrow tip to have a better representation of the second case.



                  linear function



                  documentclass{article}

                  usepackage[svgnames]{xcolor}
                  usepackage{tikz}

                  begin{document}

                  begin{tikzpicture}

                  foreach x in {0,...,5}{
                  draw [DodgerBlue](x,0) circle (0.25);
                  draw [-latex,red](x,0) -- (x,-.5);
                  }
                  foreach x in {1,...,5}{
                  draw [-latex,DarkGreen](x,0) -- (x,{0.1*x});
                  }

                  draw [ultra thin] (5,.5) -- (0,0);

                  end{tikzpicture}

                  end{document}





                  share|improve this answer


























                    8












                    8








                    8







                    You can use a simple linear function. Please note that your arrow heads are quite large in your scale. It might be a good idea to choose a larger scale or use another arrow tip to have a better representation of the second case.



                    linear function



                    documentclass{article}

                    usepackage[svgnames]{xcolor}
                    usepackage{tikz}

                    begin{document}

                    begin{tikzpicture}

                    foreach x in {0,...,5}{
                    draw [DodgerBlue](x,0) circle (0.25);
                    draw [-latex,red](x,0) -- (x,-.5);
                    }
                    foreach x in {1,...,5}{
                    draw [-latex,DarkGreen](x,0) -- (x,{0.1*x});
                    }

                    draw [ultra thin] (5,.5) -- (0,0);

                    end{tikzpicture}

                    end{document}





                    share|improve this answer













                    You can use a simple linear function. Please note that your arrow heads are quite large in your scale. It might be a good idea to choose a larger scale or use another arrow tip to have a better representation of the second case.



                    linear function



                    documentclass{article}

                    usepackage[svgnames]{xcolor}
                    usepackage{tikz}

                    begin{document}

                    begin{tikzpicture}

                    foreach x in {0,...,5}{
                    draw [DodgerBlue](x,0) circle (0.25);
                    draw [-latex,red](x,0) -- (x,-.5);
                    }
                    foreach x in {1,...,5}{
                    draw [-latex,DarkGreen](x,0) -- (x,{0.1*x});
                    }

                    draw [ultra thin] (5,.5) -- (0,0);

                    end{tikzpicture}

                    end{document}






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Dec 12 '18 at 11:08









                    TeXnicianTeXnician

                    24.9k63288




                    24.9k63288























                        7














                        A PSTricks solution with just one loop only for comparison purposes.



                        documentclass[pstricks]{standalone}
                        usepackage{pst-calculate}
                        begin{document}
                        begin{pspicture}[arrowsize=.2,arrowinset=0,linewidth=1pt](8.5,pscalculate{8/3})
                        foreach i in {0,1,...,5}{%
                        pstVerb{/x {ispace 1.5 mul .5 add} def}%
                        pscircle[linecolor=blue](!x 1){.5}
                        psline[linecolor=red]{->}(!x 1)(!x 0)
                        ifnumi=0relaxelsepsline[linecolor=green]{->}(!x 1)(!x ispace 3 div 1 add)fi
                        }
                        psline[linestyle=dashed](.5,1)(!8 dup 3 div)
                        end{pspicture}
                        end{document}


                        enter image description here






                        share|improve this answer
























                        • Thanks for upvoting my answer. Now I got a nice hat.

                          – Artificial Stupidity
                          Dec 12 '18 at 15:55
















                        7














                        A PSTricks solution with just one loop only for comparison purposes.



                        documentclass[pstricks]{standalone}
                        usepackage{pst-calculate}
                        begin{document}
                        begin{pspicture}[arrowsize=.2,arrowinset=0,linewidth=1pt](8.5,pscalculate{8/3})
                        foreach i in {0,1,...,5}{%
                        pstVerb{/x {ispace 1.5 mul .5 add} def}%
                        pscircle[linecolor=blue](!x 1){.5}
                        psline[linecolor=red]{->}(!x 1)(!x 0)
                        ifnumi=0relaxelsepsline[linecolor=green]{->}(!x 1)(!x ispace 3 div 1 add)fi
                        }
                        psline[linestyle=dashed](.5,1)(!8 dup 3 div)
                        end{pspicture}
                        end{document}


                        enter image description here






                        share|improve this answer
























                        • Thanks for upvoting my answer. Now I got a nice hat.

                          – Artificial Stupidity
                          Dec 12 '18 at 15:55














                        7












                        7








                        7







                        A PSTricks solution with just one loop only for comparison purposes.



                        documentclass[pstricks]{standalone}
                        usepackage{pst-calculate}
                        begin{document}
                        begin{pspicture}[arrowsize=.2,arrowinset=0,linewidth=1pt](8.5,pscalculate{8/3})
                        foreach i in {0,1,...,5}{%
                        pstVerb{/x {ispace 1.5 mul .5 add} def}%
                        pscircle[linecolor=blue](!x 1){.5}
                        psline[linecolor=red]{->}(!x 1)(!x 0)
                        ifnumi=0relaxelsepsline[linecolor=green]{->}(!x 1)(!x ispace 3 div 1 add)fi
                        }
                        psline[linestyle=dashed](.5,1)(!8 dup 3 div)
                        end{pspicture}
                        end{document}


                        enter image description here






                        share|improve this answer













                        A PSTricks solution with just one loop only for comparison purposes.



                        documentclass[pstricks]{standalone}
                        usepackage{pst-calculate}
                        begin{document}
                        begin{pspicture}[arrowsize=.2,arrowinset=0,linewidth=1pt](8.5,pscalculate{8/3})
                        foreach i in {0,1,...,5}{%
                        pstVerb{/x {ispace 1.5 mul .5 add} def}%
                        pscircle[linecolor=blue](!x 1){.5}
                        psline[linecolor=red]{->}(!x 1)(!x 0)
                        ifnumi=0relaxelsepsline[linecolor=green]{->}(!x 1)(!x ispace 3 div 1 add)fi
                        }
                        psline[linestyle=dashed](.5,1)(!8 dup 3 div)
                        end{pspicture}
                        end{document}


                        enter image description here







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Dec 12 '18 at 15:44









                        Artificial StupidityArtificial Stupidity

                        5,29011040




                        5,29011040













                        • Thanks for upvoting my answer. Now I got a nice hat.

                          – Artificial Stupidity
                          Dec 12 '18 at 15:55



















                        • Thanks for upvoting my answer. Now I got a nice hat.

                          – Artificial Stupidity
                          Dec 12 '18 at 15:55

















                        Thanks for upvoting my answer. Now I got a nice hat.

                        – Artificial Stupidity
                        Dec 12 '18 at 15:55





                        Thanks for upvoting my answer. Now I got a nice hat.

                        – Artificial Stupidity
                        Dec 12 '18 at 15:55











                        5














                        one more with use of lines intersections, but defined with help of the package intersections:



                        documentclass[tikz, svgnames, margin=3]{standalone}
                        usetikzlibrary{intersections}

                        begin{document}
                        begin{tikzpicture}
                        foreach x in {0,...,5}{
                        draw [DodgerBlue](x,0) circle (0.25);
                        draw [-latex,red](x,0) -- (x,-.5);
                        }
                        draw [ultra thin, name path=A] (5,.5) -- (0,0);
                        foreach x in {1,...,5}
                        {
                        path[name path=Bx] (x,0) -- ++ (0,0.5);
                        draw[-latex,DarkGreen,
                        name intersections={of=A and Bx,by={Bx}}] (x,0) -- (Bx);
                        }
                        end{tikzpicture}
                        end{document}


                        enter image description here






                        share|improve this answer




























                          5














                          one more with use of lines intersections, but defined with help of the package intersections:



                          documentclass[tikz, svgnames, margin=3]{standalone}
                          usetikzlibrary{intersections}

                          begin{document}
                          begin{tikzpicture}
                          foreach x in {0,...,5}{
                          draw [DodgerBlue](x,0) circle (0.25);
                          draw [-latex,red](x,0) -- (x,-.5);
                          }
                          draw [ultra thin, name path=A] (5,.5) -- (0,0);
                          foreach x in {1,...,5}
                          {
                          path[name path=Bx] (x,0) -- ++ (0,0.5);
                          draw[-latex,DarkGreen,
                          name intersections={of=A and Bx,by={Bx}}] (x,0) -- (Bx);
                          }
                          end{tikzpicture}
                          end{document}


                          enter image description here






                          share|improve this answer


























                            5












                            5








                            5







                            one more with use of lines intersections, but defined with help of the package intersections:



                            documentclass[tikz, svgnames, margin=3]{standalone}
                            usetikzlibrary{intersections}

                            begin{document}
                            begin{tikzpicture}
                            foreach x in {0,...,5}{
                            draw [DodgerBlue](x,0) circle (0.25);
                            draw [-latex,red](x,0) -- (x,-.5);
                            }
                            draw [ultra thin, name path=A] (5,.5) -- (0,0);
                            foreach x in {1,...,5}
                            {
                            path[name path=Bx] (x,0) -- ++ (0,0.5);
                            draw[-latex,DarkGreen,
                            name intersections={of=A and Bx,by={Bx}}] (x,0) -- (Bx);
                            }
                            end{tikzpicture}
                            end{document}


                            enter image description here






                            share|improve this answer













                            one more with use of lines intersections, but defined with help of the package intersections:



                            documentclass[tikz, svgnames, margin=3]{standalone}
                            usetikzlibrary{intersections}

                            begin{document}
                            begin{tikzpicture}
                            foreach x in {0,...,5}{
                            draw [DodgerBlue](x,0) circle (0.25);
                            draw [-latex,red](x,0) -- (x,-.5);
                            }
                            draw [ultra thin, name path=A] (5,.5) -- (0,0);
                            foreach x in {1,...,5}
                            {
                            path[name path=Bx] (x,0) -- ++ (0,0.5);
                            draw[-latex,DarkGreen,
                            name intersections={of=A and Bx,by={Bx}}] (x,0) -- (Bx);
                            }
                            end{tikzpicture}
                            end{document}


                            enter image description here







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Dec 12 '18 at 11:41









                            ZarkoZarko

                            124k866163




                            124k866163























                                4














                                Like this (please observe foreach x in {1,...,5} instead of foreach x in {0,...,5}?



                                documentclass{article}

                                usepackage[svgnames]{xcolor}
                                usepackage{tikz}

                                begin{document}

                                begin{tikzpicture}

                                foreach x in {0,...,5}
                                draw [DodgerBlue](x,-1) circle (0.25);

                                foreach x in {0,...,5}
                                draw [-latex,red](x,-1) -- (x,-1.5);

                                %foreach x in {0,...,5}
                                % draw [-latex,DarkGreen](x,-1) -- (x,-0.5);
                                foreach x in {1,...,5}
                                draw [-latex,DarkGreen](x,-1) -- (x,-1+0.1*x);

                                draw [ultra thin] (5,-0.5) -- (0,-1);

                                end{tikzpicture}

                                end{document}


                                enter image description here






                                share|improve this answer






























                                  4














                                  Like this (please observe foreach x in {1,...,5} instead of foreach x in {0,...,5}?



                                  documentclass{article}

                                  usepackage[svgnames]{xcolor}
                                  usepackage{tikz}

                                  begin{document}

                                  begin{tikzpicture}

                                  foreach x in {0,...,5}
                                  draw [DodgerBlue](x,-1) circle (0.25);

                                  foreach x in {0,...,5}
                                  draw [-latex,red](x,-1) -- (x,-1.5);

                                  %foreach x in {0,...,5}
                                  % draw [-latex,DarkGreen](x,-1) -- (x,-0.5);
                                  foreach x in {1,...,5}
                                  draw [-latex,DarkGreen](x,-1) -- (x,-1+0.1*x);

                                  draw [ultra thin] (5,-0.5) -- (0,-1);

                                  end{tikzpicture}

                                  end{document}


                                  enter image description here






                                  share|improve this answer




























                                    4












                                    4








                                    4







                                    Like this (please observe foreach x in {1,...,5} instead of foreach x in {0,...,5}?



                                    documentclass{article}

                                    usepackage[svgnames]{xcolor}
                                    usepackage{tikz}

                                    begin{document}

                                    begin{tikzpicture}

                                    foreach x in {0,...,5}
                                    draw [DodgerBlue](x,-1) circle (0.25);

                                    foreach x in {0,...,5}
                                    draw [-latex,red](x,-1) -- (x,-1.5);

                                    %foreach x in {0,...,5}
                                    % draw [-latex,DarkGreen](x,-1) -- (x,-0.5);
                                    foreach x in {1,...,5}
                                    draw [-latex,DarkGreen](x,-1) -- (x,-1+0.1*x);

                                    draw [ultra thin] (5,-0.5) -- (0,-1);

                                    end{tikzpicture}

                                    end{document}


                                    enter image description here






                                    share|improve this answer















                                    Like this (please observe foreach x in {1,...,5} instead of foreach x in {0,...,5}?



                                    documentclass{article}

                                    usepackage[svgnames]{xcolor}
                                    usepackage{tikz}

                                    begin{document}

                                    begin{tikzpicture}

                                    foreach x in {0,...,5}
                                    draw [DodgerBlue](x,-1) circle (0.25);

                                    foreach x in {0,...,5}
                                    draw [-latex,red](x,-1) -- (x,-1.5);

                                    %foreach x in {0,...,5}
                                    % draw [-latex,DarkGreen](x,-1) -- (x,-0.5);
                                    foreach x in {1,...,5}
                                    draw [-latex,DarkGreen](x,-1) -- (x,-1+0.1*x);

                                    draw [ultra thin] (5,-0.5) -- (0,-1);

                                    end{tikzpicture}

                                    end{document}


                                    enter image description here







                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Dec 12 '18 at 13:31

























                                    answered Dec 12 '18 at 11:09









                                    Przemysław ScherwentkePrzemysław Scherwentke

                                    29.8k54695




                                    29.8k54695






























                                        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%2f464497%2ftikz-picture-using-two-foreach-loops%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

                                        Probability when a professor distributes a quiz and homework assignment to a class of n students.

                                        Aardman Animations

                                        Are they similar matrix