Problem with using rnd function in Tikz polar coordinates
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
add a comment |
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
add a comment |
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
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
tikz-pgf pgfmath
asked Feb 20 at 10:51
TobiasTobias
82
82
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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}
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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}
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
add a comment |
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}
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
add a comment |
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}
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}
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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