How to clip overlaying surfaces/paths instead of filling them with white?
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
, but what I'd really like to have is:
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
|
show 3 more comments
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
, but what I'd really like to have is:
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
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
|
show 3 more comments
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
, but what I'd really like to have is:
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
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
, but what I'd really like to have is:
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
tikz-pgf path-clipping arc
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
|
show 3 more comments
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
|
show 3 more comments
1 Answer
1
active
oldest
votes
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:
The
remember picture
key on the main picture is needed to ensure that thecurrent 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 changeclip
tofill
and setfill opacity=.5
. Without theremember picture
then the rectangle blanked by thecurrent 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.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 calledagainpath
.To get the clips to obey the
even odd rule
we have to use a bit of subterfuge. We aren't allowed to put theeven odd rule
on theclip
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 theeven odd rule
directly. This is the keyclip even odd rule
which is (now) invoked as part of thereverseclip
style (since it probably should always be set for this type of clipping.
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%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
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:
The
remember picture
key on the main picture is needed to ensure that thecurrent 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 changeclip
tofill
and setfill opacity=.5
. Without theremember picture
then the rectangle blanked by thecurrent 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.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 calledagainpath
.To get the clips to obey the
even odd rule
we have to use a bit of subterfuge. We aren't allowed to put theeven odd rule
on theclip
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 theeven odd rule
directly. This is the keyclip even odd rule
which is (now) invoked as part of thereverseclip
style (since it probably should always be set for this type of clipping.
add a comment |
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:
The
remember picture
key on the main picture is needed to ensure that thecurrent 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 changeclip
tofill
and setfill opacity=.5
. Without theremember picture
then the rectangle blanked by thecurrent 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.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 calledagainpath
.To get the clips to obey the
even odd rule
we have to use a bit of subterfuge. We aren't allowed to put theeven odd rule
on theclip
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 theeven odd rule
directly. This is the keyclip even odd rule
which is (now) invoked as part of thereverseclip
style (since it probably should always be set for this type of clipping.
add a comment |
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:
The
remember picture
key on the main picture is needed to ensure that thecurrent 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 changeclip
tofill
and setfill opacity=.5
. Without theremember picture
then the rectangle blanked by thecurrent 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.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 calledagainpath
.To get the clips to obey the
even odd rule
we have to use a bit of subterfuge. We aren't allowed to put theeven odd rule
on theclip
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 theeven odd rule
directly. This is the keyclip even odd rule
which is (now) invoked as part of thereverseclip
style (since it probably should always be set for this type of clipping.
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:
The
remember picture
key on the main picture is needed to ensure that thecurrent 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 changeclip
tofill
and setfill opacity=.5
. Without theremember picture
then the rectangle blanked by thecurrent 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.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 calledagainpath
.To get the clips to obey the
even odd rule
we have to use a bit of subterfuge. We aren't allowed to put theeven odd rule
on theclip
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 theeven odd rule
directly. This is the keyclip even odd rule
which is (now) invoked as part of thereverseclip
style (since it probably should always be set for this type of clipping.
edited Apr 13 '17 at 12:35
community wiki
7 revs, 2 users 64%
letmaik
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%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
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 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