Regular polygon VS circle shapes in TikZDraw a node as a square with TikZHow to draw inside a TikZ node, using node style?Creating node shapesFilling angles with arcs in TikZIncrease the thickness of node border in TikZComputing the rectangle encompassing a node and a pointcustom hatching pattern : arbitrary direction of hatchingHow to draw inside a TikZ node using node style with arguments?Draw a transparency gradient arc over a rectangle with tikzAdjusting edge alignment and positioning of fitted nodePositioning of Node Labels
Is there a hemisphere-neutral way of specifying a season?
Is it possible to run Internet Explorer on OS X El Capitan?
How to draw the figure with four pentagons?
How can I make my BBEG immortal short of making them a Lich or Vampire?
How to take photos in burst mode, without vibration?
Is it inappropriate for a student to attend their mentor's dissertation defense?
Why doesn't H₄O²⁺ exist?
Why do I get two different answers for this counting problem?
Has there ever been an airliner design involving reducing generator load by installing solar panels?
What's the difference between 'rename' and 'mv'?
Is it unprofessional to ask if a job posting on GlassDoor is real?
What to put in ESTA if staying in US for a few days before going on to Canada
How can I prevent hyper evolved versions of regular creatures from wiping out their cousins?
90's TV series where a boy goes to another dimension through portal near power lines
I would say: "You are another teacher", but she is a woman and I am a man
Were any external disk drives stacked vertically?
Infinite Abelian subgroup of infinite non Abelian group example
Facing a paradox: Earnshaw's theorem in one dimension
Did Shadowfax go to Valinor?
What mechanic is there to disable a threat instead of killing it?
How do conventional missiles fly?
Why is it a bad idea to hire a hitman to eliminate most corrupt politicians?
Would Slavery Reparations be considered Bills of Attainder and hence Illegal?
Alternative to sending password over mail?
Regular polygon VS circle shapes in TikZ
Draw a node as a square with TikZHow to draw inside a TikZ node, using node style?Creating node shapesFilling angles with arcs in TikZIncrease the thickness of node border in TikZComputing the rectangle encompassing a node and a pointcustom hatching pattern : arbitrary direction of hatchingHow to draw inside a TikZ node using node style with arguments?Draw a transparency gradient arc over a rectangle with tikzAdjusting edge alignment and positioning of fitted nodePositioning of Node Labels
This question is a kind of continuation this answer. There, it remains unclear which is the origin of the white space around the node content, if a square shape is used, and I would like to understand this. Given the following MWE
documentclass[tikz, border=1mm]standalone
usetikzlibraryshapes.geometric
begindocument
begintikzpicture[every node/.style=draw, inner sep=0]
node[regular polygon,regular polygon sides=4] (a) XX;
node[regular polygon,regular polygon sides=100, blue] (b) XX;
node[circle] (c) XX;
foreach a in north,south,east,west,north east,south east,north west,south west
fill[red] (a.a) circle(0.5pt);
fill[yellow] (b.a) circle(0.25pt);
fill[orange] (c.a) circle(0.25pt);
endtikzpicture
enddocument
I am a bit surprised that the black circle has a radius which is smaller than that of the inscribed circle in the polygon, since the pgf
manual says
[...] the border of the polygon is always constructed using the
incircle, whose radius is calculated to tightly fit the node contents
(including anyinner sep
).
To show what I would have expected and what I would like to have I added a blue "fake circle" to the MWE as a regular polygon with 100 sides. Is there a way to draw such a blue circle using the circle shape, i.e. node[circle, ...]XX;
? Playing by hand with inner sep
is not an option for me.
As clarification/additional information, I am interested in having a node shape to be used in a wider context, i.e. not in relation with the square. And also receiving an explanation about why the 4-sides polygon leaves so much space despite the inner sep=0
would be highly appreciated.
UPDATE: From the comments, indeed, there is some room of interpretation in the question. In short, I would like to answer these questions.
- How is it possible to have a
Circle
shape (orCircle
tikzstyle) that draws exactly the inscribed circle of the correspondentregular polygon
around a given node content? - Where does the discrepancy between black circle and square in my MWE come from?
- If easier (I can also use this other approach), how is it possible to have a
Regular Polygon
shape (or tikzstyle) that has as inscribed circle the correspondentcircle
around a given node content?
tikz-pgf
|
show 5 more comments
This question is a kind of continuation this answer. There, it remains unclear which is the origin of the white space around the node content, if a square shape is used, and I would like to understand this. Given the following MWE
documentclass[tikz, border=1mm]standalone
usetikzlibraryshapes.geometric
begindocument
begintikzpicture[every node/.style=draw, inner sep=0]
node[regular polygon,regular polygon sides=4] (a) XX;
node[regular polygon,regular polygon sides=100, blue] (b) XX;
node[circle] (c) XX;
foreach a in north,south,east,west,north east,south east,north west,south west
fill[red] (a.a) circle(0.5pt);
fill[yellow] (b.a) circle(0.25pt);
fill[orange] (c.a) circle(0.25pt);
endtikzpicture
enddocument
I am a bit surprised that the black circle has a radius which is smaller than that of the inscribed circle in the polygon, since the pgf
manual says
[...] the border of the polygon is always constructed using the
incircle, whose radius is calculated to tightly fit the node contents
(including anyinner sep
).
To show what I would have expected and what I would like to have I added a blue "fake circle" to the MWE as a regular polygon with 100 sides. Is there a way to draw such a blue circle using the circle shape, i.e. node[circle, ...]XX;
? Playing by hand with inner sep
is not an option for me.
As clarification/additional information, I am interested in having a node shape to be used in a wider context, i.e. not in relation with the square. And also receiving an explanation about why the 4-sides polygon leaves so much space despite the inner sep=0
would be highly appreciated.
UPDATE: From the comments, indeed, there is some room of interpretation in the question. In short, I would like to answer these questions.
- How is it possible to have a
Circle
shape (orCircle
tikzstyle) that draws exactly the inscribed circle of the correspondentregular polygon
around a given node content? - Where does the discrepancy between black circle and square in my MWE come from?
- If easier (I can also use this other approach), how is it possible to have a
Regular Polygon
shape (or tikzstyle) that has as inscribed circle the correspondentcircle
around a given node content?
tikz-pgf
You can see in the manual that for empty nodes the ratio issqrt(2)
(but I don't know why). In the manual a regular polygon with inner space equal to0.3535cm
(which issqrt(2)/4
) is tangent to circle with radius1/2 cm
.
– Kpym
Mar 21 at 12:50
I had noticed that strangeinner sep
in the example. But I had also noticed that it was about an empty node. If I have an arbitrary node content, I would then need to adjust that0.3535cm
magic number (and I should think about how). Are you suggesting something like that?
– Axel Krypton
Mar 21 at 13:07
1
Thissqrt(2)
factor does make sense if you assume the the content is approximately quadratic. And I do not understand the question. That is, I thought I did before I saw the answers. Could you perhaps indicate to which extent the answers address the question. I am really confused.
– marmot
Mar 21 at 14:19
1
@marmot As I understand the answer is "How to draw a circular shape that has the same inner circle as all other regular polygons".
– Kpym
Mar 21 at 14:32
1
@marmot I think that I have answered this par of the question : the the origin of the white space around the node content is that in the definition of theregular polygon
shape the inner radius is calculated differently from thecircle
shape (and the ratio between both depends on the shape, i.e. the aspect ratio).
– Kpym
Mar 21 at 15:52
|
show 5 more comments
This question is a kind of continuation this answer. There, it remains unclear which is the origin of the white space around the node content, if a square shape is used, and I would like to understand this. Given the following MWE
documentclass[tikz, border=1mm]standalone
usetikzlibraryshapes.geometric
begindocument
begintikzpicture[every node/.style=draw, inner sep=0]
node[regular polygon,regular polygon sides=4] (a) XX;
node[regular polygon,regular polygon sides=100, blue] (b) XX;
node[circle] (c) XX;
foreach a in north,south,east,west,north east,south east,north west,south west
fill[red] (a.a) circle(0.5pt);
fill[yellow] (b.a) circle(0.25pt);
fill[orange] (c.a) circle(0.25pt);
endtikzpicture
enddocument
I am a bit surprised that the black circle has a radius which is smaller than that of the inscribed circle in the polygon, since the pgf
manual says
[...] the border of the polygon is always constructed using the
incircle, whose radius is calculated to tightly fit the node contents
(including anyinner sep
).
To show what I would have expected and what I would like to have I added a blue "fake circle" to the MWE as a regular polygon with 100 sides. Is there a way to draw such a blue circle using the circle shape, i.e. node[circle, ...]XX;
? Playing by hand with inner sep
is not an option for me.
As clarification/additional information, I am interested in having a node shape to be used in a wider context, i.e. not in relation with the square. And also receiving an explanation about why the 4-sides polygon leaves so much space despite the inner sep=0
would be highly appreciated.
UPDATE: From the comments, indeed, there is some room of interpretation in the question. In short, I would like to answer these questions.
- How is it possible to have a
Circle
shape (orCircle
tikzstyle) that draws exactly the inscribed circle of the correspondentregular polygon
around a given node content? - Where does the discrepancy between black circle and square in my MWE come from?
- If easier (I can also use this other approach), how is it possible to have a
Regular Polygon
shape (or tikzstyle) that has as inscribed circle the correspondentcircle
around a given node content?
tikz-pgf
This question is a kind of continuation this answer. There, it remains unclear which is the origin of the white space around the node content, if a square shape is used, and I would like to understand this. Given the following MWE
documentclass[tikz, border=1mm]standalone
usetikzlibraryshapes.geometric
begindocument
begintikzpicture[every node/.style=draw, inner sep=0]
node[regular polygon,regular polygon sides=4] (a) XX;
node[regular polygon,regular polygon sides=100, blue] (b) XX;
node[circle] (c) XX;
foreach a in north,south,east,west,north east,south east,north west,south west
fill[red] (a.a) circle(0.5pt);
fill[yellow] (b.a) circle(0.25pt);
fill[orange] (c.a) circle(0.25pt);
endtikzpicture
enddocument
I am a bit surprised that the black circle has a radius which is smaller than that of the inscribed circle in the polygon, since the pgf
manual says
[...] the border of the polygon is always constructed using the
incircle, whose radius is calculated to tightly fit the node contents
(including anyinner sep
).
To show what I would have expected and what I would like to have I added a blue "fake circle" to the MWE as a regular polygon with 100 sides. Is there a way to draw such a blue circle using the circle shape, i.e. node[circle, ...]XX;
? Playing by hand with inner sep
is not an option for me.
As clarification/additional information, I am interested in having a node shape to be used in a wider context, i.e. not in relation with the square. And also receiving an explanation about why the 4-sides polygon leaves so much space despite the inner sep=0
would be highly appreciated.
UPDATE: From the comments, indeed, there is some room of interpretation in the question. In short, I would like to answer these questions.
- How is it possible to have a
Circle
shape (orCircle
tikzstyle) that draws exactly the inscribed circle of the correspondentregular polygon
around a given node content? - Where does the discrepancy between black circle and square in my MWE come from?
- If easier (I can also use this other approach), how is it possible to have a
Regular Polygon
shape (or tikzstyle) that has as inscribed circle the correspondentcircle
around a given node content?
tikz-pgf
tikz-pgf
edited Mar 21 at 16:50
Axel Krypton
asked Mar 21 at 11:17
Axel KryptonAxel Krypton
477211
477211
You can see in the manual that for empty nodes the ratio issqrt(2)
(but I don't know why). In the manual a regular polygon with inner space equal to0.3535cm
(which issqrt(2)/4
) is tangent to circle with radius1/2 cm
.
– Kpym
Mar 21 at 12:50
I had noticed that strangeinner sep
in the example. But I had also noticed that it was about an empty node. If I have an arbitrary node content, I would then need to adjust that0.3535cm
magic number (and I should think about how). Are you suggesting something like that?
– Axel Krypton
Mar 21 at 13:07
1
Thissqrt(2)
factor does make sense if you assume the the content is approximately quadratic. And I do not understand the question. That is, I thought I did before I saw the answers. Could you perhaps indicate to which extent the answers address the question. I am really confused.
– marmot
Mar 21 at 14:19
1
@marmot As I understand the answer is "How to draw a circular shape that has the same inner circle as all other regular polygons".
– Kpym
Mar 21 at 14:32
1
@marmot I think that I have answered this par of the question : the the origin of the white space around the node content is that in the definition of theregular polygon
shape the inner radius is calculated differently from thecircle
shape (and the ratio between both depends on the shape, i.e. the aspect ratio).
– Kpym
Mar 21 at 15:52
|
show 5 more comments
You can see in the manual that for empty nodes the ratio issqrt(2)
(but I don't know why). In the manual a regular polygon with inner space equal to0.3535cm
(which issqrt(2)/4
) is tangent to circle with radius1/2 cm
.
– Kpym
Mar 21 at 12:50
I had noticed that strangeinner sep
in the example. But I had also noticed that it was about an empty node. If I have an arbitrary node content, I would then need to adjust that0.3535cm
magic number (and I should think about how). Are you suggesting something like that?
– Axel Krypton
Mar 21 at 13:07
1
Thissqrt(2)
factor does make sense if you assume the the content is approximately quadratic. And I do not understand the question. That is, I thought I did before I saw the answers. Could you perhaps indicate to which extent the answers address the question. I am really confused.
– marmot
Mar 21 at 14:19
1
@marmot As I understand the answer is "How to draw a circular shape that has the same inner circle as all other regular polygons".
– Kpym
Mar 21 at 14:32
1
@marmot I think that I have answered this par of the question : the the origin of the white space around the node content is that in the definition of theregular polygon
shape the inner radius is calculated differently from thecircle
shape (and the ratio between both depends on the shape, i.e. the aspect ratio).
– Kpym
Mar 21 at 15:52
You can see in the manual that for empty nodes the ratio is
sqrt(2)
(but I don't know why). In the manual a regular polygon with inner space equal to 0.3535cm
(which is sqrt(2)/4
) is tangent to circle with radius 1/2 cm
.– Kpym
Mar 21 at 12:50
You can see in the manual that for empty nodes the ratio is
sqrt(2)
(but I don't know why). In the manual a regular polygon with inner space equal to 0.3535cm
(which is sqrt(2)/4
) is tangent to circle with radius 1/2 cm
.– Kpym
Mar 21 at 12:50
I had noticed that strange
inner sep
in the example. But I had also noticed that it was about an empty node. If I have an arbitrary node content, I would then need to adjust that 0.3535cm
magic number (and I should think about how). Are you suggesting something like that?– Axel Krypton
Mar 21 at 13:07
I had noticed that strange
inner sep
in the example. But I had also noticed that it was about an empty node. If I have an arbitrary node content, I would then need to adjust that 0.3535cm
magic number (and I should think about how). Are you suggesting something like that?– Axel Krypton
Mar 21 at 13:07
1
1
This
sqrt(2)
factor does make sense if you assume the the content is approximately quadratic. And I do not understand the question. That is, I thought I did before I saw the answers. Could you perhaps indicate to which extent the answers address the question. I am really confused.– marmot
Mar 21 at 14:19
This
sqrt(2)
factor does make sense if you assume the the content is approximately quadratic. And I do not understand the question. That is, I thought I did before I saw the answers. Could you perhaps indicate to which extent the answers address the question. I am really confused.– marmot
Mar 21 at 14:19
1
1
@marmot As I understand the answer is "How to draw a circular shape that has the same inner circle as all other regular polygons".
– Kpym
Mar 21 at 14:32
@marmot As I understand the answer is "How to draw a circular shape that has the same inner circle as all other regular polygons".
– Kpym
Mar 21 at 14:32
1
1
@marmot I think that I have answered this par of the question : the the origin of the white space around the node content is that in the definition of the
regular polygon
shape the inner radius is calculated differently from the circle
shape (and the ratio between both depends on the shape, i.e. the aspect ratio).– Kpym
Mar 21 at 15:52
@marmot I think that I have answered this par of the question : the the origin of the white space around the node content is that in the definition of the
regular polygon
shape the inner radius is calculated differently from the circle
shape (and the ratio between both depends on the shape, i.e. the aspect ratio).– Kpym
Mar 21 at 15:52
|
show 5 more comments
5 Answers
5
active
oldest
votes
The "inner circle" in shapes.geometric
has a radius that is half of the longest side of the content box plus the inner sep, and multiplied by 1.4142136
, which is approximately sqrt(2)
. So to obtain a circle shape that has this behavior you can define a new shape, let's say Circle
(with capital C) that is a slight modification of the existing ellipse
shape.
documentclass[tikz, border=7pt, convert=density=4200]standalone
usetikzlibraryshapes.geometric
makeatletter
pgfdeclareshapeCircle
%
% Draws a circle around the text
% (based on the original ellipse shape)
%
%
savedanchorcenterpoint%
pgf@x=.5wdpgfnodeparttextbox%
pgf@y=.5htpgfnodeparttextbox%
advancepgf@y by-.5dppgfnodeparttextbox%
%
savedanchorradius%
%
% Calculate ``height radius''
%
pgf@y=.5htpgfnodeparttextbox%
advancepgf@y by.5dppgfnodeparttextbox%
pgfmathsetlengthpgf@ybpgfkeysvalueof/pgf/inner ysep%
advancepgf@y bypgf@yb%
%
% Calculate ``width radius''
%
pgf@x=.5wdpgfnodeparttextbox%
pgfmathsetlengthpgf@xbpgfkeysvalueof/pgf/inner xsep%
advancepgf@x bypgf@xb%
%
% Adjust
%
% ==============================
% added to ellipse shape to become circle
ifdimpgf@y>pgf@x%
pgf@xpgf@y%
else%
pgf@ypgf@x%
fi%
% ==============================
pgf@x=1.4142136pgf@x%
pgf@y=1.4142136pgf@y%
%
% Adjust height, if necessary
%
pgfmathsetlengthpgf@ycpgfkeysvalueof/pgf/minimum height%
ifdimpgf@y<.5pgf@yc%
pgf@y=.5pgf@yc%
fi%
%
% Adjust width, if necessary
%
pgfmathsetlengthpgf@xcpgfkeysvalueof/pgf/minimum width%
ifdimpgf@x<.5pgf@xc%
pgf@x=.5pgf@xc%
fi%
%
% Add outer sep
%
pgfmathsetlengthpgf@xbpgfkeysvalueof/pgf/outer xsep%
pgfmathsetlengthpgf@ybpgfkeysvalueof/pgf/outer ysep%
advancepgf@x bypgf@xb%
advancepgf@y bypgf@yb%
%
%
% Anchors
%
anchorcentercenterpoint%
anchormidcenterpointpgfmathsetlengthpgf@y.5ex%
anchorbasecenterpointpgf@y=0pt%
anchornorth
pgf@processradius
pgf@ya=pgf@y%
pgf@processcenterpoint
advancepgf@y bypgf@ya
%
anchorsouth
pgf@processradius
pgf@ya=pgf@y%
pgf@processcenterpoint
advancepgf@y by-pgf@ya
%
anchorwest
pgf@processradius
pgf@xa=pgf@x%
pgf@processcenterpoint
advancepgf@x by-pgf@xa
%
anchormid west
%
pgf@processradius
pgf@xa=pgf@x%
pgf@processcenterpoint
advancepgf@x by-pgf@xa%
pgfmathsetlengthpgf@y.5ex
%
anchorbase west
%
pgf@processradius
pgf@xa=pgf@x%
pgf@processcenterpoint
advancepgf@x by-pgf@xa%
pgf@y=0pt
%
anchornorth west
pgf@processradius
pgf@xa=pgf@x%
pgf@ya=pgf@y%
pgf@processcenterpoint
advancepgf@x by-0.707107pgf@xa
advancepgf@y by0.707107pgf@ya
%
anchorsouth west
pgf@processradius
pgf@xa=pgf@x%
pgf@ya=pgf@y%
pgf@processcenterpoint
advancepgf@x by-0.707107pgf@xa
advancepgf@y by-0.707107pgf@ya
%
anchoreast
%
pgf@processradius
pgf@xa=pgf@x%
pgf@processcenterpoint
advancepgf@x bypgf@xa
%
anchormid east
%
pgf@processradius
pgf@xa=pgf@x%
pgf@processcenterpoint
advancepgf@x bypgf@xa%
pgfmathsetlengthpgf@y.5ex
%
anchorbase east
%
pgf@processradius
pgf@xa=pgf@x%
pgf@processcenterpoint
advancepgf@x bypgf@xa%
pgf@y=0pt
%
anchornorth east
pgf@processradius
pgf@xa=pgf@x%
pgf@ya=pgf@y%
pgf@processcenterpoint
advancepgf@x by0.707107pgf@xa
advancepgf@y by0.707107pgf@ya
%
anchorsouth east
pgf@processradius
pgf@xa=pgf@x%
pgf@ya=pgf@y%
pgf@processcenterpoint
advancepgf@x by0.707107pgf@xa
advancepgf@y by-0.707107pgf@ya
%
anchorborder
edefpgf@marshal%
noexpandpgfpointborderellipse
noexpandpgfqpointthepgf@xthepgf@y
noexpandradius%
%
pgf@marshal%
pgf@xa=pgf@x%
pgf@ya=pgf@y%
centerpoint%
advancepgf@x bypgf@xa%
advancepgf@y bypgf@ya%
%
%
% Background path
%
backgroundpath
pgf@processradius%
pgfutil@tempdima=pgf@x%
pgfutil@tempdimb=pgf@y%
pgfmathsetlengthpgf@xbpgfkeysvalueof/pgf/outer xsep%
pgfmathsetlengthpgf@ybpgfkeysvalueof/pgf/outer ysep%
advancepgfutil@tempdima by-pgf@xb%
advancepgfutil@tempdimb by-pgf@yb%
pgfpathellipsecenterpointpgfqpointpgfutil@tempdima0ptpgfqpoint0ptpgfutil@tempdimb%
%
%
makeatother
begindocument
begintikzpicture[nodes=draw, inner sep=0]
node[regular polygon,regular polygon sides=4] (a) XX;
node[Circle, blue] (b) XX;
node[circle] (c) XX;
foreach a in north,south,east,west,north east,south east,north west,south west
fill[red] (a.a) circle(0.5pt);
fill[yellow] (b.a) circle(0.25pt);
fill[orange] (c.a) circle(0.25pt);
endtikzpicture
enddocument
Addendum:
If you want to go the other way and create a circumscribed polygon around the standard circle
node style, that do not use low level tricks, you can define circumscribed polygon
that use append after command
to add well sized regular polygon
. This is not a robust code for meany reasons, it is just a proof of concept :
documentclass[tikz,border=7pt,convert=density=4200]standalone
usetikzlibrarycalc,shapes.geometric
% don't tell me to not use tikzstyle ;)
tikzstylecircumscribed polygon[draw]=[
circle,draw=none,fill=none,shade=none,
append after command=
let p1=($(tikzlastnode.west)-(tikzlastnode.east)$),
n1 = (veclen(p1)-pgflinewidth)/2.828427 % 2*sqrt(2) = 2.8284271247461903
in
(tikzlastnode.center) node[regular polygon, inner sep=n1, #1]
]
begindocument
begintikzpicture[inner sep=1mm]
foreach~in 3,...,7
node[circumscribed polygon=draw=blue!~0!green,regular polygon sides=~] XX;
node[circle,draw=red] XX;
endtikzpicture
enddocument
Very enlightening. I wonder if, then, rather than defining a completely new shape, it is not easier to find out a systematic way to give a proper, automatically determinedinner separation
to a normalcircle
. Analogously one could give an automatically determined negativeinner sep
to aregular polygon
. I will think about it, but you helped already a lot!
– Axel Krypton
Mar 21 at 16:55
And I would also say that thepgf
inherit...[from=ellipse]
commands might be useful to shorten the code, but I have to still explore this world and I might be completely wrong.
– Axel Krypton
Mar 21 at 17:01
Thanks for the added information, very useful, indeed. I came up with a slightly differentCircle
and I shared this in a separate answer. :)
– Axel Krypton
Mar 22 at 9:02
add a comment |
Using through
library of Tikz.
documentclass[tikz, border=1mm]standalone
usetikzlibraryshapes.geometric,through
begindocument
begintikzpicture[every node/.style=draw, inner sep=0]
node[regular polygon,regular polygon sides=4] (a) XX;
node (b) [draw,blue, circle through=(a.north)] at (a.center) XX;
node[circle] (c) XX;
foreach a in north,south,east,west,north east,south east,north west,south west
fill[red] (a.a) circle(0.5pt);
fill[yellow] (b.a) circle(0.25pt);
fill[orange] (c.a) circle(0.25pt);
endtikzpicture
enddocument
Although strictly speaking you proposed a valid way to draw the blue circle, I was more interested in a general way to draw that shape for a node, without having to rely to another node/point (see edit question). The only way I see I could use your idea is to always have two nodes, one invisible and one that would be the node I wish. However, this is not what I am looking for.
– Axel Krypton
Mar 21 at 12:25
add a comment |
Just to share a different way to achieve what Kpym did in his very nice answer declaring a new shape, I thought one could have simply a Circle
style which sets properly the minimum size of a circle shape (in this particular case it is always true that the content will never exceed the minimum size
since we are trying to enlarge the circle). It should work for any node content, no matter if its width is larger than its height or vice-versa. A couple of remarks:
- In this approach the node name and the node position must be declared before the options or inside them using the
name
andat
keys, respectively. - A
Circle
inner sep
has to be specified before theCircle
style, but it might easily be improved, if needed otherwise.
Here the code:
documentclass[tikz, border=1mm]standalone
usetikzlibraryshapes.geometric
tikzset%
Square/.style=regular polygon, regular polygon sides=4,
Circle/.style=%
circle,
/utils/exec=%
pgfmathsetmacropolygonIncircleDiameter
sqrt(2)*max(width("#1")+2*pgfshapeinnerxsep, height("#1") + depth("#1") + 2 * pgfshapeinnerysep)
,
minimum size=polygonIncircleDiameter,
node contents=#1
begindocument
begintikzpicture
node[inner sep=0, Square, draw=cyan] at (0,0) xx;
node[inner sep=0, Circle=xx, draw=blue];
node[Square, draw=cyan] at (1,0) i;
node[Circle=i, draw=blue, at=(1,0)];
endtikzpicture
enddocument
Very nice ! Two remarks : it would be nice to not pass the node content as parameter toCircle
but I think that this will be tricky, and probablypolygonIncircleDiameter
is better than to divide and then multiply by 2 thepolygonIncircleRadius
.
– Kpym
Mar 22 at 9:31
I implemented your suggestion, it definitely makes sense! :) About not passing the node content to the style, well, honestly I would not know how to then achieve the same result. Yes, it definitely looks tricky to me.
– Axel Krypton
Mar 22 at 9:41
add a comment |
This wraps a polyogon around the circle.
documentclass[tikz,border=3.14mm]standalone
usetikzlibrarycalc
begindocument
begintikzpicture[every node/.style=draw, inner sep=0,
polygon with circle/.style args=#1 inscribed and #2 cornersinsert path=%
let p1=($(#1.0)-(#1.center)$),n1=abs(x1)/cos(180/#2)
in ($(#1.center)+(0:n1)$)
foreach X in 1,...,numexpr#2-1
-- ($(#1.center)+(360*X/#2:n1)$) -- cycle]
node[circle] (c) XX;
draw[blue,polygon with circle=c inscribed and 12 corners] ;
foreach a in north,south,east,west,north east,south east,north west,south west
fill[orange] (c.a) circle(0.25pt);
endtikzpicture
enddocument
add a comment |
This solution uses calc
library to compute regular polygon's inner radius. This way it's possible to compute circunscribed circle's minimum width.
documentclass[tikz, border=1mm]standalone
usetikzlibraryshapes.geometric, calc
begindocument
begintikzpicture
node[inner sep=0, regular polygon, regular polygon sides=4, draw=cyan] (a) xx;
path let p1=($(a.center)-(a.side 1)$) in node[circle, inner sep=0, minimum width=2*veclen(x1,y1)-pgflinewidth, draw=blue] ;
node[inner sep=0, draw=cyan, regular polygon, regular polygon sides=7] (b) at (1,0) i;
path let p1=($(b.center)-(b.side 1)$) in node[circle, inner sep=0, minimum width=2*veclen(x1,y1)-pgflinewidth, draw=blue] at (b) ;
endtikzpicture
enddocument
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%2f480661%2fregular-polygon-vs-circle-shapes-in-tikz%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
The "inner circle" in shapes.geometric
has a radius that is half of the longest side of the content box plus the inner sep, and multiplied by 1.4142136
, which is approximately sqrt(2)
. So to obtain a circle shape that has this behavior you can define a new shape, let's say Circle
(with capital C) that is a slight modification of the existing ellipse
shape.
documentclass[tikz, border=7pt, convert=density=4200]standalone
usetikzlibraryshapes.geometric
makeatletter
pgfdeclareshapeCircle
%
% Draws a circle around the text
% (based on the original ellipse shape)
%
%
savedanchorcenterpoint%
pgf@x=.5wdpgfnodeparttextbox%
pgf@y=.5htpgfnodeparttextbox%
advancepgf@y by-.5dppgfnodeparttextbox%
%
savedanchorradius%
%
% Calculate ``height radius''
%
pgf@y=.5htpgfnodeparttextbox%
advancepgf@y by.5dppgfnodeparttextbox%
pgfmathsetlengthpgf@ybpgfkeysvalueof/pgf/inner ysep%
advancepgf@y bypgf@yb%
%
% Calculate ``width radius''
%
pgf@x=.5wdpgfnodeparttextbox%
pgfmathsetlengthpgf@xbpgfkeysvalueof/pgf/inner xsep%
advancepgf@x bypgf@xb%
%
% Adjust
%
% ==============================
% added to ellipse shape to become circle
ifdimpgf@y>pgf@x%
pgf@xpgf@y%
else%
pgf@ypgf@x%
fi%
% ==============================
pgf@x=1.4142136pgf@x%
pgf@y=1.4142136pgf@y%
%
% Adjust height, if necessary
%
pgfmathsetlengthpgf@ycpgfkeysvalueof/pgf/minimum height%
ifdimpgf@y<.5pgf@yc%
pgf@y=.5pgf@yc%
fi%
%
% Adjust width, if necessary
%
pgfmathsetlengthpgf@xcpgfkeysvalueof/pgf/minimum width%
ifdimpgf@x<.5pgf@xc%
pgf@x=.5pgf@xc%
fi%
%
% Add outer sep
%
pgfmathsetlengthpgf@xbpgfkeysvalueof/pgf/outer xsep%
pgfmathsetlengthpgf@ybpgfkeysvalueof/pgf/outer ysep%
advancepgf@x bypgf@xb%
advancepgf@y bypgf@yb%
%
%
% Anchors
%
anchorcentercenterpoint%
anchormidcenterpointpgfmathsetlengthpgf@y.5ex%
anchorbasecenterpointpgf@y=0pt%
anchornorth
pgf@processradius
pgf@ya=pgf@y%
pgf@processcenterpoint
advancepgf@y bypgf@ya
%
anchorsouth
pgf@processradius
pgf@ya=pgf@y%
pgf@processcenterpoint
advancepgf@y by-pgf@ya
%
anchorwest
pgf@processradius
pgf@xa=pgf@x%
pgf@processcenterpoint
advancepgf@x by-pgf@xa
%
anchormid west
%
pgf@processradius
pgf@xa=pgf@x%
pgf@processcenterpoint
advancepgf@x by-pgf@xa%
pgfmathsetlengthpgf@y.5ex
%
anchorbase west
%
pgf@processradius
pgf@xa=pgf@x%
pgf@processcenterpoint
advancepgf@x by-pgf@xa%
pgf@y=0pt
%
anchornorth west
pgf@processradius
pgf@xa=pgf@x%
pgf@ya=pgf@y%
pgf@processcenterpoint
advancepgf@x by-0.707107pgf@xa
advancepgf@y by0.707107pgf@ya
%
anchorsouth west
pgf@processradius
pgf@xa=pgf@x%
pgf@ya=pgf@y%
pgf@processcenterpoint
advancepgf@x by-0.707107pgf@xa
advancepgf@y by-0.707107pgf@ya
%
anchoreast
%
pgf@processradius
pgf@xa=pgf@x%
pgf@processcenterpoint
advancepgf@x bypgf@xa
%
anchormid east
%
pgf@processradius
pgf@xa=pgf@x%
pgf@processcenterpoint
advancepgf@x bypgf@xa%
pgfmathsetlengthpgf@y.5ex
%
anchorbase east
%
pgf@processradius
pgf@xa=pgf@x%
pgf@processcenterpoint
advancepgf@x bypgf@xa%
pgf@y=0pt
%
anchornorth east
pgf@processradius
pgf@xa=pgf@x%
pgf@ya=pgf@y%
pgf@processcenterpoint
advancepgf@x by0.707107pgf@xa
advancepgf@y by0.707107pgf@ya
%
anchorsouth east
pgf@processradius
pgf@xa=pgf@x%
pgf@ya=pgf@y%
pgf@processcenterpoint
advancepgf@x by0.707107pgf@xa
advancepgf@y by-0.707107pgf@ya
%
anchorborder
edefpgf@marshal%
noexpandpgfpointborderellipse
noexpandpgfqpointthepgf@xthepgf@y
noexpandradius%
%
pgf@marshal%
pgf@xa=pgf@x%
pgf@ya=pgf@y%
centerpoint%
advancepgf@x bypgf@xa%
advancepgf@y bypgf@ya%
%
%
% Background path
%
backgroundpath
pgf@processradius%
pgfutil@tempdima=pgf@x%
pgfutil@tempdimb=pgf@y%
pgfmathsetlengthpgf@xbpgfkeysvalueof/pgf/outer xsep%
pgfmathsetlengthpgf@ybpgfkeysvalueof/pgf/outer ysep%
advancepgfutil@tempdima by-pgf@xb%
advancepgfutil@tempdimb by-pgf@yb%
pgfpathellipsecenterpointpgfqpointpgfutil@tempdima0ptpgfqpoint0ptpgfutil@tempdimb%
%
%
makeatother
begindocument
begintikzpicture[nodes=draw, inner sep=0]
node[regular polygon,regular polygon sides=4] (a) XX;
node[Circle, blue] (b) XX;
node[circle] (c) XX;
foreach a in north,south,east,west,north east,south east,north west,south west
fill[red] (a.a) circle(0.5pt);
fill[yellow] (b.a) circle(0.25pt);
fill[orange] (c.a) circle(0.25pt);
endtikzpicture
enddocument
Addendum:
If you want to go the other way and create a circumscribed polygon around the standard circle
node style, that do not use low level tricks, you can define circumscribed polygon
that use append after command
to add well sized regular polygon
. This is not a robust code for meany reasons, it is just a proof of concept :
documentclass[tikz,border=7pt,convert=density=4200]standalone
usetikzlibrarycalc,shapes.geometric
% don't tell me to not use tikzstyle ;)
tikzstylecircumscribed polygon[draw]=[
circle,draw=none,fill=none,shade=none,
append after command=
let p1=($(tikzlastnode.west)-(tikzlastnode.east)$),
n1 = (veclen(p1)-pgflinewidth)/2.828427 % 2*sqrt(2) = 2.8284271247461903
in
(tikzlastnode.center) node[regular polygon, inner sep=n1, #1]
]
begindocument
begintikzpicture[inner sep=1mm]
foreach~in 3,...,7
node[circumscribed polygon=draw=blue!~0!green,regular polygon sides=~] XX;
node[circle,draw=red] XX;
endtikzpicture
enddocument
Very enlightening. I wonder if, then, rather than defining a completely new shape, it is not easier to find out a systematic way to give a proper, automatically determinedinner separation
to a normalcircle
. Analogously one could give an automatically determined negativeinner sep
to aregular polygon
. I will think about it, but you helped already a lot!
– Axel Krypton
Mar 21 at 16:55
And I would also say that thepgf
inherit...[from=ellipse]
commands might be useful to shorten the code, but I have to still explore this world and I might be completely wrong.
– Axel Krypton
Mar 21 at 17:01
Thanks for the added information, very useful, indeed. I came up with a slightly differentCircle
and I shared this in a separate answer. :)
– Axel Krypton
Mar 22 at 9:02
add a comment |
The "inner circle" in shapes.geometric
has a radius that is half of the longest side of the content box plus the inner sep, and multiplied by 1.4142136
, which is approximately sqrt(2)
. So to obtain a circle shape that has this behavior you can define a new shape, let's say Circle
(with capital C) that is a slight modification of the existing ellipse
shape.
documentclass[tikz, border=7pt, convert=density=4200]standalone
usetikzlibraryshapes.geometric
makeatletter
pgfdeclareshapeCircle
%
% Draws a circle around the text
% (based on the original ellipse shape)
%
%
savedanchorcenterpoint%
pgf@x=.5wdpgfnodeparttextbox%
pgf@y=.5htpgfnodeparttextbox%
advancepgf@y by-.5dppgfnodeparttextbox%
%
savedanchorradius%
%
% Calculate ``height radius''
%
pgf@y=.5htpgfnodeparttextbox%
advancepgf@y by.5dppgfnodeparttextbox%
pgfmathsetlengthpgf@ybpgfkeysvalueof/pgf/inner ysep%
advancepgf@y bypgf@yb%
%
% Calculate ``width radius''
%
pgf@x=.5wdpgfnodeparttextbox%
pgfmathsetlengthpgf@xbpgfkeysvalueof/pgf/inner xsep%
advancepgf@x bypgf@xb%
%
% Adjust
%
% ==============================
% added to ellipse shape to become circle
ifdimpgf@y>pgf@x%
pgf@xpgf@y%
else%
pgf@ypgf@x%
fi%
% ==============================
pgf@x=1.4142136pgf@x%
pgf@y=1.4142136pgf@y%
%
% Adjust height, if necessary
%
pgfmathsetlengthpgf@ycpgfkeysvalueof/pgf/minimum height%
ifdimpgf@y<.5pgf@yc%
pgf@y=.5pgf@yc%
fi%
%
% Adjust width, if necessary
%
pgfmathsetlengthpgf@xcpgfkeysvalueof/pgf/minimum width%
ifdimpgf@x<.5pgf@xc%
pgf@x=.5pgf@xc%
fi%
%
% Add outer sep
%
pgfmathsetlengthpgf@xbpgfkeysvalueof/pgf/outer xsep%
pgfmathsetlengthpgf@ybpgfkeysvalueof/pgf/outer ysep%
advancepgf@x bypgf@xb%
advancepgf@y bypgf@yb%
%
%
% Anchors
%
anchorcentercenterpoint%
anchormidcenterpointpgfmathsetlengthpgf@y.5ex%
anchorbasecenterpointpgf@y=0pt%
anchornorth
pgf@processradius
pgf@ya=pgf@y%
pgf@processcenterpoint
advancepgf@y bypgf@ya
%
anchorsouth
pgf@processradius
pgf@ya=pgf@y%
pgf@processcenterpoint
advancepgf@y by-pgf@ya
%
anchorwest
pgf@processradius
pgf@xa=pgf@x%
pgf@processcenterpoint
advancepgf@x by-pgf@xa
%
anchormid west
%
pgf@processradius
pgf@xa=pgf@x%
pgf@processcenterpoint
advancepgf@x by-pgf@xa%
pgfmathsetlengthpgf@y.5ex
%
anchorbase west
%
pgf@processradius
pgf@xa=pgf@x%
pgf@processcenterpoint
advancepgf@x by-pgf@xa%
pgf@y=0pt
%
anchornorth west
pgf@processradius
pgf@xa=pgf@x%
pgf@ya=pgf@y%
pgf@processcenterpoint
advancepgf@x by-0.707107pgf@xa
advancepgf@y by0.707107pgf@ya
%
anchorsouth west
pgf@processradius
pgf@xa=pgf@x%
pgf@ya=pgf@y%
pgf@processcenterpoint
advancepgf@x by-0.707107pgf@xa
advancepgf@y by-0.707107pgf@ya
%
anchoreast
%
pgf@processradius
pgf@xa=pgf@x%
pgf@processcenterpoint
advancepgf@x bypgf@xa
%
anchormid east
%
pgf@processradius
pgf@xa=pgf@x%
pgf@processcenterpoint
advancepgf@x bypgf@xa%
pgfmathsetlengthpgf@y.5ex
%
anchorbase east
%
pgf@processradius
pgf@xa=pgf@x%
pgf@processcenterpoint
advancepgf@x bypgf@xa%
pgf@y=0pt
%
anchornorth east
pgf@processradius
pgf@xa=pgf@x%
pgf@ya=pgf@y%
pgf@processcenterpoint
advancepgf@x by0.707107pgf@xa
advancepgf@y by0.707107pgf@ya
%
anchorsouth east
pgf@processradius
pgf@xa=pgf@x%
pgf@ya=pgf@y%
pgf@processcenterpoint
advancepgf@x by0.707107pgf@xa
advancepgf@y by-0.707107pgf@ya
%
anchorborder
edefpgf@marshal%
noexpandpgfpointborderellipse
noexpandpgfqpointthepgf@xthepgf@y
noexpandradius%
%
pgf@marshal%
pgf@xa=pgf@x%
pgf@ya=pgf@y%
centerpoint%
advancepgf@x bypgf@xa%
advancepgf@y bypgf@ya%
%
%
% Background path
%
backgroundpath
pgf@processradius%
pgfutil@tempdima=pgf@x%
pgfutil@tempdimb=pgf@y%
pgfmathsetlengthpgf@xbpgfkeysvalueof/pgf/outer xsep%
pgfmathsetlengthpgf@ybpgfkeysvalueof/pgf/outer ysep%
advancepgfutil@tempdima by-pgf@xb%
advancepgfutil@tempdimb by-pgf@yb%
pgfpathellipsecenterpointpgfqpointpgfutil@tempdima0ptpgfqpoint0ptpgfutil@tempdimb%
%
%
makeatother
begindocument
begintikzpicture[nodes=draw, inner sep=0]
node[regular polygon,regular polygon sides=4] (a) XX;
node[Circle, blue] (b) XX;
node[circle] (c) XX;
foreach a in north,south,east,west,north east,south east,north west,south west
fill[red] (a.a) circle(0.5pt);
fill[yellow] (b.a) circle(0.25pt);
fill[orange] (c.a) circle(0.25pt);
endtikzpicture
enddocument
Addendum:
If you want to go the other way and create a circumscribed polygon around the standard circle
node style, that do not use low level tricks, you can define circumscribed polygon
that use append after command
to add well sized regular polygon
. This is not a robust code for meany reasons, it is just a proof of concept :
documentclass[tikz,border=7pt,convert=density=4200]standalone
usetikzlibrarycalc,shapes.geometric
% don't tell me to not use tikzstyle ;)
tikzstylecircumscribed polygon[draw]=[
circle,draw=none,fill=none,shade=none,
append after command=
let p1=($(tikzlastnode.west)-(tikzlastnode.east)$),
n1 = (veclen(p1)-pgflinewidth)/2.828427 % 2*sqrt(2) = 2.8284271247461903
in
(tikzlastnode.center) node[regular polygon, inner sep=n1, #1]
]
begindocument
begintikzpicture[inner sep=1mm]
foreach~in 3,...,7
node[circumscribed polygon=draw=blue!~0!green,regular polygon sides=~] XX;
node[circle,draw=red] XX;
endtikzpicture
enddocument
Very enlightening. I wonder if, then, rather than defining a completely new shape, it is not easier to find out a systematic way to give a proper, automatically determinedinner separation
to a normalcircle
. Analogously one could give an automatically determined negativeinner sep
to aregular polygon
. I will think about it, but you helped already a lot!
– Axel Krypton
Mar 21 at 16:55
And I would also say that thepgf
inherit...[from=ellipse]
commands might be useful to shorten the code, but I have to still explore this world and I might be completely wrong.
– Axel Krypton
Mar 21 at 17:01
Thanks for the added information, very useful, indeed. I came up with a slightly differentCircle
and I shared this in a separate answer. :)
– Axel Krypton
Mar 22 at 9:02
add a comment |
The "inner circle" in shapes.geometric
has a radius that is half of the longest side of the content box plus the inner sep, and multiplied by 1.4142136
, which is approximately sqrt(2)
. So to obtain a circle shape that has this behavior you can define a new shape, let's say Circle
(with capital C) that is a slight modification of the existing ellipse
shape.
documentclass[tikz, border=7pt, convert=density=4200]standalone
usetikzlibraryshapes.geometric
makeatletter
pgfdeclareshapeCircle
%
% Draws a circle around the text
% (based on the original ellipse shape)
%
%
savedanchorcenterpoint%
pgf@x=.5wdpgfnodeparttextbox%
pgf@y=.5htpgfnodeparttextbox%
advancepgf@y by-.5dppgfnodeparttextbox%
%
savedanchorradius%
%
% Calculate ``height radius''
%
pgf@y=.5htpgfnodeparttextbox%
advancepgf@y by.5dppgfnodeparttextbox%
pgfmathsetlengthpgf@ybpgfkeysvalueof/pgf/inner ysep%
advancepgf@y bypgf@yb%
%
% Calculate ``width radius''
%
pgf@x=.5wdpgfnodeparttextbox%
pgfmathsetlengthpgf@xbpgfkeysvalueof/pgf/inner xsep%
advancepgf@x bypgf@xb%
%
% Adjust
%
% ==============================
% added to ellipse shape to become circle
ifdimpgf@y>pgf@x%
pgf@xpgf@y%
else%
pgf@ypgf@x%
fi%
% ==============================
pgf@x=1.4142136pgf@x%
pgf@y=1.4142136pgf@y%
%
% Adjust height, if necessary
%
pgfmathsetlengthpgf@ycpgfkeysvalueof/pgf/minimum height%
ifdimpgf@y<.5pgf@yc%
pgf@y=.5pgf@yc%
fi%
%
% Adjust width, if necessary
%
pgfmathsetlengthpgf@xcpgfkeysvalueof/pgf/minimum width%
ifdimpgf@x<.5pgf@xc%
pgf@x=.5pgf@xc%
fi%
%
% Add outer sep
%
pgfmathsetlengthpgf@xbpgfkeysvalueof/pgf/outer xsep%
pgfmathsetlengthpgf@ybpgfkeysvalueof/pgf/outer ysep%
advancepgf@x bypgf@xb%
advancepgf@y bypgf@yb%
%
%
% Anchors
%
anchorcentercenterpoint%
anchormidcenterpointpgfmathsetlengthpgf@y.5ex%
anchorbasecenterpointpgf@y=0pt%
anchornorth
pgf@processradius
pgf@ya=pgf@y%
pgf@processcenterpoint
advancepgf@y bypgf@ya
%
anchorsouth
pgf@processradius
pgf@ya=pgf@y%
pgf@processcenterpoint
advancepgf@y by-pgf@ya
%
anchorwest
pgf@processradius
pgf@xa=pgf@x%
pgf@processcenterpoint
advancepgf@x by-pgf@xa
%
anchormid west
%
pgf@processradius
pgf@xa=pgf@x%
pgf@processcenterpoint
advancepgf@x by-pgf@xa%
pgfmathsetlengthpgf@y.5ex
%
anchorbase west
%
pgf@processradius
pgf@xa=pgf@x%
pgf@processcenterpoint
advancepgf@x by-pgf@xa%
pgf@y=0pt
%
anchornorth west
pgf@processradius
pgf@xa=pgf@x%
pgf@ya=pgf@y%
pgf@processcenterpoint
advancepgf@x by-0.707107pgf@xa
advancepgf@y by0.707107pgf@ya
%
anchorsouth west
pgf@processradius
pgf@xa=pgf@x%
pgf@ya=pgf@y%
pgf@processcenterpoint
advancepgf@x by-0.707107pgf@xa
advancepgf@y by-0.707107pgf@ya
%
anchoreast
%
pgf@processradius
pgf@xa=pgf@x%
pgf@processcenterpoint
advancepgf@x bypgf@xa
%
anchormid east
%
pgf@processradius
pgf@xa=pgf@x%
pgf@processcenterpoint
advancepgf@x bypgf@xa%
pgfmathsetlengthpgf@y.5ex
%
anchorbase east
%
pgf@processradius
pgf@xa=pgf@x%
pgf@processcenterpoint
advancepgf@x bypgf@xa%
pgf@y=0pt
%
anchornorth east
pgf@processradius
pgf@xa=pgf@x%
pgf@ya=pgf@y%
pgf@processcenterpoint
advancepgf@x by0.707107pgf@xa
advancepgf@y by0.707107pgf@ya
%
anchorsouth east
pgf@processradius
pgf@xa=pgf@x%
pgf@ya=pgf@y%
pgf@processcenterpoint
advancepgf@x by0.707107pgf@xa
advancepgf@y by-0.707107pgf@ya
%
anchorborder
edefpgf@marshal%
noexpandpgfpointborderellipse
noexpandpgfqpointthepgf@xthepgf@y
noexpandradius%
%
pgf@marshal%
pgf@xa=pgf@x%
pgf@ya=pgf@y%
centerpoint%
advancepgf@x bypgf@xa%
advancepgf@y bypgf@ya%
%
%
% Background path
%
backgroundpath
pgf@processradius%
pgfutil@tempdima=pgf@x%
pgfutil@tempdimb=pgf@y%
pgfmathsetlengthpgf@xbpgfkeysvalueof/pgf/outer xsep%
pgfmathsetlengthpgf@ybpgfkeysvalueof/pgf/outer ysep%
advancepgfutil@tempdima by-pgf@xb%
advancepgfutil@tempdimb by-pgf@yb%
pgfpathellipsecenterpointpgfqpointpgfutil@tempdima0ptpgfqpoint0ptpgfutil@tempdimb%
%
%
makeatother
begindocument
begintikzpicture[nodes=draw, inner sep=0]
node[regular polygon,regular polygon sides=4] (a) XX;
node[Circle, blue] (b) XX;
node[circle] (c) XX;
foreach a in north,south,east,west,north east,south east,north west,south west
fill[red] (a.a) circle(0.5pt);
fill[yellow] (b.a) circle(0.25pt);
fill[orange] (c.a) circle(0.25pt);
endtikzpicture
enddocument
Addendum:
If you want to go the other way and create a circumscribed polygon around the standard circle
node style, that do not use low level tricks, you can define circumscribed polygon
that use append after command
to add well sized regular polygon
. This is not a robust code for meany reasons, it is just a proof of concept :
documentclass[tikz,border=7pt,convert=density=4200]standalone
usetikzlibrarycalc,shapes.geometric
% don't tell me to not use tikzstyle ;)
tikzstylecircumscribed polygon[draw]=[
circle,draw=none,fill=none,shade=none,
append after command=
let p1=($(tikzlastnode.west)-(tikzlastnode.east)$),
n1 = (veclen(p1)-pgflinewidth)/2.828427 % 2*sqrt(2) = 2.8284271247461903
in
(tikzlastnode.center) node[regular polygon, inner sep=n1, #1]
]
begindocument
begintikzpicture[inner sep=1mm]
foreach~in 3,...,7
node[circumscribed polygon=draw=blue!~0!green,regular polygon sides=~] XX;
node[circle,draw=red] XX;
endtikzpicture
enddocument
The "inner circle" in shapes.geometric
has a radius that is half of the longest side of the content box plus the inner sep, and multiplied by 1.4142136
, which is approximately sqrt(2)
. So to obtain a circle shape that has this behavior you can define a new shape, let's say Circle
(with capital C) that is a slight modification of the existing ellipse
shape.
documentclass[tikz, border=7pt, convert=density=4200]standalone
usetikzlibraryshapes.geometric
makeatletter
pgfdeclareshapeCircle
%
% Draws a circle around the text
% (based on the original ellipse shape)
%
%
savedanchorcenterpoint%
pgf@x=.5wdpgfnodeparttextbox%
pgf@y=.5htpgfnodeparttextbox%
advancepgf@y by-.5dppgfnodeparttextbox%
%
savedanchorradius%
%
% Calculate ``height radius''
%
pgf@y=.5htpgfnodeparttextbox%
advancepgf@y by.5dppgfnodeparttextbox%
pgfmathsetlengthpgf@ybpgfkeysvalueof/pgf/inner ysep%
advancepgf@y bypgf@yb%
%
% Calculate ``width radius''
%
pgf@x=.5wdpgfnodeparttextbox%
pgfmathsetlengthpgf@xbpgfkeysvalueof/pgf/inner xsep%
advancepgf@x bypgf@xb%
%
% Adjust
%
% ==============================
% added to ellipse shape to become circle
ifdimpgf@y>pgf@x%
pgf@xpgf@y%
else%
pgf@ypgf@x%
fi%
% ==============================
pgf@x=1.4142136pgf@x%
pgf@y=1.4142136pgf@y%
%
% Adjust height, if necessary
%
pgfmathsetlengthpgf@ycpgfkeysvalueof/pgf/minimum height%
ifdimpgf@y<.5pgf@yc%
pgf@y=.5pgf@yc%
fi%
%
% Adjust width, if necessary
%
pgfmathsetlengthpgf@xcpgfkeysvalueof/pgf/minimum width%
ifdimpgf@x<.5pgf@xc%
pgf@x=.5pgf@xc%
fi%
%
% Add outer sep
%
pgfmathsetlengthpgf@xbpgfkeysvalueof/pgf/outer xsep%
pgfmathsetlengthpgf@ybpgfkeysvalueof/pgf/outer ysep%
advancepgf@x bypgf@xb%
advancepgf@y bypgf@yb%
%
%
% Anchors
%
anchorcentercenterpoint%
anchormidcenterpointpgfmathsetlengthpgf@y.5ex%
anchorbasecenterpointpgf@y=0pt%
anchornorth
pgf@processradius
pgf@ya=pgf@y%
pgf@processcenterpoint
advancepgf@y bypgf@ya
%
anchorsouth
pgf@processradius
pgf@ya=pgf@y%
pgf@processcenterpoint
advancepgf@y by-pgf@ya
%
anchorwest
pgf@processradius
pgf@xa=pgf@x%
pgf@processcenterpoint
advancepgf@x by-pgf@xa
%
anchormid west
%
pgf@processradius
pgf@xa=pgf@x%
pgf@processcenterpoint
advancepgf@x by-pgf@xa%
pgfmathsetlengthpgf@y.5ex
%
anchorbase west
%
pgf@processradius
pgf@xa=pgf@x%
pgf@processcenterpoint
advancepgf@x by-pgf@xa%
pgf@y=0pt
%
anchornorth west
pgf@processradius
pgf@xa=pgf@x%
pgf@ya=pgf@y%
pgf@processcenterpoint
advancepgf@x by-0.707107pgf@xa
advancepgf@y by0.707107pgf@ya
%
anchorsouth west
pgf@processradius
pgf@xa=pgf@x%
pgf@ya=pgf@y%
pgf@processcenterpoint
advancepgf@x by-0.707107pgf@xa
advancepgf@y by-0.707107pgf@ya
%
anchoreast
%
pgf@processradius
pgf@xa=pgf@x%
pgf@processcenterpoint
advancepgf@x bypgf@xa
%
anchormid east
%
pgf@processradius
pgf@xa=pgf@x%
pgf@processcenterpoint
advancepgf@x bypgf@xa%
pgfmathsetlengthpgf@y.5ex
%
anchorbase east
%
pgf@processradius
pgf@xa=pgf@x%
pgf@processcenterpoint
advancepgf@x bypgf@xa%
pgf@y=0pt
%
anchornorth east
pgf@processradius
pgf@xa=pgf@x%
pgf@ya=pgf@y%
pgf@processcenterpoint
advancepgf@x by0.707107pgf@xa
advancepgf@y by0.707107pgf@ya
%
anchorsouth east
pgf@processradius
pgf@xa=pgf@x%
pgf@ya=pgf@y%
pgf@processcenterpoint
advancepgf@x by0.707107pgf@xa
advancepgf@y by-0.707107pgf@ya
%
anchorborder
edefpgf@marshal%
noexpandpgfpointborderellipse
noexpandpgfqpointthepgf@xthepgf@y
noexpandradius%
%
pgf@marshal%
pgf@xa=pgf@x%
pgf@ya=pgf@y%
centerpoint%
advancepgf@x bypgf@xa%
advancepgf@y bypgf@ya%
%
%
% Background path
%
backgroundpath
pgf@processradius%
pgfutil@tempdima=pgf@x%
pgfutil@tempdimb=pgf@y%
pgfmathsetlengthpgf@xbpgfkeysvalueof/pgf/outer xsep%
pgfmathsetlengthpgf@ybpgfkeysvalueof/pgf/outer ysep%
advancepgfutil@tempdima by-pgf@xb%
advancepgfutil@tempdimb by-pgf@yb%
pgfpathellipsecenterpointpgfqpointpgfutil@tempdima0ptpgfqpoint0ptpgfutil@tempdimb%
%
%
makeatother
begindocument
begintikzpicture[nodes=draw, inner sep=0]
node[regular polygon,regular polygon sides=4] (a) XX;
node[Circle, blue] (b) XX;
node[circle] (c) XX;
foreach a in north,south,east,west,north east,south east,north west,south west
fill[red] (a.a) circle(0.5pt);
fill[yellow] (b.a) circle(0.25pt);
fill[orange] (c.a) circle(0.25pt);
endtikzpicture
enddocument
Addendum:
If you want to go the other way and create a circumscribed polygon around the standard circle
node style, that do not use low level tricks, you can define circumscribed polygon
that use append after command
to add well sized regular polygon
. This is not a robust code for meany reasons, it is just a proof of concept :
documentclass[tikz,border=7pt,convert=density=4200]standalone
usetikzlibrarycalc,shapes.geometric
% don't tell me to not use tikzstyle ;)
tikzstylecircumscribed polygon[draw]=[
circle,draw=none,fill=none,shade=none,
append after command=
let p1=($(tikzlastnode.west)-(tikzlastnode.east)$),
n1 = (veclen(p1)-pgflinewidth)/2.828427 % 2*sqrt(2) = 2.8284271247461903
in
(tikzlastnode.center) node[regular polygon, inner sep=n1, #1]
]
begindocument
begintikzpicture[inner sep=1mm]
foreach~in 3,...,7
node[circumscribed polygon=draw=blue!~0!green,regular polygon sides=~] XX;
node[circle,draw=red] XX;
endtikzpicture
enddocument
edited Mar 22 at 8:20
answered Mar 21 at 14:05
KpymKpym
17.7k24191
17.7k24191
Very enlightening. I wonder if, then, rather than defining a completely new shape, it is not easier to find out a systematic way to give a proper, automatically determinedinner separation
to a normalcircle
. Analogously one could give an automatically determined negativeinner sep
to aregular polygon
. I will think about it, but you helped already a lot!
– Axel Krypton
Mar 21 at 16:55
And I would also say that thepgf
inherit...[from=ellipse]
commands might be useful to shorten the code, but I have to still explore this world and I might be completely wrong.
– Axel Krypton
Mar 21 at 17:01
Thanks for the added information, very useful, indeed. I came up with a slightly differentCircle
and I shared this in a separate answer. :)
– Axel Krypton
Mar 22 at 9:02
add a comment |
Very enlightening. I wonder if, then, rather than defining a completely new shape, it is not easier to find out a systematic way to give a proper, automatically determinedinner separation
to a normalcircle
. Analogously one could give an automatically determined negativeinner sep
to aregular polygon
. I will think about it, but you helped already a lot!
– Axel Krypton
Mar 21 at 16:55
And I would also say that thepgf
inherit...[from=ellipse]
commands might be useful to shorten the code, but I have to still explore this world and I might be completely wrong.
– Axel Krypton
Mar 21 at 17:01
Thanks for the added information, very useful, indeed. I came up with a slightly differentCircle
and I shared this in a separate answer. :)
– Axel Krypton
Mar 22 at 9:02
Very enlightening. I wonder if, then, rather than defining a completely new shape, it is not easier to find out a systematic way to give a proper, automatically determined
inner separation
to a normal circle
. Analogously one could give an automatically determined negative inner sep
to a regular polygon
. I will think about it, but you helped already a lot!– Axel Krypton
Mar 21 at 16:55
Very enlightening. I wonder if, then, rather than defining a completely new shape, it is not easier to find out a systematic way to give a proper, automatically determined
inner separation
to a normal circle
. Analogously one could give an automatically determined negative inner sep
to a regular polygon
. I will think about it, but you helped already a lot!– Axel Krypton
Mar 21 at 16:55
And I would also say that the
pgf
inherit...[from=ellipse]
commands might be useful to shorten the code, but I have to still explore this world and I might be completely wrong.– Axel Krypton
Mar 21 at 17:01
And I would also say that the
pgf
inherit...[from=ellipse]
commands might be useful to shorten the code, but I have to still explore this world and I might be completely wrong.– Axel Krypton
Mar 21 at 17:01
Thanks for the added information, very useful, indeed. I came up with a slightly different
Circle
and I shared this in a separate answer. :)– Axel Krypton
Mar 22 at 9:02
Thanks for the added information, very useful, indeed. I came up with a slightly different
Circle
and I shared this in a separate answer. :)– Axel Krypton
Mar 22 at 9:02
add a comment |
Using through
library of Tikz.
documentclass[tikz, border=1mm]standalone
usetikzlibraryshapes.geometric,through
begindocument
begintikzpicture[every node/.style=draw, inner sep=0]
node[regular polygon,regular polygon sides=4] (a) XX;
node (b) [draw,blue, circle through=(a.north)] at (a.center) XX;
node[circle] (c) XX;
foreach a in north,south,east,west,north east,south east,north west,south west
fill[red] (a.a) circle(0.5pt);
fill[yellow] (b.a) circle(0.25pt);
fill[orange] (c.a) circle(0.25pt);
endtikzpicture
enddocument
Although strictly speaking you proposed a valid way to draw the blue circle, I was more interested in a general way to draw that shape for a node, without having to rely to another node/point (see edit question). The only way I see I could use your idea is to always have two nodes, one invisible and one that would be the node I wish. However, this is not what I am looking for.
– Axel Krypton
Mar 21 at 12:25
add a comment |
Using through
library of Tikz.
documentclass[tikz, border=1mm]standalone
usetikzlibraryshapes.geometric,through
begindocument
begintikzpicture[every node/.style=draw, inner sep=0]
node[regular polygon,regular polygon sides=4] (a) XX;
node (b) [draw,blue, circle through=(a.north)] at (a.center) XX;
node[circle] (c) XX;
foreach a in north,south,east,west,north east,south east,north west,south west
fill[red] (a.a) circle(0.5pt);
fill[yellow] (b.a) circle(0.25pt);
fill[orange] (c.a) circle(0.25pt);
endtikzpicture
enddocument
Although strictly speaking you proposed a valid way to draw the blue circle, I was more interested in a general way to draw that shape for a node, without having to rely to another node/point (see edit question). The only way I see I could use your idea is to always have two nodes, one invisible and one that would be the node I wish. However, this is not what I am looking for.
– Axel Krypton
Mar 21 at 12:25
add a comment |
Using through
library of Tikz.
documentclass[tikz, border=1mm]standalone
usetikzlibraryshapes.geometric,through
begindocument
begintikzpicture[every node/.style=draw, inner sep=0]
node[regular polygon,regular polygon sides=4] (a) XX;
node (b) [draw,blue, circle through=(a.north)] at (a.center) XX;
node[circle] (c) XX;
foreach a in north,south,east,west,north east,south east,north west,south west
fill[red] (a.a) circle(0.5pt);
fill[yellow] (b.a) circle(0.25pt);
fill[orange] (c.a) circle(0.25pt);
endtikzpicture
enddocument
Using through
library of Tikz.
documentclass[tikz, border=1mm]standalone
usetikzlibraryshapes.geometric,through
begindocument
begintikzpicture[every node/.style=draw, inner sep=0]
node[regular polygon,regular polygon sides=4] (a) XX;
node (b) [draw,blue, circle through=(a.north)] at (a.center) XX;
node[circle] (c) XX;
foreach a in north,south,east,west,north east,south east,north west,south west
fill[red] (a.a) circle(0.5pt);
fill[yellow] (b.a) circle(0.25pt);
fill[orange] (c.a) circle(0.25pt);
endtikzpicture
enddocument
answered Mar 21 at 11:40
ferahfezaferahfeza
7,35911933
7,35911933
Although strictly speaking you proposed a valid way to draw the blue circle, I was more interested in a general way to draw that shape for a node, without having to rely to another node/point (see edit question). The only way I see I could use your idea is to always have two nodes, one invisible and one that would be the node I wish. However, this is not what I am looking for.
– Axel Krypton
Mar 21 at 12:25
add a comment |
Although strictly speaking you proposed a valid way to draw the blue circle, I was more interested in a general way to draw that shape for a node, without having to rely to another node/point (see edit question). The only way I see I could use your idea is to always have two nodes, one invisible and one that would be the node I wish. However, this is not what I am looking for.
– Axel Krypton
Mar 21 at 12:25
Although strictly speaking you proposed a valid way to draw the blue circle, I was more interested in a general way to draw that shape for a node, without having to rely to another node/point (see edit question). The only way I see I could use your idea is to always have two nodes, one invisible and one that would be the node I wish. However, this is not what I am looking for.
– Axel Krypton
Mar 21 at 12:25
Although strictly speaking you proposed a valid way to draw the blue circle, I was more interested in a general way to draw that shape for a node, without having to rely to another node/point (see edit question). The only way I see I could use your idea is to always have two nodes, one invisible and one that would be the node I wish. However, this is not what I am looking for.
– Axel Krypton
Mar 21 at 12:25
add a comment |
Just to share a different way to achieve what Kpym did in his very nice answer declaring a new shape, I thought one could have simply a Circle
style which sets properly the minimum size of a circle shape (in this particular case it is always true that the content will never exceed the minimum size
since we are trying to enlarge the circle). It should work for any node content, no matter if its width is larger than its height or vice-versa. A couple of remarks:
- In this approach the node name and the node position must be declared before the options or inside them using the
name
andat
keys, respectively. - A
Circle
inner sep
has to be specified before theCircle
style, but it might easily be improved, if needed otherwise.
Here the code:
documentclass[tikz, border=1mm]standalone
usetikzlibraryshapes.geometric
tikzset%
Square/.style=regular polygon, regular polygon sides=4,
Circle/.style=%
circle,
/utils/exec=%
pgfmathsetmacropolygonIncircleDiameter
sqrt(2)*max(width("#1")+2*pgfshapeinnerxsep, height("#1") + depth("#1") + 2 * pgfshapeinnerysep)
,
minimum size=polygonIncircleDiameter,
node contents=#1
begindocument
begintikzpicture
node[inner sep=0, Square, draw=cyan] at (0,0) xx;
node[inner sep=0, Circle=xx, draw=blue];
node[Square, draw=cyan] at (1,0) i;
node[Circle=i, draw=blue, at=(1,0)];
endtikzpicture
enddocument
Very nice ! Two remarks : it would be nice to not pass the node content as parameter toCircle
but I think that this will be tricky, and probablypolygonIncircleDiameter
is better than to divide and then multiply by 2 thepolygonIncircleRadius
.
– Kpym
Mar 22 at 9:31
I implemented your suggestion, it definitely makes sense! :) About not passing the node content to the style, well, honestly I would not know how to then achieve the same result. Yes, it definitely looks tricky to me.
– Axel Krypton
Mar 22 at 9:41
add a comment |
Just to share a different way to achieve what Kpym did in his very nice answer declaring a new shape, I thought one could have simply a Circle
style which sets properly the minimum size of a circle shape (in this particular case it is always true that the content will never exceed the minimum size
since we are trying to enlarge the circle). It should work for any node content, no matter if its width is larger than its height or vice-versa. A couple of remarks:
- In this approach the node name and the node position must be declared before the options or inside them using the
name
andat
keys, respectively. - A
Circle
inner sep
has to be specified before theCircle
style, but it might easily be improved, if needed otherwise.
Here the code:
documentclass[tikz, border=1mm]standalone
usetikzlibraryshapes.geometric
tikzset%
Square/.style=regular polygon, regular polygon sides=4,
Circle/.style=%
circle,
/utils/exec=%
pgfmathsetmacropolygonIncircleDiameter
sqrt(2)*max(width("#1")+2*pgfshapeinnerxsep, height("#1") + depth("#1") + 2 * pgfshapeinnerysep)
,
minimum size=polygonIncircleDiameter,
node contents=#1
begindocument
begintikzpicture
node[inner sep=0, Square, draw=cyan] at (0,0) xx;
node[inner sep=0, Circle=xx, draw=blue];
node[Square, draw=cyan] at (1,0) i;
node[Circle=i, draw=blue, at=(1,0)];
endtikzpicture
enddocument
Very nice ! Two remarks : it would be nice to not pass the node content as parameter toCircle
but I think that this will be tricky, and probablypolygonIncircleDiameter
is better than to divide and then multiply by 2 thepolygonIncircleRadius
.
– Kpym
Mar 22 at 9:31
I implemented your suggestion, it definitely makes sense! :) About not passing the node content to the style, well, honestly I would not know how to then achieve the same result. Yes, it definitely looks tricky to me.
– Axel Krypton
Mar 22 at 9:41
add a comment |
Just to share a different way to achieve what Kpym did in his very nice answer declaring a new shape, I thought one could have simply a Circle
style which sets properly the minimum size of a circle shape (in this particular case it is always true that the content will never exceed the minimum size
since we are trying to enlarge the circle). It should work for any node content, no matter if its width is larger than its height or vice-versa. A couple of remarks:
- In this approach the node name and the node position must be declared before the options or inside them using the
name
andat
keys, respectively. - A
Circle
inner sep
has to be specified before theCircle
style, but it might easily be improved, if needed otherwise.
Here the code:
documentclass[tikz, border=1mm]standalone
usetikzlibraryshapes.geometric
tikzset%
Square/.style=regular polygon, regular polygon sides=4,
Circle/.style=%
circle,
/utils/exec=%
pgfmathsetmacropolygonIncircleDiameter
sqrt(2)*max(width("#1")+2*pgfshapeinnerxsep, height("#1") + depth("#1") + 2 * pgfshapeinnerysep)
,
minimum size=polygonIncircleDiameter,
node contents=#1
begindocument
begintikzpicture
node[inner sep=0, Square, draw=cyan] at (0,0) xx;
node[inner sep=0, Circle=xx, draw=blue];
node[Square, draw=cyan] at (1,0) i;
node[Circle=i, draw=blue, at=(1,0)];
endtikzpicture
enddocument
Just to share a different way to achieve what Kpym did in his very nice answer declaring a new shape, I thought one could have simply a Circle
style which sets properly the minimum size of a circle shape (in this particular case it is always true that the content will never exceed the minimum size
since we are trying to enlarge the circle). It should work for any node content, no matter if its width is larger than its height or vice-versa. A couple of remarks:
- In this approach the node name and the node position must be declared before the options or inside them using the
name
andat
keys, respectively. - A
Circle
inner sep
has to be specified before theCircle
style, but it might easily be improved, if needed otherwise.
Here the code:
documentclass[tikz, border=1mm]standalone
usetikzlibraryshapes.geometric
tikzset%
Square/.style=regular polygon, regular polygon sides=4,
Circle/.style=%
circle,
/utils/exec=%
pgfmathsetmacropolygonIncircleDiameter
sqrt(2)*max(width("#1")+2*pgfshapeinnerxsep, height("#1") + depth("#1") + 2 * pgfshapeinnerysep)
,
minimum size=polygonIncircleDiameter,
node contents=#1
begindocument
begintikzpicture
node[inner sep=0, Square, draw=cyan] at (0,0) xx;
node[inner sep=0, Circle=xx, draw=blue];
node[Square, draw=cyan] at (1,0) i;
node[Circle=i, draw=blue, at=(1,0)];
endtikzpicture
enddocument
edited Mar 22 at 9:39
answered Mar 22 at 9:01
Axel KryptonAxel Krypton
477211
477211
Very nice ! Two remarks : it would be nice to not pass the node content as parameter toCircle
but I think that this will be tricky, and probablypolygonIncircleDiameter
is better than to divide and then multiply by 2 thepolygonIncircleRadius
.
– Kpym
Mar 22 at 9:31
I implemented your suggestion, it definitely makes sense! :) About not passing the node content to the style, well, honestly I would not know how to then achieve the same result. Yes, it definitely looks tricky to me.
– Axel Krypton
Mar 22 at 9:41
add a comment |
Very nice ! Two remarks : it would be nice to not pass the node content as parameter toCircle
but I think that this will be tricky, and probablypolygonIncircleDiameter
is better than to divide and then multiply by 2 thepolygonIncircleRadius
.
– Kpym
Mar 22 at 9:31
I implemented your suggestion, it definitely makes sense! :) About not passing the node content to the style, well, honestly I would not know how to then achieve the same result. Yes, it definitely looks tricky to me.
– Axel Krypton
Mar 22 at 9:41
Very nice ! Two remarks : it would be nice to not pass the node content as parameter to
Circle
but I think that this will be tricky, and probably polygonIncircleDiameter
is better than to divide and then multiply by 2 the polygonIncircleRadius
.– Kpym
Mar 22 at 9:31
Very nice ! Two remarks : it would be nice to not pass the node content as parameter to
Circle
but I think that this will be tricky, and probably polygonIncircleDiameter
is better than to divide and then multiply by 2 the polygonIncircleRadius
.– Kpym
Mar 22 at 9:31
I implemented your suggestion, it definitely makes sense! :) About not passing the node content to the style, well, honestly I would not know how to then achieve the same result. Yes, it definitely looks tricky to me.
– Axel Krypton
Mar 22 at 9:41
I implemented your suggestion, it definitely makes sense! :) About not passing the node content to the style, well, honestly I would not know how to then achieve the same result. Yes, it definitely looks tricky to me.
– Axel Krypton
Mar 22 at 9:41
add a comment |
This wraps a polyogon around the circle.
documentclass[tikz,border=3.14mm]standalone
usetikzlibrarycalc
begindocument
begintikzpicture[every node/.style=draw, inner sep=0,
polygon with circle/.style args=#1 inscribed and #2 cornersinsert path=%
let p1=($(#1.0)-(#1.center)$),n1=abs(x1)/cos(180/#2)
in ($(#1.center)+(0:n1)$)
foreach X in 1,...,numexpr#2-1
-- ($(#1.center)+(360*X/#2:n1)$) -- cycle]
node[circle] (c) XX;
draw[blue,polygon with circle=c inscribed and 12 corners] ;
foreach a in north,south,east,west,north east,south east,north west,south west
fill[orange] (c.a) circle(0.25pt);
endtikzpicture
enddocument
add a comment |
This wraps a polyogon around the circle.
documentclass[tikz,border=3.14mm]standalone
usetikzlibrarycalc
begindocument
begintikzpicture[every node/.style=draw, inner sep=0,
polygon with circle/.style args=#1 inscribed and #2 cornersinsert path=%
let p1=($(#1.0)-(#1.center)$),n1=abs(x1)/cos(180/#2)
in ($(#1.center)+(0:n1)$)
foreach X in 1,...,numexpr#2-1
-- ($(#1.center)+(360*X/#2:n1)$) -- cycle]
node[circle] (c) XX;
draw[blue,polygon with circle=c inscribed and 12 corners] ;
foreach a in north,south,east,west,north east,south east,north west,south west
fill[orange] (c.a) circle(0.25pt);
endtikzpicture
enddocument
add a comment |
This wraps a polyogon around the circle.
documentclass[tikz,border=3.14mm]standalone
usetikzlibrarycalc
begindocument
begintikzpicture[every node/.style=draw, inner sep=0,
polygon with circle/.style args=#1 inscribed and #2 cornersinsert path=%
let p1=($(#1.0)-(#1.center)$),n1=abs(x1)/cos(180/#2)
in ($(#1.center)+(0:n1)$)
foreach X in 1,...,numexpr#2-1
-- ($(#1.center)+(360*X/#2:n1)$) -- cycle]
node[circle] (c) XX;
draw[blue,polygon with circle=c inscribed and 12 corners] ;
foreach a in north,south,east,west,north east,south east,north west,south west
fill[orange] (c.a) circle(0.25pt);
endtikzpicture
enddocument
This wraps a polyogon around the circle.
documentclass[tikz,border=3.14mm]standalone
usetikzlibrarycalc
begindocument
begintikzpicture[every node/.style=draw, inner sep=0,
polygon with circle/.style args=#1 inscribed and #2 cornersinsert path=%
let p1=($(#1.0)-(#1.center)$),n1=abs(x1)/cos(180/#2)
in ($(#1.center)+(0:n1)$)
foreach X in 1,...,numexpr#2-1
-- ($(#1.center)+(360*X/#2:n1)$) -- cycle]
node[circle] (c) XX;
draw[blue,polygon with circle=c inscribed and 12 corners] ;
foreach a in north,south,east,west,north east,south east,north west,south west
fill[orange] (c.a) circle(0.25pt);
endtikzpicture
enddocument
answered Mar 22 at 7:05
marmotmarmot
114k5145276
114k5145276
add a comment |
add a comment |
This solution uses calc
library to compute regular polygon's inner radius. This way it's possible to compute circunscribed circle's minimum width.
documentclass[tikz, border=1mm]standalone
usetikzlibraryshapes.geometric, calc
begindocument
begintikzpicture
node[inner sep=0, regular polygon, regular polygon sides=4, draw=cyan] (a) xx;
path let p1=($(a.center)-(a.side 1)$) in node[circle, inner sep=0, minimum width=2*veclen(x1,y1)-pgflinewidth, draw=blue] ;
node[inner sep=0, draw=cyan, regular polygon, regular polygon sides=7] (b) at (1,0) i;
path let p1=($(b.center)-(b.side 1)$) in node[circle, inner sep=0, minimum width=2*veclen(x1,y1)-pgflinewidth, draw=blue] at (b) ;
endtikzpicture
enddocument
add a comment |
This solution uses calc
library to compute regular polygon's inner radius. This way it's possible to compute circunscribed circle's minimum width.
documentclass[tikz, border=1mm]standalone
usetikzlibraryshapes.geometric, calc
begindocument
begintikzpicture
node[inner sep=0, regular polygon, regular polygon sides=4, draw=cyan] (a) xx;
path let p1=($(a.center)-(a.side 1)$) in node[circle, inner sep=0, minimum width=2*veclen(x1,y1)-pgflinewidth, draw=blue] ;
node[inner sep=0, draw=cyan, regular polygon, regular polygon sides=7] (b) at (1,0) i;
path let p1=($(b.center)-(b.side 1)$) in node[circle, inner sep=0, minimum width=2*veclen(x1,y1)-pgflinewidth, draw=blue] at (b) ;
endtikzpicture
enddocument
add a comment |
This solution uses calc
library to compute regular polygon's inner radius. This way it's possible to compute circunscribed circle's minimum width.
documentclass[tikz, border=1mm]standalone
usetikzlibraryshapes.geometric, calc
begindocument
begintikzpicture
node[inner sep=0, regular polygon, regular polygon sides=4, draw=cyan] (a) xx;
path let p1=($(a.center)-(a.side 1)$) in node[circle, inner sep=0, minimum width=2*veclen(x1,y1)-pgflinewidth, draw=blue] ;
node[inner sep=0, draw=cyan, regular polygon, regular polygon sides=7] (b) at (1,0) i;
path let p1=($(b.center)-(b.side 1)$) in node[circle, inner sep=0, minimum width=2*veclen(x1,y1)-pgflinewidth, draw=blue] at (b) ;
endtikzpicture
enddocument
This solution uses calc
library to compute regular polygon's inner radius. This way it's possible to compute circunscribed circle's minimum width.
documentclass[tikz, border=1mm]standalone
usetikzlibraryshapes.geometric, calc
begindocument
begintikzpicture
node[inner sep=0, regular polygon, regular polygon sides=4, draw=cyan] (a) xx;
path let p1=($(a.center)-(a.side 1)$) in node[circle, inner sep=0, minimum width=2*veclen(x1,y1)-pgflinewidth, draw=blue] ;
node[inner sep=0, draw=cyan, regular polygon, regular polygon sides=7] (b) at (1,0) i;
path let p1=($(b.center)-(b.side 1)$) in node[circle, inner sep=0, minimum width=2*veclen(x1,y1)-pgflinewidth, draw=blue] at (b) ;
endtikzpicture
enddocument
answered Mar 22 at 12:12
IgnasiIgnasi
95.7k4175320
95.7k4175320
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.
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%2f480661%2fregular-polygon-vs-circle-shapes-in-tikz%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
You can see in the manual that for empty nodes the ratio is
sqrt(2)
(but I don't know why). In the manual a regular polygon with inner space equal to0.3535cm
(which issqrt(2)/4
) is tangent to circle with radius1/2 cm
.– Kpym
Mar 21 at 12:50
I had noticed that strange
inner sep
in the example. But I had also noticed that it was about an empty node. If I have an arbitrary node content, I would then need to adjust that0.3535cm
magic number (and I should think about how). Are you suggesting something like that?– Axel Krypton
Mar 21 at 13:07
1
This
sqrt(2)
factor does make sense if you assume the the content is approximately quadratic. And I do not understand the question. That is, I thought I did before I saw the answers. Could you perhaps indicate to which extent the answers address the question. I am really confused.– marmot
Mar 21 at 14:19
1
@marmot As I understand the answer is "How to draw a circular shape that has the same inner circle as all other regular polygons".
– Kpym
Mar 21 at 14:32
1
@marmot I think that I have answered this par of the question : the the origin of the white space around the node content is that in the definition of the
regular polygon
shape the inner radius is calculated differently from thecircle
shape (and the ratio between both depends on the shape, i.e. the aspect ratio).– Kpym
Mar 21 at 15:52