Tikz picture using two “foreach” loops
up vote
4
down vote
favorite
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
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
add a comment |
up vote
4
down vote
favorite
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
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
add a comment |
up vote
4
down vote
favorite
up vote
4
down vote
favorite
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
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
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
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
tikz-pgf foreach
asked 57 mins ago
Damitr
570312
570312
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
up vote
4
down vote
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.
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}
add a comment |
up vote
4
down vote
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}
Using intersections is an interesting idea :)
– TeXnician
36 mins ago
@TeXnician These are actually those intersections that come withcalc
and do not require theintersections
library. They are restricted to intersections of straight lines, though. (+1 to your analytic solution ;-)
– marmot
33 mins ago
I have used these "calc intersections" before, but I would not have thought of them in this case…
– TeXnician
25 mins ago
add a comment |
up vote
3
down vote
Like this (please obeserve foreach x in {1,...,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}
add a comment |
up vote
0
down vote
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}
add a comment |
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
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.
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}
add a comment |
up vote
4
down vote
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.
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}
add a comment |
up vote
4
down vote
up vote
4
down vote
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.
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}
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.
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}
answered 39 mins ago
TeXnician
23.9k62984
23.9k62984
add a comment |
add a comment |
up vote
4
down vote
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}
Using intersections is an interesting idea :)
– TeXnician
36 mins ago
@TeXnician These are actually those intersections that come withcalc
and do not require theintersections
library. They are restricted to intersections of straight lines, though. (+1 to your analytic solution ;-)
– marmot
33 mins ago
I have used these "calc intersections" before, but I would not have thought of them in this case…
– TeXnician
25 mins ago
add a comment |
up vote
4
down vote
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}
Using intersections is an interesting idea :)
– TeXnician
36 mins ago
@TeXnician These are actually those intersections that come withcalc
and do not require theintersections
library. They are restricted to intersections of straight lines, though. (+1 to your analytic solution ;-)
– marmot
33 mins ago
I have used these "calc intersections" before, but I would not have thought of them in this case…
– TeXnician
25 mins ago
add a comment |
up vote
4
down vote
up vote
4
down vote
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}
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}
edited 35 mins ago
answered 38 mins ago
marmot
82.5k493176
82.5k493176
Using intersections is an interesting idea :)
– TeXnician
36 mins ago
@TeXnician These are actually those intersections that come withcalc
and do not require theintersections
library. They are restricted to intersections of straight lines, though. (+1 to your analytic solution ;-)
– marmot
33 mins ago
I have used these "calc intersections" before, but I would not have thought of them in this case…
– TeXnician
25 mins ago
add a comment |
Using intersections is an interesting idea :)
– TeXnician
36 mins ago
@TeXnician These are actually those intersections that come withcalc
and do not require theintersections
library. They are restricted to intersections of straight lines, though. (+1 to your analytic solution ;-)
– marmot
33 mins ago
I have used these "calc intersections" before, but I would not have thought of them in this case…
– TeXnician
25 mins ago
Using intersections is an interesting idea :)
– TeXnician
36 mins ago
Using intersections is an interesting idea :)
– TeXnician
36 mins ago
@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
33 mins ago
@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
33 mins ago
I have used these "calc intersections" before, but I would not have thought of them in this case…
– TeXnician
25 mins ago
I have used these "calc intersections" before, but I would not have thought of them in this case…
– TeXnician
25 mins ago
add a comment |
up vote
3
down vote
Like this (please obeserve foreach x in {1,...,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}
add a comment |
up vote
3
down vote
Like this (please obeserve foreach x in {1,...,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}
add a comment |
up vote
3
down vote
up vote
3
down vote
Like this (please obeserve foreach x in {1,...,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}
Like this (please obeserve foreach x in {1,...,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}
edited 25 mins ago
answered 37 mins ago
Przemysław Scherwentke
29.6k54494
29.6k54494
add a comment |
add a comment |
up vote
0
down vote
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}
add a comment |
up vote
0
down vote
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}
add a comment |
up vote
0
down vote
up vote
0
down vote
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}
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}
answered 6 mins ago
Zarko
118k865155
118k865155
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f464497%2ftikz-picture-using-two-foreach-loops%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