Tikz: Method to color regions

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












(I would think that this question has already been asked in many other forms. I just do not how to search for it.)



MWE:



begindocument
begintikzpicture
draw (0, 0) -- (0, 8) -- (8, 8) -- (8, 0) --cycle;
draw (0, 8) -- (8, 4);
draw (0, 0) -- (8, 8);
endtikzpicture
enddocument


enter image description here



Apart from calculating the intersection point and manually drawing each shape, etc., what other options do I have to color any one of the four regions?










share|improve this question

























    up vote
    2
    down vote

    favorite












    (I would think that this question has already been asked in many other forms. I just do not how to search for it.)



    MWE:



    begindocument
    begintikzpicture
    draw (0, 0) -- (0, 8) -- (8, 8) -- (8, 0) --cycle;
    draw (0, 8) -- (8, 4);
    draw (0, 0) -- (8, 8);
    endtikzpicture
    enddocument


    enter image description here



    Apart from calculating the intersection point and manually drawing each shape, etc., what other options do I have to color any one of the four regions?










    share|improve this question























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      (I would think that this question has already been asked in many other forms. I just do not how to search for it.)



      MWE:



      begindocument
      begintikzpicture
      draw (0, 0) -- (0, 8) -- (8, 8) -- (8, 0) --cycle;
      draw (0, 8) -- (8, 4);
      draw (0, 0) -- (8, 8);
      endtikzpicture
      enddocument


      enter image description here



      Apart from calculating the intersection point and manually drawing each shape, etc., what other options do I have to color any one of the four regions?










      share|improve this question













      (I would think that this question has already been asked in many other forms. I just do not how to search for it.)



      MWE:



      begindocument
      begintikzpicture
      draw (0, 0) -- (0, 8) -- (8, 8) -- (8, 0) --cycle;
      draw (0, 8) -- (8, 4);
      draw (0, 0) -- (8, 8);
      endtikzpicture
      enddocument


      enter image description here



      Apart from calculating the intersection point and manually drawing each shape, etc., what other options do I have to color any one of the four regions?







      tikz-pgf






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 33 mins ago









      blackened

      1,215710




      1,215710




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          3
          down vote













          A perhaps less know possibility is to employ the pgfplots library fillbetween. To show that I do not overwrite different parts, I fill each of them separately in an animation.



          documentclass[tikz,border=3.14mm]standalone
          usepackagepgfplots
          pgfplotssetcompat=1.16
          usepgfplotslibraryfillbetween
          begindocument
          foreach X in 0,...,3
          begintikzpicture
          draw[name path=box] (0, 0) -- (0, 8) -- (8, 8) -- (8, 0) --cycle;
          draw[name path=d1] (0, 8) -- (8, 4);
          draw[name path=d2] (0, 0) -- (8, 8);
          ifcaseX
          fill [blue,intersection segments=of=d1 and d2,
          sequence=A0 -- B0[reverse]];
          or
          fill [blue,intersection segments=of=d1 and d2,
          sequence=A0 -- B1];
          or
          fill [blue,intersection segments=of=d1 and d2,
          sequence=A1[reverse] -- B1];
          or
          path [name path=aux,intersection segments=of=d1 and d2,
          sequence=A1[reverse] -- B0[reverse]];
          fill [blue,intersection segments=of=aux and box,
          sequence=A1 -- B2[reverse]];
          fi
          endtikzpicture
          enddocument


          enter image description here





          share



























            up vote
            1
            down vote













            One possibility is to calculate the coordinates of the intersection point of the two segments drawn in the square with TikZ; then to color the desired part.
            For this purpose, there is an operation that is no longer documented in manual 3.0.1a but is fully functional.
            Its documentation can be found in the manual 1.18 which is still available (until when?) here TikZ manual 1.18 (p 87, section 10.2.4 Intersection Coordinate Systems).



            documentclass[border=5pt]standalone
            usepackagetikz

            begindocument
            begintikzpicture
            draw (0, 0) coordinate(A)node[below left]A-- (0, 8)coordinate(B)node[above left]B -- (8, 8)coordinate(C)node[above right]C -- (8, 0)coordinate(D)node[below right]D --cycle;
            draw (B) -- (8, 4)coordinate(E)node[right]E;
            draw (A) -- (C);
            coordinate (I) at (intersection of 0,8--E and A--C);
            fill[green](A)--(B)--(I)--cycle;
            fill[blue](B)--(C)--(I)--cycle;
            fill[red](C)--(E)--(I)--cycle;
            fill[violet](A)--(D)--(E)--(I)--cycle;
            endtikzpicture
            enddocument


            fill-region



            Translated with www.DeepL.com/Translator






            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: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              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%2f455112%2ftikz-method-to-color-regions%23new-answer', 'question_page');

              );

              Post as a guest






























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              3
              down vote













              A perhaps less know possibility is to employ the pgfplots library fillbetween. To show that I do not overwrite different parts, I fill each of them separately in an animation.



              documentclass[tikz,border=3.14mm]standalone
              usepackagepgfplots
              pgfplotssetcompat=1.16
              usepgfplotslibraryfillbetween
              begindocument
              foreach X in 0,...,3
              begintikzpicture
              draw[name path=box] (0, 0) -- (0, 8) -- (8, 8) -- (8, 0) --cycle;
              draw[name path=d1] (0, 8) -- (8, 4);
              draw[name path=d2] (0, 0) -- (8, 8);
              ifcaseX
              fill [blue,intersection segments=of=d1 and d2,
              sequence=A0 -- B0[reverse]];
              or
              fill [blue,intersection segments=of=d1 and d2,
              sequence=A0 -- B1];
              or
              fill [blue,intersection segments=of=d1 and d2,
              sequence=A1[reverse] -- B1];
              or
              path [name path=aux,intersection segments=of=d1 and d2,
              sequence=A1[reverse] -- B0[reverse]];
              fill [blue,intersection segments=of=aux and box,
              sequence=A1 -- B2[reverse]];
              fi
              endtikzpicture
              enddocument


              enter image description here





              share
























                up vote
                3
                down vote













                A perhaps less know possibility is to employ the pgfplots library fillbetween. To show that I do not overwrite different parts, I fill each of them separately in an animation.



                documentclass[tikz,border=3.14mm]standalone
                usepackagepgfplots
                pgfplotssetcompat=1.16
                usepgfplotslibraryfillbetween
                begindocument
                foreach X in 0,...,3
                begintikzpicture
                draw[name path=box] (0, 0) -- (0, 8) -- (8, 8) -- (8, 0) --cycle;
                draw[name path=d1] (0, 8) -- (8, 4);
                draw[name path=d2] (0, 0) -- (8, 8);
                ifcaseX
                fill [blue,intersection segments=of=d1 and d2,
                sequence=A0 -- B0[reverse]];
                or
                fill [blue,intersection segments=of=d1 and d2,
                sequence=A0 -- B1];
                or
                fill [blue,intersection segments=of=d1 and d2,
                sequence=A1[reverse] -- B1];
                or
                path [name path=aux,intersection segments=of=d1 and d2,
                sequence=A1[reverse] -- B0[reverse]];
                fill [blue,intersection segments=of=aux and box,
                sequence=A1 -- B2[reverse]];
                fi
                endtikzpicture
                enddocument


                enter image description here





                share






















                  up vote
                  3
                  down vote










                  up vote
                  3
                  down vote









                  A perhaps less know possibility is to employ the pgfplots library fillbetween. To show that I do not overwrite different parts, I fill each of them separately in an animation.



                  documentclass[tikz,border=3.14mm]standalone
                  usepackagepgfplots
                  pgfplotssetcompat=1.16
                  usepgfplotslibraryfillbetween
                  begindocument
                  foreach X in 0,...,3
                  begintikzpicture
                  draw[name path=box] (0, 0) -- (0, 8) -- (8, 8) -- (8, 0) --cycle;
                  draw[name path=d1] (0, 8) -- (8, 4);
                  draw[name path=d2] (0, 0) -- (8, 8);
                  ifcaseX
                  fill [blue,intersection segments=of=d1 and d2,
                  sequence=A0 -- B0[reverse]];
                  or
                  fill [blue,intersection segments=of=d1 and d2,
                  sequence=A0 -- B1];
                  or
                  fill [blue,intersection segments=of=d1 and d2,
                  sequence=A1[reverse] -- B1];
                  or
                  path [name path=aux,intersection segments=of=d1 and d2,
                  sequence=A1[reverse] -- B0[reverse]];
                  fill [blue,intersection segments=of=aux and box,
                  sequence=A1 -- B2[reverse]];
                  fi
                  endtikzpicture
                  enddocument


                  enter image description here





                  share












                  A perhaps less know possibility is to employ the pgfplots library fillbetween. To show that I do not overwrite different parts, I fill each of them separately in an animation.



                  documentclass[tikz,border=3.14mm]standalone
                  usepackagepgfplots
                  pgfplotssetcompat=1.16
                  usepgfplotslibraryfillbetween
                  begindocument
                  foreach X in 0,...,3
                  begintikzpicture
                  draw[name path=box] (0, 0) -- (0, 8) -- (8, 8) -- (8, 0) --cycle;
                  draw[name path=d1] (0, 8) -- (8, 4);
                  draw[name path=d2] (0, 0) -- (8, 8);
                  ifcaseX
                  fill [blue,intersection segments=of=d1 and d2,
                  sequence=A0 -- B0[reverse]];
                  or
                  fill [blue,intersection segments=of=d1 and d2,
                  sequence=A0 -- B1];
                  or
                  fill [blue,intersection segments=of=d1 and d2,
                  sequence=A1[reverse] -- B1];
                  or
                  path [name path=aux,intersection segments=of=d1 and d2,
                  sequence=A1[reverse] -- B0[reverse]];
                  fill [blue,intersection segments=of=aux and box,
                  sequence=A1 -- B2[reverse]];
                  fi
                  endtikzpicture
                  enddocument


                  enter image description here






                  share











                  share


                  share










                  answered 7 mins ago









                  marmot

                  65.2k471139




                  65.2k471139




















                      up vote
                      1
                      down vote













                      One possibility is to calculate the coordinates of the intersection point of the two segments drawn in the square with TikZ; then to color the desired part.
                      For this purpose, there is an operation that is no longer documented in manual 3.0.1a but is fully functional.
                      Its documentation can be found in the manual 1.18 which is still available (until when?) here TikZ manual 1.18 (p 87, section 10.2.4 Intersection Coordinate Systems).



                      documentclass[border=5pt]standalone
                      usepackagetikz

                      begindocument
                      begintikzpicture
                      draw (0, 0) coordinate(A)node[below left]A-- (0, 8)coordinate(B)node[above left]B -- (8, 8)coordinate(C)node[above right]C -- (8, 0)coordinate(D)node[below right]D --cycle;
                      draw (B) -- (8, 4)coordinate(E)node[right]E;
                      draw (A) -- (C);
                      coordinate (I) at (intersection of 0,8--E and A--C);
                      fill[green](A)--(B)--(I)--cycle;
                      fill[blue](B)--(C)--(I)--cycle;
                      fill[red](C)--(E)--(I)--cycle;
                      fill[violet](A)--(D)--(E)--(I)--cycle;
                      endtikzpicture
                      enddocument


                      fill-region



                      Translated with www.DeepL.com/Translator






                      share|improve this answer
























                        up vote
                        1
                        down vote













                        One possibility is to calculate the coordinates of the intersection point of the two segments drawn in the square with TikZ; then to color the desired part.
                        For this purpose, there is an operation that is no longer documented in manual 3.0.1a but is fully functional.
                        Its documentation can be found in the manual 1.18 which is still available (until when?) here TikZ manual 1.18 (p 87, section 10.2.4 Intersection Coordinate Systems).



                        documentclass[border=5pt]standalone
                        usepackagetikz

                        begindocument
                        begintikzpicture
                        draw (0, 0) coordinate(A)node[below left]A-- (0, 8)coordinate(B)node[above left]B -- (8, 8)coordinate(C)node[above right]C -- (8, 0)coordinate(D)node[below right]D --cycle;
                        draw (B) -- (8, 4)coordinate(E)node[right]E;
                        draw (A) -- (C);
                        coordinate (I) at (intersection of 0,8--E and A--C);
                        fill[green](A)--(B)--(I)--cycle;
                        fill[blue](B)--(C)--(I)--cycle;
                        fill[red](C)--(E)--(I)--cycle;
                        fill[violet](A)--(D)--(E)--(I)--cycle;
                        endtikzpicture
                        enddocument


                        fill-region



                        Translated with www.DeepL.com/Translator






                        share|improve this answer






















                          up vote
                          1
                          down vote










                          up vote
                          1
                          down vote









                          One possibility is to calculate the coordinates of the intersection point of the two segments drawn in the square with TikZ; then to color the desired part.
                          For this purpose, there is an operation that is no longer documented in manual 3.0.1a but is fully functional.
                          Its documentation can be found in the manual 1.18 which is still available (until when?) here TikZ manual 1.18 (p 87, section 10.2.4 Intersection Coordinate Systems).



                          documentclass[border=5pt]standalone
                          usepackagetikz

                          begindocument
                          begintikzpicture
                          draw (0, 0) coordinate(A)node[below left]A-- (0, 8)coordinate(B)node[above left]B -- (8, 8)coordinate(C)node[above right]C -- (8, 0)coordinate(D)node[below right]D --cycle;
                          draw (B) -- (8, 4)coordinate(E)node[right]E;
                          draw (A) -- (C);
                          coordinate (I) at (intersection of 0,8--E and A--C);
                          fill[green](A)--(B)--(I)--cycle;
                          fill[blue](B)--(C)--(I)--cycle;
                          fill[red](C)--(E)--(I)--cycle;
                          fill[violet](A)--(D)--(E)--(I)--cycle;
                          endtikzpicture
                          enddocument


                          fill-region



                          Translated with www.DeepL.com/Translator






                          share|improve this answer












                          One possibility is to calculate the coordinates of the intersection point of the two segments drawn in the square with TikZ; then to color the desired part.
                          For this purpose, there is an operation that is no longer documented in manual 3.0.1a but is fully functional.
                          Its documentation can be found in the manual 1.18 which is still available (until when?) here TikZ manual 1.18 (p 87, section 10.2.4 Intersection Coordinate Systems).



                          documentclass[border=5pt]standalone
                          usepackagetikz

                          begindocument
                          begintikzpicture
                          draw (0, 0) coordinate(A)node[below left]A-- (0, 8)coordinate(B)node[above left]B -- (8, 8)coordinate(C)node[above right]C -- (8, 0)coordinate(D)node[below right]D --cycle;
                          draw (B) -- (8, 4)coordinate(E)node[right]E;
                          draw (A) -- (C);
                          coordinate (I) at (intersection of 0,8--E and A--C);
                          fill[green](A)--(B)--(I)--cycle;
                          fill[blue](B)--(C)--(I)--cycle;
                          fill[red](C)--(E)--(I)--cycle;
                          fill[violet](A)--(D)--(E)--(I)--cycle;
                          endtikzpicture
                          enddocument


                          fill-region



                          Translated with www.DeepL.com/Translator







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered 14 mins ago









                          AndréC

                          3,700729




                          3,700729



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f455112%2ftikz-method-to-color-regions%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Comments

                              Popular posts from this blog

                              What does second last employer means? [closed]

                              List of Gilmore Girls characters

                              Confectionery