Problem with using rnd function in Tikz polar coordinates












1















I am trying to draw lines with a different, random length but the same direction. This is what I thought should work, but if I put in any other angle than 90 degrees (for example 30 degrees in this example) the lines don't point in the same direction.



documentclass{scrartcl}
usepackage[papersize={5.5cm,8cm}, left=0.5cm,right=0.5cm,top=1cm,bottom=1cm,margin=0pt]{geometry}
pagestyle{empty}
usepackage{tikz}
usepackage{pgfmath}

begin{document}
centering
begin{tikzpicture}[remember picture,overlay]
foreach x in {0,1,...,paperwidth}{
draw(current page.south west)++(x pt,0)--++(30:rnd);
}
end{tikzpicture}
end{document}









share|improve this question



























    1















    I am trying to draw lines with a different, random length but the same direction. This is what I thought should work, but if I put in any other angle than 90 degrees (for example 30 degrees in this example) the lines don't point in the same direction.



    documentclass{scrartcl}
    usepackage[papersize={5.5cm,8cm}, left=0.5cm,right=0.5cm,top=1cm,bottom=1cm,margin=0pt]{geometry}
    pagestyle{empty}
    usepackage{tikz}
    usepackage{pgfmath}

    begin{document}
    centering
    begin{tikzpicture}[remember picture,overlay]
    foreach x in {0,1,...,paperwidth}{
    draw(current page.south west)++(x pt,0)--++(30:rnd);
    }
    end{tikzpicture}
    end{document}









    share|improve this question

























      1












      1








      1








      I am trying to draw lines with a different, random length but the same direction. This is what I thought should work, but if I put in any other angle than 90 degrees (for example 30 degrees in this example) the lines don't point in the same direction.



      documentclass{scrartcl}
      usepackage[papersize={5.5cm,8cm}, left=0.5cm,right=0.5cm,top=1cm,bottom=1cm,margin=0pt]{geometry}
      pagestyle{empty}
      usepackage{tikz}
      usepackage{pgfmath}

      begin{document}
      centering
      begin{tikzpicture}[remember picture,overlay]
      foreach x in {0,1,...,paperwidth}{
      draw(current page.south west)++(x pt,0)--++(30:rnd);
      }
      end{tikzpicture}
      end{document}









      share|improve this question














      I am trying to draw lines with a different, random length but the same direction. This is what I thought should work, but if I put in any other angle than 90 degrees (for example 30 degrees in this example) the lines don't point in the same direction.



      documentclass{scrartcl}
      usepackage[papersize={5.5cm,8cm}, left=0.5cm,right=0.5cm,top=1cm,bottom=1cm,margin=0pt]{geometry}
      pagestyle{empty}
      usepackage{tikz}
      usepackage{pgfmath}

      begin{document}
      centering
      begin{tikzpicture}[remember picture,overlay]
      foreach x in {0,1,...,paperwidth}{
      draw(current page.south west)++(x pt,0)--++(30:rnd);
      }
      end{tikzpicture}
      end{document}






      tikz-pgf pgfmath






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 20 at 10:51









      TobiasTobias

      82




      82






















          1 Answer
          1






          active

          oldest

          votes


















          1














          Use the pgfmathparse and pgfmathresult for getting a random number.



          documentclass{scrartcl}
          usepackage[papersize={5.5cm,8cm}, left=0.5cm,right=0.5cm,top=1cm,bottom=1cm,margin=0pt]{geometry}
          pagestyle{empty}
          usepackage{tikz}
          usepackage{pgf}

          pgfmathsetseed{numberpdfrandomseed} % Getting different random numbers. If you don't want, comment this.

          begin{document}
          centering

          begin{tikzpicture}[remember picture,overlay]
          foreach x in {0,1,...,paperwidth}{
          pgfmathparse{int(rand*10)}letA=pgfmathresult
          draw(current page.south west)++(x pt,0)--++(80:A);
          }
          end{tikzpicture}
          end{document}





          share|improve this answer
























          • That does it but could you perhaps explain a bit why you are doing that? It seems that TikZ transforms the coordinate into something like ({rnd*cos(80)},{rnd*sin(80)}) and assigns the random number only afterwards. You evade this by first computing the random number and then constructing the path.

            – marmot
            Feb 20 at 18:23











          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%2f475805%2fproblem-with-using-rnd-function-in-tikz-polar-coordinates%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Use the pgfmathparse and pgfmathresult for getting a random number.



          documentclass{scrartcl}
          usepackage[papersize={5.5cm,8cm}, left=0.5cm,right=0.5cm,top=1cm,bottom=1cm,margin=0pt]{geometry}
          pagestyle{empty}
          usepackage{tikz}
          usepackage{pgf}

          pgfmathsetseed{numberpdfrandomseed} % Getting different random numbers. If you don't want, comment this.

          begin{document}
          centering

          begin{tikzpicture}[remember picture,overlay]
          foreach x in {0,1,...,paperwidth}{
          pgfmathparse{int(rand*10)}letA=pgfmathresult
          draw(current page.south west)++(x pt,0)--++(80:A);
          }
          end{tikzpicture}
          end{document}





          share|improve this answer
























          • That does it but could you perhaps explain a bit why you are doing that? It seems that TikZ transforms the coordinate into something like ({rnd*cos(80)},{rnd*sin(80)}) and assigns the random number only afterwards. You evade this by first computing the random number and then constructing the path.

            – marmot
            Feb 20 at 18:23
















          1














          Use the pgfmathparse and pgfmathresult for getting a random number.



          documentclass{scrartcl}
          usepackage[papersize={5.5cm,8cm}, left=0.5cm,right=0.5cm,top=1cm,bottom=1cm,margin=0pt]{geometry}
          pagestyle{empty}
          usepackage{tikz}
          usepackage{pgf}

          pgfmathsetseed{numberpdfrandomseed} % Getting different random numbers. If you don't want, comment this.

          begin{document}
          centering

          begin{tikzpicture}[remember picture,overlay]
          foreach x in {0,1,...,paperwidth}{
          pgfmathparse{int(rand*10)}letA=pgfmathresult
          draw(current page.south west)++(x pt,0)--++(80:A);
          }
          end{tikzpicture}
          end{document}





          share|improve this answer
























          • That does it but could you perhaps explain a bit why you are doing that? It seems that TikZ transforms the coordinate into something like ({rnd*cos(80)},{rnd*sin(80)}) and assigns the random number only afterwards. You evade this by first computing the random number and then constructing the path.

            – marmot
            Feb 20 at 18:23














          1












          1








          1







          Use the pgfmathparse and pgfmathresult for getting a random number.



          documentclass{scrartcl}
          usepackage[papersize={5.5cm,8cm}, left=0.5cm,right=0.5cm,top=1cm,bottom=1cm,margin=0pt]{geometry}
          pagestyle{empty}
          usepackage{tikz}
          usepackage{pgf}

          pgfmathsetseed{numberpdfrandomseed} % Getting different random numbers. If you don't want, comment this.

          begin{document}
          centering

          begin{tikzpicture}[remember picture,overlay]
          foreach x in {0,1,...,paperwidth}{
          pgfmathparse{int(rand*10)}letA=pgfmathresult
          draw(current page.south west)++(x pt,0)--++(80:A);
          }
          end{tikzpicture}
          end{document}





          share|improve this answer













          Use the pgfmathparse and pgfmathresult for getting a random number.



          documentclass{scrartcl}
          usepackage[papersize={5.5cm,8cm}, left=0.5cm,right=0.5cm,top=1cm,bottom=1cm,margin=0pt]{geometry}
          pagestyle{empty}
          usepackage{tikz}
          usepackage{pgf}

          pgfmathsetseed{numberpdfrandomseed} % Getting different random numbers. If you don't want, comment this.

          begin{document}
          centering

          begin{tikzpicture}[remember picture,overlay]
          foreach x in {0,1,...,paperwidth}{
          pgfmathparse{int(rand*10)}letA=pgfmathresult
          draw(current page.south west)++(x pt,0)--++(80:A);
          }
          end{tikzpicture}
          end{document}






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Feb 20 at 11:21









          ferahfezaferahfeza

          6,29611932




          6,29611932













          • That does it but could you perhaps explain a bit why you are doing that? It seems that TikZ transforms the coordinate into something like ({rnd*cos(80)},{rnd*sin(80)}) and assigns the random number only afterwards. You evade this by first computing the random number and then constructing the path.

            – marmot
            Feb 20 at 18:23



















          • That does it but could you perhaps explain a bit why you are doing that? It seems that TikZ transforms the coordinate into something like ({rnd*cos(80)},{rnd*sin(80)}) and assigns the random number only afterwards. You evade this by first computing the random number and then constructing the path.

            – marmot
            Feb 20 at 18:23

















          That does it but could you perhaps explain a bit why you are doing that? It seems that TikZ transforms the coordinate into something like ({rnd*cos(80)},{rnd*sin(80)}) and assigns the random number only afterwards. You evade this by first computing the random number and then constructing the path.

          – marmot
          Feb 20 at 18:23





          That does it but could you perhaps explain a bit why you are doing that? It seems that TikZ transforms the coordinate into something like ({rnd*cos(80)},{rnd*sin(80)}) and assigns the random number only afterwards. You evade this by first computing the random number and then constructing the path.

          – marmot
          Feb 20 at 18:23


















          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%2f475805%2fproblem-with-using-rnd-function-in-tikz-polar-coordinates%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

          How to change which sound is reproduced for terminal bell?

          Can I use Tabulator js library in my java Spring + Thymeleaf project?

          Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents