Colorize sides regular polygon
Clash Royale CLAN TAG#URR8PPP
up vote
5
down vote
favorite
To illustrate what edge-coloring is, I'd like to colorize a regular polygon. I want to generate the shape using TikZ, then colorize the sides (edges) of the polygon separately, for instance by doing something like this:
draw[red] (polygon.side 1);
Unfortunately, the world does not seem to work like this. For now my ugly workaround is to overdraw using dotted, dashed, and thick lines.
documentclassstandalone
usepackagetikz
usetikzlibraryshapes.geometric,positioning
begindocument
begintikzpicture
node[draw, dotted, minimum size=2cm, regular polygon,
regular polygon sides=5] (polygon) ;
draw[thick] (polygon.corner 1) -- (polygon.corner 2);
draw[dashed] (polygon.corner 2) -- (polygon.corner 3);
draw[thick] (polygon.corner 4) -- (polygon.corner 5);
draw[dashed] (polygon.corner 5) -- (polygon.corner 1);
endtikzpicture
enddocument
Thanks!
tikz-pgf graphs tikz-shape polygon
add a comment |
up vote
5
down vote
favorite
To illustrate what edge-coloring is, I'd like to colorize a regular polygon. I want to generate the shape using TikZ, then colorize the sides (edges) of the polygon separately, for instance by doing something like this:
draw[red] (polygon.side 1);
Unfortunately, the world does not seem to work like this. For now my ugly workaround is to overdraw using dotted, dashed, and thick lines.
documentclassstandalone
usepackagetikz
usetikzlibraryshapes.geometric,positioning
begindocument
begintikzpicture
node[draw, dotted, minimum size=2cm, regular polygon,
regular polygon sides=5] (polygon) ;
draw[thick] (polygon.corner 1) -- (polygon.corner 2);
draw[dashed] (polygon.corner 2) -- (polygon.corner 3);
draw[thick] (polygon.corner 4) -- (polygon.corner 5);
draw[dashed] (polygon.corner 5) -- (polygon.corner 1);
endtikzpicture
enddocument
Thanks!
tikz-pgf graphs tikz-shape polygon
Do you really want to use a node?
– Sigur
Nov 21 at 23:02
I want the simplest thing possible. I may have driven into the wrong direction. Also, why wouldn't I want a node?
– Antonin Décimo
Nov 21 at 23:04
add a comment |
up vote
5
down vote
favorite
up vote
5
down vote
favorite
To illustrate what edge-coloring is, I'd like to colorize a regular polygon. I want to generate the shape using TikZ, then colorize the sides (edges) of the polygon separately, for instance by doing something like this:
draw[red] (polygon.side 1);
Unfortunately, the world does not seem to work like this. For now my ugly workaround is to overdraw using dotted, dashed, and thick lines.
documentclassstandalone
usepackagetikz
usetikzlibraryshapes.geometric,positioning
begindocument
begintikzpicture
node[draw, dotted, minimum size=2cm, regular polygon,
regular polygon sides=5] (polygon) ;
draw[thick] (polygon.corner 1) -- (polygon.corner 2);
draw[dashed] (polygon.corner 2) -- (polygon.corner 3);
draw[thick] (polygon.corner 4) -- (polygon.corner 5);
draw[dashed] (polygon.corner 5) -- (polygon.corner 1);
endtikzpicture
enddocument
Thanks!
tikz-pgf graphs tikz-shape polygon
To illustrate what edge-coloring is, I'd like to colorize a regular polygon. I want to generate the shape using TikZ, then colorize the sides (edges) of the polygon separately, for instance by doing something like this:
draw[red] (polygon.side 1);
Unfortunately, the world does not seem to work like this. For now my ugly workaround is to overdraw using dotted, dashed, and thick lines.
documentclassstandalone
usepackagetikz
usetikzlibraryshapes.geometric,positioning
begindocument
begintikzpicture
node[draw, dotted, minimum size=2cm, regular polygon,
regular polygon sides=5] (polygon) ;
draw[thick] (polygon.corner 1) -- (polygon.corner 2);
draw[dashed] (polygon.corner 2) -- (polygon.corner 3);
draw[thick] (polygon.corner 4) -- (polygon.corner 5);
draw[dashed] (polygon.corner 5) -- (polygon.corner 1);
endtikzpicture
enddocument
Thanks!
tikz-pgf graphs tikz-shape polygon
tikz-pgf graphs tikz-shape polygon
asked Nov 21 at 22:59
Antonin Décimo
534
534
Do you really want to use a node?
– Sigur
Nov 21 at 23:02
I want the simplest thing possible. I may have driven into the wrong direction. Also, why wouldn't I want a node?
– Antonin Décimo
Nov 21 at 23:04
add a comment |
Do you really want to use a node?
– Sigur
Nov 21 at 23:02
I want the simplest thing possible. I may have driven into the wrong direction. Also, why wouldn't I want a node?
– Antonin Décimo
Nov 21 at 23:04
Do you really want to use a node?
– Sigur
Nov 21 at 23:02
Do you really want to use a node?
– Sigur
Nov 21 at 23:02
I want the simplest thing possible. I may have driven into the wrong direction. Also, why wouldn't I want a node?
– Antonin Décimo
Nov 21 at 23:04
I want the simplest thing possible. I may have driven into the wrong direction. Also, why wouldn't I want a node?
– Antonin Décimo
Nov 21 at 23:04
add a comment |
3 Answers
3
active
oldest
votes
up vote
3
down vote
accepted
With regular polygon colors
option, there's no need for extra commands to draw the sides. Everything is done within the node command.
documentclass[tikz,border=3.14mm]standalone
usetikzlibraryshapes.geometric, positioning
begindocument
begintikzpicture[
regular polygon colors/.style 2 args=
append after command=%
pgfextra
foreach i [count=ni, remember=ni as lasti (initially #1)] in #2
draw[i] (tikzlastnode.corner lasti) --(tikzlastnode.corner ni);
endpgfextra
,
]
node[minimum size=2cm, regular polygon,
regular polygon sides=5,
regular polygon colors=5red,blue,orange,green,cyan] (polygon) ;
node[minimum size=2cm, regular polygon,
regular polygon sides=7,
regular polygon colors=7red, blue, orange, green, cyan, violet, brown,
right=of polygon] (polygon2) ;
endtikzpicture
enddocument
add a comment |
up vote
5
down vote
Like this?
documentclass[margin=1mm]standalone
usepackagetikz
begindocument
begintikzpicture[thick]
foreach i/c in 90/red,162/blue,234/green,306/pink,378/orange
draw[c] (i:1cm) -- (72+i:1cm);
endtikzpicture
enddocument
Edit 1: Another option, to have a better join line:
begintikzpicture[thick]
foreach i/c in 90/red,162/blue,234/green,306/pink,378/orange
fill[c] (i:1cm) -- (72+i:1cm) -- (0,0) -- cycle;
fill[white] (90:.95cm)--(162:.95cm)--(234:.95cm)--(306:.95cm)--(378:.95cm)--cycle;
endtikzpicture
Edit 2: just for fun.
begintikzpicture
foreach r in 1,.9,...,.1
pgfmathparse30 * r%
pgfmathsetmacropercentpgfmathresult
foreach i/c in 90/red,162/blue,234/green,306/pink,378/orange
fill[c!percent] (i:r cm) -- (72+i:r cm) -- (0,0) -- cycle;
endtikzpicture
add a comment |
up vote
3
down vote
Here is a proposal that defines a style polygon side
which can be used e.g. like draw[red,polygon side=2];
to draw the second side red.
documentclass[tikz,border=3.14mm]standalone
usetikzlibraryshapes.geometric
begindocument
begintikzpicture[get next vertex/.code n args=2%
pgfmathparseint(1+mod(#1,5))
xdef#2pgfmathresult,
polygon side/.style=get next vertex=#1tmpnextn,
insert path=(polygon.corner #1)-- (polygon.corner tmpnextn)
]
node[draw, dotted, minimum size=2cm, regular polygon,
regular polygon sides=5] (polygon) ;
foreach X [count=Y] in red,blue,orange,green,cyan
draw[X,polygon side=Y];
endtikzpicture
enddocument
Note that as of now the number of corners (or sides) as well as the name of the object (or node), polygon
, are hard coded. One could of course use pgfkeys to store them in some keys, and if you ask me to I'll be happy to add this to this answer.
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
With regular polygon colors
option, there's no need for extra commands to draw the sides. Everything is done within the node command.
documentclass[tikz,border=3.14mm]standalone
usetikzlibraryshapes.geometric, positioning
begindocument
begintikzpicture[
regular polygon colors/.style 2 args=
append after command=%
pgfextra
foreach i [count=ni, remember=ni as lasti (initially #1)] in #2
draw[i] (tikzlastnode.corner lasti) --(tikzlastnode.corner ni);
endpgfextra
,
]
node[minimum size=2cm, regular polygon,
regular polygon sides=5,
regular polygon colors=5red,blue,orange,green,cyan] (polygon) ;
node[minimum size=2cm, regular polygon,
regular polygon sides=7,
regular polygon colors=7red, blue, orange, green, cyan, violet, brown,
right=of polygon] (polygon2) ;
endtikzpicture
enddocument
add a comment |
up vote
3
down vote
accepted
With regular polygon colors
option, there's no need for extra commands to draw the sides. Everything is done within the node command.
documentclass[tikz,border=3.14mm]standalone
usetikzlibraryshapes.geometric, positioning
begindocument
begintikzpicture[
regular polygon colors/.style 2 args=
append after command=%
pgfextra
foreach i [count=ni, remember=ni as lasti (initially #1)] in #2
draw[i] (tikzlastnode.corner lasti) --(tikzlastnode.corner ni);
endpgfextra
,
]
node[minimum size=2cm, regular polygon,
regular polygon sides=5,
regular polygon colors=5red,blue,orange,green,cyan] (polygon) ;
node[minimum size=2cm, regular polygon,
regular polygon sides=7,
regular polygon colors=7red, blue, orange, green, cyan, violet, brown,
right=of polygon] (polygon2) ;
endtikzpicture
enddocument
add a comment |
up vote
3
down vote
accepted
up vote
3
down vote
accepted
With regular polygon colors
option, there's no need for extra commands to draw the sides. Everything is done within the node command.
documentclass[tikz,border=3.14mm]standalone
usetikzlibraryshapes.geometric, positioning
begindocument
begintikzpicture[
regular polygon colors/.style 2 args=
append after command=%
pgfextra
foreach i [count=ni, remember=ni as lasti (initially #1)] in #2
draw[i] (tikzlastnode.corner lasti) --(tikzlastnode.corner ni);
endpgfextra
,
]
node[minimum size=2cm, regular polygon,
regular polygon sides=5,
regular polygon colors=5red,blue,orange,green,cyan] (polygon) ;
node[minimum size=2cm, regular polygon,
regular polygon sides=7,
regular polygon colors=7red, blue, orange, green, cyan, violet, brown,
right=of polygon] (polygon2) ;
endtikzpicture
enddocument
With regular polygon colors
option, there's no need for extra commands to draw the sides. Everything is done within the node command.
documentclass[tikz,border=3.14mm]standalone
usetikzlibraryshapes.geometric, positioning
begindocument
begintikzpicture[
regular polygon colors/.style 2 args=
append after command=%
pgfextra
foreach i [count=ni, remember=ni as lasti (initially #1)] in #2
draw[i] (tikzlastnode.corner lasti) --(tikzlastnode.corner ni);
endpgfextra
,
]
node[minimum size=2cm, regular polygon,
regular polygon sides=5,
regular polygon colors=5red,blue,orange,green,cyan] (polygon) ;
node[minimum size=2cm, regular polygon,
regular polygon sides=7,
regular polygon colors=7red, blue, orange, green, cyan, violet, brown,
right=of polygon] (polygon2) ;
endtikzpicture
enddocument
answered Nov 22 at 8:55
Ignasi
90.3k4163302
90.3k4163302
add a comment |
add a comment |
up vote
5
down vote
Like this?
documentclass[margin=1mm]standalone
usepackagetikz
begindocument
begintikzpicture[thick]
foreach i/c in 90/red,162/blue,234/green,306/pink,378/orange
draw[c] (i:1cm) -- (72+i:1cm);
endtikzpicture
enddocument
Edit 1: Another option, to have a better join line:
begintikzpicture[thick]
foreach i/c in 90/red,162/blue,234/green,306/pink,378/orange
fill[c] (i:1cm) -- (72+i:1cm) -- (0,0) -- cycle;
fill[white] (90:.95cm)--(162:.95cm)--(234:.95cm)--(306:.95cm)--(378:.95cm)--cycle;
endtikzpicture
Edit 2: just for fun.
begintikzpicture
foreach r in 1,.9,...,.1
pgfmathparse30 * r%
pgfmathsetmacropercentpgfmathresult
foreach i/c in 90/red,162/blue,234/green,306/pink,378/orange
fill[c!percent] (i:r cm) -- (72+i:r cm) -- (0,0) -- cycle;
endtikzpicture
add a comment |
up vote
5
down vote
Like this?
documentclass[margin=1mm]standalone
usepackagetikz
begindocument
begintikzpicture[thick]
foreach i/c in 90/red,162/blue,234/green,306/pink,378/orange
draw[c] (i:1cm) -- (72+i:1cm);
endtikzpicture
enddocument
Edit 1: Another option, to have a better join line:
begintikzpicture[thick]
foreach i/c in 90/red,162/blue,234/green,306/pink,378/orange
fill[c] (i:1cm) -- (72+i:1cm) -- (0,0) -- cycle;
fill[white] (90:.95cm)--(162:.95cm)--(234:.95cm)--(306:.95cm)--(378:.95cm)--cycle;
endtikzpicture
Edit 2: just for fun.
begintikzpicture
foreach r in 1,.9,...,.1
pgfmathparse30 * r%
pgfmathsetmacropercentpgfmathresult
foreach i/c in 90/red,162/blue,234/green,306/pink,378/orange
fill[c!percent] (i:r cm) -- (72+i:r cm) -- (0,0) -- cycle;
endtikzpicture
add a comment |
up vote
5
down vote
up vote
5
down vote
Like this?
documentclass[margin=1mm]standalone
usepackagetikz
begindocument
begintikzpicture[thick]
foreach i/c in 90/red,162/blue,234/green,306/pink,378/orange
draw[c] (i:1cm) -- (72+i:1cm);
endtikzpicture
enddocument
Edit 1: Another option, to have a better join line:
begintikzpicture[thick]
foreach i/c in 90/red,162/blue,234/green,306/pink,378/orange
fill[c] (i:1cm) -- (72+i:1cm) -- (0,0) -- cycle;
fill[white] (90:.95cm)--(162:.95cm)--(234:.95cm)--(306:.95cm)--(378:.95cm)--cycle;
endtikzpicture
Edit 2: just for fun.
begintikzpicture
foreach r in 1,.9,...,.1
pgfmathparse30 * r%
pgfmathsetmacropercentpgfmathresult
foreach i/c in 90/red,162/blue,234/green,306/pink,378/orange
fill[c!percent] (i:r cm) -- (72+i:r cm) -- (0,0) -- cycle;
endtikzpicture
Like this?
documentclass[margin=1mm]standalone
usepackagetikz
begindocument
begintikzpicture[thick]
foreach i/c in 90/red,162/blue,234/green,306/pink,378/orange
draw[c] (i:1cm) -- (72+i:1cm);
endtikzpicture
enddocument
Edit 1: Another option, to have a better join line:
begintikzpicture[thick]
foreach i/c in 90/red,162/blue,234/green,306/pink,378/orange
fill[c] (i:1cm) -- (72+i:1cm) -- (0,0) -- cycle;
fill[white] (90:.95cm)--(162:.95cm)--(234:.95cm)--(306:.95cm)--(378:.95cm)--cycle;
endtikzpicture
Edit 2: just for fun.
begintikzpicture
foreach r in 1,.9,...,.1
pgfmathparse30 * r%
pgfmathsetmacropercentpgfmathresult
foreach i/c in 90/red,162/blue,234/green,306/pink,378/orange
fill[c!percent] (i:r cm) -- (72+i:r cm) -- (0,0) -- cycle;
endtikzpicture
edited Nov 21 at 23:37
answered Nov 21 at 23:08
Sigur
23.3k354135
23.3k354135
add a comment |
add a comment |
up vote
3
down vote
Here is a proposal that defines a style polygon side
which can be used e.g. like draw[red,polygon side=2];
to draw the second side red.
documentclass[tikz,border=3.14mm]standalone
usetikzlibraryshapes.geometric
begindocument
begintikzpicture[get next vertex/.code n args=2%
pgfmathparseint(1+mod(#1,5))
xdef#2pgfmathresult,
polygon side/.style=get next vertex=#1tmpnextn,
insert path=(polygon.corner #1)-- (polygon.corner tmpnextn)
]
node[draw, dotted, minimum size=2cm, regular polygon,
regular polygon sides=5] (polygon) ;
foreach X [count=Y] in red,blue,orange,green,cyan
draw[X,polygon side=Y];
endtikzpicture
enddocument
Note that as of now the number of corners (or sides) as well as the name of the object (or node), polygon
, are hard coded. One could of course use pgfkeys to store them in some keys, and if you ask me to I'll be happy to add this to this answer.
add a comment |
up vote
3
down vote
Here is a proposal that defines a style polygon side
which can be used e.g. like draw[red,polygon side=2];
to draw the second side red.
documentclass[tikz,border=3.14mm]standalone
usetikzlibraryshapes.geometric
begindocument
begintikzpicture[get next vertex/.code n args=2%
pgfmathparseint(1+mod(#1,5))
xdef#2pgfmathresult,
polygon side/.style=get next vertex=#1tmpnextn,
insert path=(polygon.corner #1)-- (polygon.corner tmpnextn)
]
node[draw, dotted, minimum size=2cm, regular polygon,
regular polygon sides=5] (polygon) ;
foreach X [count=Y] in red,blue,orange,green,cyan
draw[X,polygon side=Y];
endtikzpicture
enddocument
Note that as of now the number of corners (or sides) as well as the name of the object (or node), polygon
, are hard coded. One could of course use pgfkeys to store them in some keys, and if you ask me to I'll be happy to add this to this answer.
add a comment |
up vote
3
down vote
up vote
3
down vote
Here is a proposal that defines a style polygon side
which can be used e.g. like draw[red,polygon side=2];
to draw the second side red.
documentclass[tikz,border=3.14mm]standalone
usetikzlibraryshapes.geometric
begindocument
begintikzpicture[get next vertex/.code n args=2%
pgfmathparseint(1+mod(#1,5))
xdef#2pgfmathresult,
polygon side/.style=get next vertex=#1tmpnextn,
insert path=(polygon.corner #1)-- (polygon.corner tmpnextn)
]
node[draw, dotted, minimum size=2cm, regular polygon,
regular polygon sides=5] (polygon) ;
foreach X [count=Y] in red,blue,orange,green,cyan
draw[X,polygon side=Y];
endtikzpicture
enddocument
Note that as of now the number of corners (or sides) as well as the name of the object (or node), polygon
, are hard coded. One could of course use pgfkeys to store them in some keys, and if you ask me to I'll be happy to add this to this answer.
Here is a proposal that defines a style polygon side
which can be used e.g. like draw[red,polygon side=2];
to draw the second side red.
documentclass[tikz,border=3.14mm]standalone
usetikzlibraryshapes.geometric
begindocument
begintikzpicture[get next vertex/.code n args=2%
pgfmathparseint(1+mod(#1,5))
xdef#2pgfmathresult,
polygon side/.style=get next vertex=#1tmpnextn,
insert path=(polygon.corner #1)-- (polygon.corner tmpnextn)
]
node[draw, dotted, minimum size=2cm, regular polygon,
regular polygon sides=5] (polygon) ;
foreach X [count=Y] in red,blue,orange,green,cyan
draw[X,polygon side=Y];
endtikzpicture
enddocument
Note that as of now the number of corners (or sides) as well as the name of the object (or node), polygon
, are hard coded. One could of course use pgfkeys to store them in some keys, and if you ask me to I'll be happy to add this to this answer.
answered Nov 21 at 23:27
marmot
78.8k487166
78.8k487166
add a comment |
add a comment |
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%2f461207%2fcolorize-sides-regular-polygon%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
Do you really want to use a node?
– Sigur
Nov 21 at 23:02
I want the simplest thing possible. I may have driven into the wrong direction. Also, why wouldn't I want a node?
– Antonin Décimo
Nov 21 at 23:04