TikZ: Coordinate on shape vertices











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



documentclass{standalone}

usepackage{tikz}
usetikzlibrary{calc}

begin{document}

begin{tikzpicture}

% 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];

end{tikzpicture}

end{document}









share|improve this question


























    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



    documentclass{standalone}

    usepackage{tikz}
    usetikzlibrary{calc}

    begin{document}

    begin{tikzpicture}

    % 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];

    end{tikzpicture}

    end{document}









    share|improve this question
























      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



      documentclass{standalone}

      usepackage{tikz}
      usetikzlibrary{calc}

      begin{document}

      begin{tikzpicture}

      % 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];

      end{tikzpicture}

      end{document}









      share|improve this question













      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



      documentclass{standalone}

      usepackage{tikz}
      usetikzlibrary{calc}

      begin{document}

      begin{tikzpicture}

      % 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];

      end{tikzpicture}

      end{document}






      tikz-pgf coordinates tikz-shape






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 26 at 14:47









      krtek

      873820




      873820






















          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}
          begin{document}
          begin{tikzpicture}[my rectangle/.style={to path={
          -| coordinate[pos=0.5] (#1-2) (tikztotarget) coordinate (#1-3)
          -| 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];}
          end{tikzpicture}
          end{document}


          the style my rectangle=<coordinate base name> will give the four corners the names coordinate base name-1, ... , coordinate base name-4.



          enter image description here



          And there are, of course, predefined shapes that have the corner coordinates stored in anchors.



          documentclass[tikz,border=3.14mm]{standalone}
          begin{document}
          usetikzlibrary{shapes.geometric}
          begin{tikzpicture}

          % 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];}

          end{tikzpicture}

          end{document}


          enter image description here






          share|improve this answer






























            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} 
            usetikzlibrary{fit}

            begin{document}
            begin{tikzpicture}

            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);
            end{tikzpicture}
            end{document}


            enter image description here






            share|improve this answer





















              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',
              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
              });


              }
              });














              draft saved

              draft discarded


















              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

























              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}
              begin{document}
              begin{tikzpicture}[my rectangle/.style={to path={
              -| coordinate[pos=0.5] (#1-2) (tikztotarget) coordinate (#1-3)
              -| 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];}
              end{tikzpicture}
              end{document}


              the style my rectangle=<coordinate base name> will give the four corners the names coordinate base name-1, ... , coordinate base name-4.



              enter image description here



              And there are, of course, predefined shapes that have the corner coordinates stored in anchors.



              documentclass[tikz,border=3.14mm]{standalone}
              begin{document}
              usetikzlibrary{shapes.geometric}
              begin{tikzpicture}

              % 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];}

              end{tikzpicture}

              end{document}


              enter image description here






              share|improve this answer



























                up vote
                3
                down vote



                accepted










                You could define your own rectangle path. In the MWE



                documentclass[tikz,border=3.14mm]{standalone}
                begin{document}
                begin{tikzpicture}[my rectangle/.style={to path={
                -| coordinate[pos=0.5] (#1-2) (tikztotarget) coordinate (#1-3)
                -| 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];}
                end{tikzpicture}
                end{document}


                the style my rectangle=<coordinate base name> will give the four corners the names coordinate base name-1, ... , coordinate base name-4.



                enter image description here



                And there are, of course, predefined shapes that have the corner coordinates stored in anchors.



                documentclass[tikz,border=3.14mm]{standalone}
                begin{document}
                usetikzlibrary{shapes.geometric}
                begin{tikzpicture}

                % 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];}

                end{tikzpicture}

                end{document}


                enter image description here






                share|improve this answer

























                  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}
                  begin{document}
                  begin{tikzpicture}[my rectangle/.style={to path={
                  -| coordinate[pos=0.5] (#1-2) (tikztotarget) coordinate (#1-3)
                  -| 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];}
                  end{tikzpicture}
                  end{document}


                  the style my rectangle=<coordinate base name> will give the four corners the names coordinate base name-1, ... , coordinate base name-4.



                  enter image description here



                  And there are, of course, predefined shapes that have the corner coordinates stored in anchors.



                  documentclass[tikz,border=3.14mm]{standalone}
                  begin{document}
                  usetikzlibrary{shapes.geometric}
                  begin{tikzpicture}

                  % 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];}

                  end{tikzpicture}

                  end{document}


                  enter image description here






                  share|improve this answer














                  You could define your own rectangle path. In the MWE



                  documentclass[tikz,border=3.14mm]{standalone}
                  begin{document}
                  begin{tikzpicture}[my rectangle/.style={to path={
                  -| coordinate[pos=0.5] (#1-2) (tikztotarget) coordinate (#1-3)
                  -| 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];}
                  end{tikzpicture}
                  end{document}


                  the style my rectangle=<coordinate base name> will give the four corners the names coordinate base name-1, ... , coordinate base name-4.



                  enter image description here



                  And there are, of course, predefined shapes that have the corner coordinates stored in anchors.



                  documentclass[tikz,border=3.14mm]{standalone}
                  begin{document}
                  usetikzlibrary{shapes.geometric}
                  begin{tikzpicture}

                  % 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];}

                  end{tikzpicture}

                  end{document}


                  enter image description here







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 26 at 16:13

























                  answered Nov 26 at 15:41









                  marmot

                  80.4k491172




                  80.4k491172






















                      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} 
                      usetikzlibrary{fit}

                      begin{document}
                      begin{tikzpicture}

                      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);
                      end{tikzpicture}
                      end{document}


                      enter image description here






                      share|improve this answer

























                        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} 
                        usetikzlibrary{fit}

                        begin{document}
                        begin{tikzpicture}

                        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);
                        end{tikzpicture}
                        end{document}


                        enter image description here






                        share|improve this answer























                          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} 
                          usetikzlibrary{fit}

                          begin{document}
                          begin{tikzpicture}

                          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);
                          end{tikzpicture}
                          end{document}


                          enter image description here






                          share|improve this answer












                          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} 
                          usetikzlibrary{fit}

                          begin{document}
                          begin{tikzpicture}

                          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);
                          end{tikzpicture}
                          end{document}


                          enter image description here







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 26 at 16:39









                          Ignasi

                          90.6k4164303




                          90.6k4164303






























                              draft saved

                              draft discarded




















































                              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.




                              draft saved


                              draft discarded














                              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





















































                              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







                              Popular posts from this blog

                              flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                              Mangá

                               ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕