TikZ: Coordinate on shape vertices

Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
I know that I can draw a rectangle with tikz using draw (0.0,0.0) rectangle (1.0,1.0);. Is there a possibility to determine all 4 edge coordinates directly from the shape?
I do can save the lower left coordinate and the upper right by draw (0.0,0.0) coordinate (lb) rectangle (1.0,1.0) coordinate (ru);. But is there a way to get the upper left and bottom right corner directly from the shape?
I know I can calculate them. But are they directly accessible from the shape?
MWE
documentclassstandalone
usepackagetikz
usetikzlibrarycalc
begindocument
begintikzpicture
% the rectangle
draw (0.0,0.0) coordinate (lb) rectangle (1.0,1.0) coordinate (ru);
% coordinates
draw (lb) circle [radius=2pt];
draw (ru) circle [radius=2pt];
% calculated coordinates
draw[dashed] (lb |- ru) coordinate (lu) circle [radius=2pt];
draw[dashed] (lb -| ru) coordinate (rb) circle [radius=2pt];
endtikzpicture
enddocument
tikz-pgf coordinates tikz-shape
add a comment |
up vote
4
down vote
favorite
I know that I can draw a rectangle with tikz using draw (0.0,0.0) rectangle (1.0,1.0);. Is there a possibility to determine all 4 edge coordinates directly from the shape?
I do can save the lower left coordinate and the upper right by draw (0.0,0.0) coordinate (lb) rectangle (1.0,1.0) coordinate (ru);. But is there a way to get the upper left and bottom right corner directly from the shape?
I know I can calculate them. But are they directly accessible from the shape?
MWE
documentclassstandalone
usepackagetikz
usetikzlibrarycalc
begindocument
begintikzpicture
% the rectangle
draw (0.0,0.0) coordinate (lb) rectangle (1.0,1.0) coordinate (ru);
% coordinates
draw (lb) circle [radius=2pt];
draw (ru) circle [radius=2pt];
% calculated coordinates
draw[dashed] (lb |- ru) coordinate (lu) circle [radius=2pt];
draw[dashed] (lb -| ru) coordinate (rb) circle [radius=2pt];
endtikzpicture
enddocument
tikz-pgf coordinates tikz-shape
add a comment |
up vote
4
down vote
favorite
up vote
4
down vote
favorite
I know that I can draw a rectangle with tikz using draw (0.0,0.0) rectangle (1.0,1.0);. Is there a possibility to determine all 4 edge coordinates directly from the shape?
I do can save the lower left coordinate and the upper right by draw (0.0,0.0) coordinate (lb) rectangle (1.0,1.0) coordinate (ru);. But is there a way to get the upper left and bottom right corner directly from the shape?
I know I can calculate them. But are they directly accessible from the shape?
MWE
documentclassstandalone
usepackagetikz
usetikzlibrarycalc
begindocument
begintikzpicture
% the rectangle
draw (0.0,0.0) coordinate (lb) rectangle (1.0,1.0) coordinate (ru);
% coordinates
draw (lb) circle [radius=2pt];
draw (ru) circle [radius=2pt];
% calculated coordinates
draw[dashed] (lb |- ru) coordinate (lu) circle [radius=2pt];
draw[dashed] (lb -| ru) coordinate (rb) circle [radius=2pt];
endtikzpicture
enddocument
tikz-pgf coordinates tikz-shape
I know that I can draw a rectangle with tikz using draw (0.0,0.0) rectangle (1.0,1.0);. Is there a possibility to determine all 4 edge coordinates directly from the shape?
I do can save the lower left coordinate and the upper right by draw (0.0,0.0) coordinate (lb) rectangle (1.0,1.0) coordinate (ru);. But is there a way to get the upper left and bottom right corner directly from the shape?
I know I can calculate them. But are they directly accessible from the shape?
MWE
documentclassstandalone
usepackagetikz
usetikzlibrarycalc
begindocument
begintikzpicture
% the rectangle
draw (0.0,0.0) coordinate (lb) rectangle (1.0,1.0) coordinate (ru);
% coordinates
draw (lb) circle [radius=2pt];
draw (ru) circle [radius=2pt];
% calculated coordinates
draw[dashed] (lb |- ru) coordinate (lu) circle [radius=2pt];
draw[dashed] (lb -| ru) coordinate (rb) circle [radius=2pt];
endtikzpicture
enddocument
tikz-pgf coordinates tikz-shape
tikz-pgf coordinates tikz-shape
asked Nov 26 at 14:47
krtek
873820
873820
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
3
down vote
accepted
You could define your own rectangle path. In the MWE
documentclass[tikz,border=3.14mm]standalone
begindocument
begintikzpicture[my rectangle/.style=to path= coordinate (#1-4) (tikztostart) coordinate (#1-1) ]
draw (0,0) edge[my rectangle=krtek] (1,1);
foreach X in 1,...,4
draw (krtek-X) circle [radius=2pt];
endtikzpicture
enddocument
the style my rectangle=<coordinate base name> will give the four corners the names coordinate base name-1, ... , coordinate base name-4.

And there are, of course, predefined shapes that have the corner coordinates stored in anchors.
documentclass[tikz,border=3.14mm]standalone
begindocument
usetikzlibraryshapes.geometric
begintikzpicture
% the rectangle
path (0,0) node[draw,anchor=south west,minimum size=1cm] (R) ;
foreach X in 45,135,225,315
draw (R.X) circle [radius=2pt];
path (2,0) node[draw,anchor=south west,minimum size=sqrt(2)*1cm,regular polygon,regular
polygon sides=4] (poly) ;
foreach X in 1,...,4
draw (poly.corner X) circle [radius=2pt];
endtikzpicture
enddocument

add a comment |
up vote
2
down vote
If you don't want to explicitely declare coordinates for the corners, you can automatically convert your rectangle into a node with fit library. This way, the resultant node gives you all rectangular anchors without havint to name them.
Following example shows how to insert rectangular coordinates into fit parameter. The result node is equivalent to previously drawn rectangle (you don't need to draw the previous rectangle, it's just for demonstration purposes).
documentclass[tikz,border=2mm]standalone
usetikzlibraryfit
begindocument
begintikzpicture
draw (0,0) rectangle (2,1);
node[fit=(0,0) (2,1), inner sep=0pt, draw=red, opacity=.5] (a) ;
foreach i in north east, north west, south east, south west
draw (a.i) circle(2pt);
endtikzpicture
enddocument

add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
You could define your own rectangle path. In the MWE
documentclass[tikz,border=3.14mm]standalone
begindocument
begintikzpicture[my rectangle/.style=to path= coordinate (#1-4) (tikztostart) coordinate (#1-1) ]
draw (0,0) edge[my rectangle=krtek] (1,1);
foreach X in 1,...,4
draw (krtek-X) circle [radius=2pt];
endtikzpicture
enddocument
the style my rectangle=<coordinate base name> will give the four corners the names coordinate base name-1, ... , coordinate base name-4.

And there are, of course, predefined shapes that have the corner coordinates stored in anchors.
documentclass[tikz,border=3.14mm]standalone
begindocument
usetikzlibraryshapes.geometric
begintikzpicture
% the rectangle
path (0,0) node[draw,anchor=south west,minimum size=1cm] (R) ;
foreach X in 45,135,225,315
draw (R.X) circle [radius=2pt];
path (2,0) node[draw,anchor=south west,minimum size=sqrt(2)*1cm,regular polygon,regular
polygon sides=4] (poly) ;
foreach X in 1,...,4
draw (poly.corner X) circle [radius=2pt];
endtikzpicture
enddocument

add a comment |
up vote
3
down vote
accepted
You could define your own rectangle path. In the MWE
documentclass[tikz,border=3.14mm]standalone
begindocument
begintikzpicture[my rectangle/.style=to path= coordinate (#1-4) (tikztostart) coordinate (#1-1) ]
draw (0,0) edge[my rectangle=krtek] (1,1);
foreach X in 1,...,4
draw (krtek-X) circle [radius=2pt];
endtikzpicture
enddocument
the style my rectangle=<coordinate base name> will give the four corners the names coordinate base name-1, ... , coordinate base name-4.

And there are, of course, predefined shapes that have the corner coordinates stored in anchors.
documentclass[tikz,border=3.14mm]standalone
begindocument
usetikzlibraryshapes.geometric
begintikzpicture
% the rectangle
path (0,0) node[draw,anchor=south west,minimum size=1cm] (R) ;
foreach X in 45,135,225,315
draw (R.X) circle [radius=2pt];
path (2,0) node[draw,anchor=south west,minimum size=sqrt(2)*1cm,regular polygon,regular
polygon sides=4] (poly) ;
foreach X in 1,...,4
draw (poly.corner X) circle [radius=2pt];
endtikzpicture
enddocument

add a comment |
up vote
3
down vote
accepted
up vote
3
down vote
accepted
You could define your own rectangle path. In the MWE
documentclass[tikz,border=3.14mm]standalone
begindocument
begintikzpicture[my rectangle/.style=to path= coordinate (#1-4) (tikztostart) coordinate (#1-1) ]
draw (0,0) edge[my rectangle=krtek] (1,1);
foreach X in 1,...,4
draw (krtek-X) circle [radius=2pt];
endtikzpicture
enddocument
the style my rectangle=<coordinate base name> will give the four corners the names coordinate base name-1, ... , coordinate base name-4.

And there are, of course, predefined shapes that have the corner coordinates stored in anchors.
documentclass[tikz,border=3.14mm]standalone
begindocument
usetikzlibraryshapes.geometric
begintikzpicture
% the rectangle
path (0,0) node[draw,anchor=south west,minimum size=1cm] (R) ;
foreach X in 45,135,225,315
draw (R.X) circle [radius=2pt];
path (2,0) node[draw,anchor=south west,minimum size=sqrt(2)*1cm,regular polygon,regular
polygon sides=4] (poly) ;
foreach X in 1,...,4
draw (poly.corner X) circle [radius=2pt];
endtikzpicture
enddocument

You could define your own rectangle path. In the MWE
documentclass[tikz,border=3.14mm]standalone
begindocument
begintikzpicture[my rectangle/.style=to path= coordinate (#1-4) (tikztostart) coordinate (#1-1) ]
draw (0,0) edge[my rectangle=krtek] (1,1);
foreach X in 1,...,4
draw (krtek-X) circle [radius=2pt];
endtikzpicture
enddocument
the style my rectangle=<coordinate base name> will give the four corners the names coordinate base name-1, ... , coordinate base name-4.

And there are, of course, predefined shapes that have the corner coordinates stored in anchors.
documentclass[tikz,border=3.14mm]standalone
begindocument
usetikzlibraryshapes.geometric
begintikzpicture
% the rectangle
path (0,0) node[draw,anchor=south west,minimum size=1cm] (R) ;
foreach X in 45,135,225,315
draw (R.X) circle [radius=2pt];
path (2,0) node[draw,anchor=south west,minimum size=sqrt(2)*1cm,regular polygon,regular
polygon sides=4] (poly) ;
foreach X in 1,...,4
draw (poly.corner X) circle [radius=2pt];
endtikzpicture
enddocument

edited Nov 26 at 16:13
answered Nov 26 at 15:41
marmot
80.6k491172
80.6k491172
add a comment |
add a comment |
up vote
2
down vote
If you don't want to explicitely declare coordinates for the corners, you can automatically convert your rectangle into a node with fit library. This way, the resultant node gives you all rectangular anchors without havint to name them.
Following example shows how to insert rectangular coordinates into fit parameter. The result node is equivalent to previously drawn rectangle (you don't need to draw the previous rectangle, it's just for demonstration purposes).
documentclass[tikz,border=2mm]standalone
usetikzlibraryfit
begindocument
begintikzpicture
draw (0,0) rectangle (2,1);
node[fit=(0,0) (2,1), inner sep=0pt, draw=red, opacity=.5] (a) ;
foreach i in north east, north west, south east, south west
draw (a.i) circle(2pt);
endtikzpicture
enddocument

add a comment |
up vote
2
down vote
If you don't want to explicitely declare coordinates for the corners, you can automatically convert your rectangle into a node with fit library. This way, the resultant node gives you all rectangular anchors without havint to name them.
Following example shows how to insert rectangular coordinates into fit parameter. The result node is equivalent to previously drawn rectangle (you don't need to draw the previous rectangle, it's just for demonstration purposes).
documentclass[tikz,border=2mm]standalone
usetikzlibraryfit
begindocument
begintikzpicture
draw (0,0) rectangle (2,1);
node[fit=(0,0) (2,1), inner sep=0pt, draw=red, opacity=.5] (a) ;
foreach i in north east, north west, south east, south west
draw (a.i) circle(2pt);
endtikzpicture
enddocument

add a comment |
up vote
2
down vote
up vote
2
down vote
If you don't want to explicitely declare coordinates for the corners, you can automatically convert your rectangle into a node with fit library. This way, the resultant node gives you all rectangular anchors without havint to name them.
Following example shows how to insert rectangular coordinates into fit parameter. The result node is equivalent to previously drawn rectangle (you don't need to draw the previous rectangle, it's just for demonstration purposes).
documentclass[tikz,border=2mm]standalone
usetikzlibraryfit
begindocument
begintikzpicture
draw (0,0) rectangle (2,1);
node[fit=(0,0) (2,1), inner sep=0pt, draw=red, opacity=.5] (a) ;
foreach i in north east, north west, south east, south west
draw (a.i) circle(2pt);
endtikzpicture
enddocument

If you don't want to explicitely declare coordinates for the corners, you can automatically convert your rectangle into a node with fit library. This way, the resultant node gives you all rectangular anchors without havint to name them.
Following example shows how to insert rectangular coordinates into fit parameter. The result node is equivalent to previously drawn rectangle (you don't need to draw the previous rectangle, it's just for demonstration purposes).
documentclass[tikz,border=2mm]standalone
usetikzlibraryfit
begindocument
begintikzpicture
draw (0,0) rectangle (2,1);
node[fit=(0,0) (2,1), inner sep=0pt, draw=red, opacity=.5] (a) ;
foreach i in north east, north west, south east, south west
draw (a.i) circle(2pt);
endtikzpicture
enddocument

answered Nov 26 at 16:39
Ignasi
90.7k4164303
90.7k4164303
add a comment |
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f461830%2ftikz-coordinate-on-shape-vertices%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