How to clip overlaying surfaces/paths instead of filling them with white?












6















The following code



newcommand*{arcthickness}{0.3}
newcommand*{myarc}[4]{ % x,y,radius,text
% node is positioned by splitting the arc in two parts
% see http://tex.stackexchange.com/a/76369/6255
draw (#1,#2) arc (180:90:#3)
node[below=-1.5pt] {tiny #4}
arc (90:0:#3)
-- ++(-arcthickness,0) arc (0:180:#3-arcthickness) -- cycle;
}
begin{tikzpicture}
myarc{0}{0}{1}{A}
myarc{3}{0}{1}{C}
myarc{1}{0}{1.5}{B}
end{tikzpicture}


produces



arc



, but what I'd really like to have is:



arc



where the intersected parts are not white but should just be left out (clipped). The reason is that the figure should work on any background color. And, of course, ideally it should work in a generic way where a further application of myarc overlays/clips the previous ones.










share|improve this question

























  • You need to clip the lower arcs against the higher ones, which suggests drawing them in reverse order: each arc draws itself and then defines a reverse clip against itself for all future drawings. Would that suit? Reverse clipping can be found at tex.stackexchange.com/q/12010/86

    – Loop Space
    Oct 12 '12 at 10:41











  • @AndrewStacey Wow, seems to work, I'll post a solution, but this can be marked as duplicate.

    – letmaik
    Oct 12 '12 at 10:53













  • @AndrewStacey I made a community wiki answer, there are still some issues though, maybe I haven't understood the reverse clipping completely yet.

    – letmaik
    Oct 12 '12 at 11:11











  • I've modified your answer hopefully correcting the issues you found. The clipping one is subtle!

    – Loop Space
    Oct 12 '12 at 13:10











  • @AndrewStacey Thanks for that, looks a lot cleaner now! While refactoring I discovered a really strange problem, see my edit at the bottom

    – letmaik
    Oct 12 '12 at 13:24


















6















The following code



newcommand*{arcthickness}{0.3}
newcommand*{myarc}[4]{ % x,y,radius,text
% node is positioned by splitting the arc in two parts
% see http://tex.stackexchange.com/a/76369/6255
draw (#1,#2) arc (180:90:#3)
node[below=-1.5pt] {tiny #4}
arc (90:0:#3)
-- ++(-arcthickness,0) arc (0:180:#3-arcthickness) -- cycle;
}
begin{tikzpicture}
myarc{0}{0}{1}{A}
myarc{3}{0}{1}{C}
myarc{1}{0}{1.5}{B}
end{tikzpicture}


produces



arc



, but what I'd really like to have is:



arc



where the intersected parts are not white but should just be left out (clipped). The reason is that the figure should work on any background color. And, of course, ideally it should work in a generic way where a further application of myarc overlays/clips the previous ones.










share|improve this question

























  • You need to clip the lower arcs against the higher ones, which suggests drawing them in reverse order: each arc draws itself and then defines a reverse clip against itself for all future drawings. Would that suit? Reverse clipping can be found at tex.stackexchange.com/q/12010/86

    – Loop Space
    Oct 12 '12 at 10:41











  • @AndrewStacey Wow, seems to work, I'll post a solution, but this can be marked as duplicate.

    – letmaik
    Oct 12 '12 at 10:53













  • @AndrewStacey I made a community wiki answer, there are still some issues though, maybe I haven't understood the reverse clipping completely yet.

    – letmaik
    Oct 12 '12 at 11:11











  • I've modified your answer hopefully correcting the issues you found. The clipping one is subtle!

    – Loop Space
    Oct 12 '12 at 13:10











  • @AndrewStacey Thanks for that, looks a lot cleaner now! While refactoring I discovered a really strange problem, see my edit at the bottom

    – letmaik
    Oct 12 '12 at 13:24
















6












6








6


1






The following code



newcommand*{arcthickness}{0.3}
newcommand*{myarc}[4]{ % x,y,radius,text
% node is positioned by splitting the arc in two parts
% see http://tex.stackexchange.com/a/76369/6255
draw (#1,#2) arc (180:90:#3)
node[below=-1.5pt] {tiny #4}
arc (90:0:#3)
-- ++(-arcthickness,0) arc (0:180:#3-arcthickness) -- cycle;
}
begin{tikzpicture}
myarc{0}{0}{1}{A}
myarc{3}{0}{1}{C}
myarc{1}{0}{1.5}{B}
end{tikzpicture}


produces



arc



, but what I'd really like to have is:



arc



where the intersected parts are not white but should just be left out (clipped). The reason is that the figure should work on any background color. And, of course, ideally it should work in a generic way where a further application of myarc overlays/clips the previous ones.










share|improve this question
















The following code



newcommand*{arcthickness}{0.3}
newcommand*{myarc}[4]{ % x,y,radius,text
% node is positioned by splitting the arc in two parts
% see http://tex.stackexchange.com/a/76369/6255
draw (#1,#2) arc (180:90:#3)
node[below=-1.5pt] {tiny #4}
arc (90:0:#3)
-- ++(-arcthickness,0) arc (0:180:#3-arcthickness) -- cycle;
}
begin{tikzpicture}
myarc{0}{0}{1}{A}
myarc{3}{0}{1}{C}
myarc{1}{0}{1.5}{B}
end{tikzpicture}


produces



arc



, but what I'd really like to have is:



arc



where the intersected parts are not white but should just be left out (clipped). The reason is that the figure should work on any background color. And, of course, ideally it should work in a generic way where a further application of myarc overlays/clips the previous ones.







tikz-pgf path-clipping arc






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 1 at 21:33









Glorfindel

211129




211129










asked Oct 12 '12 at 10:35









letmaikletmaik

9971823




9971823













  • You need to clip the lower arcs against the higher ones, which suggests drawing them in reverse order: each arc draws itself and then defines a reverse clip against itself for all future drawings. Would that suit? Reverse clipping can be found at tex.stackexchange.com/q/12010/86

    – Loop Space
    Oct 12 '12 at 10:41











  • @AndrewStacey Wow, seems to work, I'll post a solution, but this can be marked as duplicate.

    – letmaik
    Oct 12 '12 at 10:53













  • @AndrewStacey I made a community wiki answer, there are still some issues though, maybe I haven't understood the reverse clipping completely yet.

    – letmaik
    Oct 12 '12 at 11:11











  • I've modified your answer hopefully correcting the issues you found. The clipping one is subtle!

    – Loop Space
    Oct 12 '12 at 13:10











  • @AndrewStacey Thanks for that, looks a lot cleaner now! While refactoring I discovered a really strange problem, see my edit at the bottom

    – letmaik
    Oct 12 '12 at 13:24





















  • You need to clip the lower arcs against the higher ones, which suggests drawing them in reverse order: each arc draws itself and then defines a reverse clip against itself for all future drawings. Would that suit? Reverse clipping can be found at tex.stackexchange.com/q/12010/86

    – Loop Space
    Oct 12 '12 at 10:41











  • @AndrewStacey Wow, seems to work, I'll post a solution, but this can be marked as duplicate.

    – letmaik
    Oct 12 '12 at 10:53













  • @AndrewStacey I made a community wiki answer, there are still some issues though, maybe I haven't understood the reverse clipping completely yet.

    – letmaik
    Oct 12 '12 at 11:11











  • I've modified your answer hopefully correcting the issues you found. The clipping one is subtle!

    – Loop Space
    Oct 12 '12 at 13:10











  • @AndrewStacey Thanks for that, looks a lot cleaner now! While refactoring I discovered a really strange problem, see my edit at the bottom

    – letmaik
    Oct 12 '12 at 13:24



















You need to clip the lower arcs against the higher ones, which suggests drawing them in reverse order: each arc draws itself and then defines a reverse clip against itself for all future drawings. Would that suit? Reverse clipping can be found at tex.stackexchange.com/q/12010/86

– Loop Space
Oct 12 '12 at 10:41





You need to clip the lower arcs against the higher ones, which suggests drawing them in reverse order: each arc draws itself and then defines a reverse clip against itself for all future drawings. Would that suit? Reverse clipping can be found at tex.stackexchange.com/q/12010/86

– Loop Space
Oct 12 '12 at 10:41













@AndrewStacey Wow, seems to work, I'll post a solution, but this can be marked as duplicate.

– letmaik
Oct 12 '12 at 10:53







@AndrewStacey Wow, seems to work, I'll post a solution, but this can be marked as duplicate.

– letmaik
Oct 12 '12 at 10:53















@AndrewStacey I made a community wiki answer, there are still some issues though, maybe I haven't understood the reverse clipping completely yet.

– letmaik
Oct 12 '12 at 11:11





@AndrewStacey I made a community wiki answer, there are still some issues though, maybe I haven't understood the reverse clipping completely yet.

– letmaik
Oct 12 '12 at 11:11













I've modified your answer hopefully correcting the issues you found. The clipping one is subtle!

– Loop Space
Oct 12 '12 at 13:10





I've modified your answer hopefully correcting the issues you found. The clipping one is subtle!

– Loop Space
Oct 12 '12 at 13:10













@AndrewStacey Thanks for that, looks a lot cleaner now! While refactoring I discovered a really strange problem, see my edit at the bottom

– letmaik
Oct 12 '12 at 13:24







@AndrewStacey Thanks for that, looks a lot cleaner now! While refactoring I discovered a really strange problem, see my edit at the bottom

– letmaik
Oct 12 '12 at 13:24












1 Answer
1






active

oldest

votes


















6














As suggested by Andrew, reverse clipping can be used:



documentclass{article}
%url{https://tex.stackexchange.com/q/76409/86}
usepackage{tikz}

tikzset{
reverseclip/.style={
clip even odd rule,
insert path={(current page.north east) --
(current page.south east) --
(current page.south west) --
(current page.north west) --
(current page.north east)}
},
clip even odd rule/.code={pgfseteorule}
}

newcommand*{reverseclip}[1]{
begin{pgfinterruptboundingbox}
clip[reverseclip] againpath #1;
end{pgfinterruptboundingbox}
}

newcommand*{arcthickness}{0.3}
newcommand*{myarc}[4]{ % x,y,radius,text
% node is positioned by splitting the arc in two parts
% (workaround until new pgf is released)
% see https://tex.stackexchange.com/a/76369/6255
draw[save path=arcclippath]
(#1,#2) arc (180:90:#3)
node[below=-1.5pt] {tiny #4}
arc (90:0:#3)
-- ++(-arcthickness,0) arc (0:180:#3-arcthickness) -- cycle;
reverseclip{arcclippath}
}

begin{document}

begin{tikzpicture}[remember picture]

myarc{1}{0}{1.5}{B}
myarc{0}{0}{1}{A}
myarc{3}{0}{1}{C}

end{tikzpicture}
end{document}


Notes:




  1. The remember picture key on the main picture is needed to ensure that the current page pseudo-node works as it should. Without that, it is incorrectly positioned and so the clip region is not quite what is expected. A good way to debug clipping is to change clip to fill and set fill opacity=.5. Without the remember picture then the rectangle blanked by the current page is offset to the position of the current picture rather than of the page. However, overlay is not needed as the extra large pieces of the picture are not used when computing its bounding box.


  2. To avoid path duplication, we use the ability of TikZ to save a path for later use. This is the save path key. To restore it, we use a command called againpath.


  3. To get the clips to obey the even odd rule we have to use a bit of subterfuge. We aren't allowed to put the even odd rule on the clip path itself (as this triggers the dread warning from TikZ) and as we want the clip to continue in effect we cannot put it inside a scope. So we have to duplicated the effect of the even odd rule directly. This is the key clip even odd rule which is (now) invoked as part of the reverseclip style (since it probably should always be set for this type of clipping.



Arcs with clipping






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


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f76409%2fhow-to-clip-overlaying-surfaces-paths-instead-of-filling-them-with-white%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    6














    As suggested by Andrew, reverse clipping can be used:



    documentclass{article}
    %url{https://tex.stackexchange.com/q/76409/86}
    usepackage{tikz}

    tikzset{
    reverseclip/.style={
    clip even odd rule,
    insert path={(current page.north east) --
    (current page.south east) --
    (current page.south west) --
    (current page.north west) --
    (current page.north east)}
    },
    clip even odd rule/.code={pgfseteorule}
    }

    newcommand*{reverseclip}[1]{
    begin{pgfinterruptboundingbox}
    clip[reverseclip] againpath #1;
    end{pgfinterruptboundingbox}
    }

    newcommand*{arcthickness}{0.3}
    newcommand*{myarc}[4]{ % x,y,radius,text
    % node is positioned by splitting the arc in two parts
    % (workaround until new pgf is released)
    % see https://tex.stackexchange.com/a/76369/6255
    draw[save path=arcclippath]
    (#1,#2) arc (180:90:#3)
    node[below=-1.5pt] {tiny #4}
    arc (90:0:#3)
    -- ++(-arcthickness,0) arc (0:180:#3-arcthickness) -- cycle;
    reverseclip{arcclippath}
    }

    begin{document}

    begin{tikzpicture}[remember picture]

    myarc{1}{0}{1.5}{B}
    myarc{0}{0}{1}{A}
    myarc{3}{0}{1}{C}

    end{tikzpicture}
    end{document}


    Notes:




    1. The remember picture key on the main picture is needed to ensure that the current page pseudo-node works as it should. Without that, it is incorrectly positioned and so the clip region is not quite what is expected. A good way to debug clipping is to change clip to fill and set fill opacity=.5. Without the remember picture then the rectangle blanked by the current page is offset to the position of the current picture rather than of the page. However, overlay is not needed as the extra large pieces of the picture are not used when computing its bounding box.


    2. To avoid path duplication, we use the ability of TikZ to save a path for later use. This is the save path key. To restore it, we use a command called againpath.


    3. To get the clips to obey the even odd rule we have to use a bit of subterfuge. We aren't allowed to put the even odd rule on the clip path itself (as this triggers the dread warning from TikZ) and as we want the clip to continue in effect we cannot put it inside a scope. So we have to duplicated the effect of the even odd rule directly. This is the key clip even odd rule which is (now) invoked as part of the reverseclip style (since it probably should always be set for this type of clipping.



    Arcs with clipping






    share|improve this answer






























      6














      As suggested by Andrew, reverse clipping can be used:



      documentclass{article}
      %url{https://tex.stackexchange.com/q/76409/86}
      usepackage{tikz}

      tikzset{
      reverseclip/.style={
      clip even odd rule,
      insert path={(current page.north east) --
      (current page.south east) --
      (current page.south west) --
      (current page.north west) --
      (current page.north east)}
      },
      clip even odd rule/.code={pgfseteorule}
      }

      newcommand*{reverseclip}[1]{
      begin{pgfinterruptboundingbox}
      clip[reverseclip] againpath #1;
      end{pgfinterruptboundingbox}
      }

      newcommand*{arcthickness}{0.3}
      newcommand*{myarc}[4]{ % x,y,radius,text
      % node is positioned by splitting the arc in two parts
      % (workaround until new pgf is released)
      % see https://tex.stackexchange.com/a/76369/6255
      draw[save path=arcclippath]
      (#1,#2) arc (180:90:#3)
      node[below=-1.5pt] {tiny #4}
      arc (90:0:#3)
      -- ++(-arcthickness,0) arc (0:180:#3-arcthickness) -- cycle;
      reverseclip{arcclippath}
      }

      begin{document}

      begin{tikzpicture}[remember picture]

      myarc{1}{0}{1.5}{B}
      myarc{0}{0}{1}{A}
      myarc{3}{0}{1}{C}

      end{tikzpicture}
      end{document}


      Notes:




      1. The remember picture key on the main picture is needed to ensure that the current page pseudo-node works as it should. Without that, it is incorrectly positioned and so the clip region is not quite what is expected. A good way to debug clipping is to change clip to fill and set fill opacity=.5. Without the remember picture then the rectangle blanked by the current page is offset to the position of the current picture rather than of the page. However, overlay is not needed as the extra large pieces of the picture are not used when computing its bounding box.


      2. To avoid path duplication, we use the ability of TikZ to save a path for later use. This is the save path key. To restore it, we use a command called againpath.


      3. To get the clips to obey the even odd rule we have to use a bit of subterfuge. We aren't allowed to put the even odd rule on the clip path itself (as this triggers the dread warning from TikZ) and as we want the clip to continue in effect we cannot put it inside a scope. So we have to duplicated the effect of the even odd rule directly. This is the key clip even odd rule which is (now) invoked as part of the reverseclip style (since it probably should always be set for this type of clipping.



      Arcs with clipping






      share|improve this answer




























        6












        6








        6







        As suggested by Andrew, reverse clipping can be used:



        documentclass{article}
        %url{https://tex.stackexchange.com/q/76409/86}
        usepackage{tikz}

        tikzset{
        reverseclip/.style={
        clip even odd rule,
        insert path={(current page.north east) --
        (current page.south east) --
        (current page.south west) --
        (current page.north west) --
        (current page.north east)}
        },
        clip even odd rule/.code={pgfseteorule}
        }

        newcommand*{reverseclip}[1]{
        begin{pgfinterruptboundingbox}
        clip[reverseclip] againpath #1;
        end{pgfinterruptboundingbox}
        }

        newcommand*{arcthickness}{0.3}
        newcommand*{myarc}[4]{ % x,y,radius,text
        % node is positioned by splitting the arc in two parts
        % (workaround until new pgf is released)
        % see https://tex.stackexchange.com/a/76369/6255
        draw[save path=arcclippath]
        (#1,#2) arc (180:90:#3)
        node[below=-1.5pt] {tiny #4}
        arc (90:0:#3)
        -- ++(-arcthickness,0) arc (0:180:#3-arcthickness) -- cycle;
        reverseclip{arcclippath}
        }

        begin{document}

        begin{tikzpicture}[remember picture]

        myarc{1}{0}{1.5}{B}
        myarc{0}{0}{1}{A}
        myarc{3}{0}{1}{C}

        end{tikzpicture}
        end{document}


        Notes:




        1. The remember picture key on the main picture is needed to ensure that the current page pseudo-node works as it should. Without that, it is incorrectly positioned and so the clip region is not quite what is expected. A good way to debug clipping is to change clip to fill and set fill opacity=.5. Without the remember picture then the rectangle blanked by the current page is offset to the position of the current picture rather than of the page. However, overlay is not needed as the extra large pieces of the picture are not used when computing its bounding box.


        2. To avoid path duplication, we use the ability of TikZ to save a path for later use. This is the save path key. To restore it, we use a command called againpath.


        3. To get the clips to obey the even odd rule we have to use a bit of subterfuge. We aren't allowed to put the even odd rule on the clip path itself (as this triggers the dread warning from TikZ) and as we want the clip to continue in effect we cannot put it inside a scope. So we have to duplicated the effect of the even odd rule directly. This is the key clip even odd rule which is (now) invoked as part of the reverseclip style (since it probably should always be set for this type of clipping.



        Arcs with clipping






        share|improve this answer















        As suggested by Andrew, reverse clipping can be used:



        documentclass{article}
        %url{https://tex.stackexchange.com/q/76409/86}
        usepackage{tikz}

        tikzset{
        reverseclip/.style={
        clip even odd rule,
        insert path={(current page.north east) --
        (current page.south east) --
        (current page.south west) --
        (current page.north west) --
        (current page.north east)}
        },
        clip even odd rule/.code={pgfseteorule}
        }

        newcommand*{reverseclip}[1]{
        begin{pgfinterruptboundingbox}
        clip[reverseclip] againpath #1;
        end{pgfinterruptboundingbox}
        }

        newcommand*{arcthickness}{0.3}
        newcommand*{myarc}[4]{ % x,y,radius,text
        % node is positioned by splitting the arc in two parts
        % (workaround until new pgf is released)
        % see https://tex.stackexchange.com/a/76369/6255
        draw[save path=arcclippath]
        (#1,#2) arc (180:90:#3)
        node[below=-1.5pt] {tiny #4}
        arc (90:0:#3)
        -- ++(-arcthickness,0) arc (0:180:#3-arcthickness) -- cycle;
        reverseclip{arcclippath}
        }

        begin{document}

        begin{tikzpicture}[remember picture]

        myarc{1}{0}{1.5}{B}
        myarc{0}{0}{1}{A}
        myarc{3}{0}{1}{C}

        end{tikzpicture}
        end{document}


        Notes:




        1. The remember picture key on the main picture is needed to ensure that the current page pseudo-node works as it should. Without that, it is incorrectly positioned and so the clip region is not quite what is expected. A good way to debug clipping is to change clip to fill and set fill opacity=.5. Without the remember picture then the rectangle blanked by the current page is offset to the position of the current picture rather than of the page. However, overlay is not needed as the extra large pieces of the picture are not used when computing its bounding box.


        2. To avoid path duplication, we use the ability of TikZ to save a path for later use. This is the save path key. To restore it, we use a command called againpath.


        3. To get the clips to obey the even odd rule we have to use a bit of subterfuge. We aren't allowed to put the even odd rule on the clip path itself (as this triggers the dread warning from TikZ) and as we want the clip to continue in effect we cannot put it inside a scope. So we have to duplicated the effect of the even odd rule directly. This is the key clip even odd rule which is (now) invoked as part of the reverseclip style (since it probably should always be set for this type of clipping.



        Arcs with clipping







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Apr 13 '17 at 12:35


























        community wiki





        7 revs, 2 users 64%
        letmaik































            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f76409%2fhow-to-clip-overlaying-surfaces-paths-instead-of-filling-them-with-white%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

            How to change which sound is reproduced for terminal bell?

            Can I use Tabulator js library in my java Spring + Thymeleaf project?

            Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents