Fill the area between two curves
Clash Royale CLAN TAG#URR8PPP
up vote
10
down vote
favorite
Hi I am trying to fill the area between two curves. One curve is two joined arcs, and the other is one freehand curve. The part I want to fill is the white area. I use the fillbetween
library but I just can't get the upper curve right.
Your help is much appreciated. A MWE is as follows
documentclass[margin=10pt]standalone
usepackagetikz
usepackagepgfplots
pgfplotssetcompat=newest
usepgfplotslibraryfillbetween
usetikzlibraryintersections
begindocument
begintikzpicture%[x=1cm, y=1cm]
defrsmall2
defrlarge4
defalpha60
defbeta40
defgamma20
defAoutalpha+gamma-90
defBin270-beta-gamma
pgfmathsetmacroax-rsmall+cos(alpha)*rsmall
pgfmathsetmacroaysin(alpha)*rsmall
pgfmathsetmacrobxrlarge-cos(beta)*rlarge
pgfmathsetmacrobysin(beta)*rlarge
filldraw[name path=arcs, fill=gray!20, thick]
(180:2*rsmall) arc (180:0:rsmall) arc (180:0:rlarge);
coordinate (A) at (ax, ay);
coordinate (B) at (bx, by);
draw[name path=unduloid, thick] (A) to[out=Aout, in=Bin] (B);
fill[blue!20,intersection segments=of=unduloid and arcs,sequence=L2--R2];
endtikzpicture
enddocument
tikz-pgf fillbetween
add a comment |Â
up vote
10
down vote
favorite
Hi I am trying to fill the area between two curves. One curve is two joined arcs, and the other is one freehand curve. The part I want to fill is the white area. I use the fillbetween
library but I just can't get the upper curve right.
Your help is much appreciated. A MWE is as follows
documentclass[margin=10pt]standalone
usepackagetikz
usepackagepgfplots
pgfplotssetcompat=newest
usepgfplotslibraryfillbetween
usetikzlibraryintersections
begindocument
begintikzpicture%[x=1cm, y=1cm]
defrsmall2
defrlarge4
defalpha60
defbeta40
defgamma20
defAoutalpha+gamma-90
defBin270-beta-gamma
pgfmathsetmacroax-rsmall+cos(alpha)*rsmall
pgfmathsetmacroaysin(alpha)*rsmall
pgfmathsetmacrobxrlarge-cos(beta)*rlarge
pgfmathsetmacrobysin(beta)*rlarge
filldraw[name path=arcs, fill=gray!20, thick]
(180:2*rsmall) arc (180:0:rsmall) arc (180:0:rlarge);
coordinate (A) at (ax, ay);
coordinate (B) at (bx, by);
draw[name path=unduloid, thick] (A) to[out=Aout, in=Bin] (B);
fill[blue!20,intersection segments=of=unduloid and arcs,sequence=L2--R2];
endtikzpicture
enddocument
tikz-pgf fillbetween
add a comment |Â
up vote
10
down vote
favorite
up vote
10
down vote
favorite
Hi I am trying to fill the area between two curves. One curve is two joined arcs, and the other is one freehand curve. The part I want to fill is the white area. I use the fillbetween
library but I just can't get the upper curve right.
Your help is much appreciated. A MWE is as follows
documentclass[margin=10pt]standalone
usepackagetikz
usepackagepgfplots
pgfplotssetcompat=newest
usepgfplotslibraryfillbetween
usetikzlibraryintersections
begindocument
begintikzpicture%[x=1cm, y=1cm]
defrsmall2
defrlarge4
defalpha60
defbeta40
defgamma20
defAoutalpha+gamma-90
defBin270-beta-gamma
pgfmathsetmacroax-rsmall+cos(alpha)*rsmall
pgfmathsetmacroaysin(alpha)*rsmall
pgfmathsetmacrobxrlarge-cos(beta)*rlarge
pgfmathsetmacrobysin(beta)*rlarge
filldraw[name path=arcs, fill=gray!20, thick]
(180:2*rsmall) arc (180:0:rsmall) arc (180:0:rlarge);
coordinate (A) at (ax, ay);
coordinate (B) at (bx, by);
draw[name path=unduloid, thick] (A) to[out=Aout, in=Bin] (B);
fill[blue!20,intersection segments=of=unduloid and arcs,sequence=L2--R2];
endtikzpicture
enddocument
tikz-pgf fillbetween
Hi I am trying to fill the area between two curves. One curve is two joined arcs, and the other is one freehand curve. The part I want to fill is the white area. I use the fillbetween
library but I just can't get the upper curve right.
Your help is much appreciated. A MWE is as follows
documentclass[margin=10pt]standalone
usepackagetikz
usepackagepgfplots
pgfplotssetcompat=newest
usepgfplotslibraryfillbetween
usetikzlibraryintersections
begindocument
begintikzpicture%[x=1cm, y=1cm]
defrsmall2
defrlarge4
defalpha60
defbeta40
defgamma20
defAoutalpha+gamma-90
defBin270-beta-gamma
pgfmathsetmacroax-rsmall+cos(alpha)*rsmall
pgfmathsetmacroaysin(alpha)*rsmall
pgfmathsetmacrobxrlarge-cos(beta)*rlarge
pgfmathsetmacrobysin(beta)*rlarge
filldraw[name path=arcs, fill=gray!20, thick]
(180:2*rsmall) arc (180:0:rsmall) arc (180:0:rlarge);
coordinate (A) at (ax, ay);
coordinate (B) at (bx, by);
draw[name path=unduloid, thick] (A) to[out=Aout, in=Bin] (B);
fill[blue!20,intersection segments=of=unduloid and arcs,sequence=L2--R2];
endtikzpicture
enddocument
tikz-pgf fillbetween
asked Aug 23 at 3:28
noir
43538
43538
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
14
down vote
accepted
You only need to add a [reverse]
to one of the segments.
documentclass[margin=10pt]standalone
usepackagetikz
usepackagepgfplots
pgfplotssetcompat=newest
usepgfplotslibraryfillbetween
usetikzlibraryintersections
begindocument
begintikzpicture%[x=1cm, y=1cm]
defrsmall2
defrlarge4
defalpha60
defbeta40
defgamma20
defAoutalpha+gamma-90
defBin270-beta-gamma
pgfmathsetmacroax-rsmall+cos(alpha)*rsmall
pgfmathsetmacroaysin(alpha)*rsmall
pgfmathsetmacrobxrlarge-cos(beta)*rlarge
pgfmathsetmacrobysin(beta)*rlarge
filldraw[name path=arcs, fill=gray!20, thick]
(180:2*rsmall) arc (180:0:rsmall) arc (180:0:rlarge);
coordinate (A) at (ax, ay);
coordinate (B) at (bx, by);
draw[name path=unduloid, thick] (A) to[out=Aout, in=Bin] (B);
path[%draw=red,thick,
fill=blue!20,intersection segments=of=unduloid and arcs,sequence=L2--R2[reverse]];
endtikzpicture
enddocument
How can one debug this? Just draw curves with arrows on the segments in question. Here one would add
draw[red,thick,-latex,
intersection segments=of=unduloid and arcs,sequence=L2];
draw[blue,thick,-latex,
intersection segments=of=unduloid and arcs,sequence=R2];
and then get
This means that the paths start and end at the same points. To fix this, i.e. to produce a cycle, you have to run through one of the paths in the reverse
direction. If you don't, TikZ will close the path on its own by a straight line. That's why you got the straight line for one of the bounding curves.
ADDENDUM: In this situation you do not really need all the segments nor the fillbetween
library. Personally I would also refrain from redefining alpha
, beta
etc. since you may need these Greek symbols.
documentclass[margin=10pt]standalone
usepackagetikz
usetikzlibrarycalc
begindocument
begintikzpicture%[x=1cm, y=1cm]
defrsmall2
defrlarge4
defmyalpha60
defmybeta40
defgamma20
defAoutmyalpha+gamma-90
defBin270-mybeta-gamma
filldraw[fill=gray!20, thick]
(180:2*rsmall) arc (180:0:rsmall) arc (180:0:rlarge);
coordinate (A) at ($(-rsmall,0)+(myalpha:rsmall)$);
coordinate (B) at ($(rlarge,0)+(180-mybeta:rlarge)$);
draw[red,fill=blue!20, thick] (A) to[out=Aout, in=Bin] (B)
arc(180-mybeta:180:rlarge) arc(0:myalpha:rsmall) -- cycle;
endtikzpicture
enddocument
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
14
down vote
accepted
You only need to add a [reverse]
to one of the segments.
documentclass[margin=10pt]standalone
usepackagetikz
usepackagepgfplots
pgfplotssetcompat=newest
usepgfplotslibraryfillbetween
usetikzlibraryintersections
begindocument
begintikzpicture%[x=1cm, y=1cm]
defrsmall2
defrlarge4
defalpha60
defbeta40
defgamma20
defAoutalpha+gamma-90
defBin270-beta-gamma
pgfmathsetmacroax-rsmall+cos(alpha)*rsmall
pgfmathsetmacroaysin(alpha)*rsmall
pgfmathsetmacrobxrlarge-cos(beta)*rlarge
pgfmathsetmacrobysin(beta)*rlarge
filldraw[name path=arcs, fill=gray!20, thick]
(180:2*rsmall) arc (180:0:rsmall) arc (180:0:rlarge);
coordinate (A) at (ax, ay);
coordinate (B) at (bx, by);
draw[name path=unduloid, thick] (A) to[out=Aout, in=Bin] (B);
path[%draw=red,thick,
fill=blue!20,intersection segments=of=unduloid and arcs,sequence=L2--R2[reverse]];
endtikzpicture
enddocument
How can one debug this? Just draw curves with arrows on the segments in question. Here one would add
draw[red,thick,-latex,
intersection segments=of=unduloid and arcs,sequence=L2];
draw[blue,thick,-latex,
intersection segments=of=unduloid and arcs,sequence=R2];
and then get
This means that the paths start and end at the same points. To fix this, i.e. to produce a cycle, you have to run through one of the paths in the reverse
direction. If you don't, TikZ will close the path on its own by a straight line. That's why you got the straight line for one of the bounding curves.
ADDENDUM: In this situation you do not really need all the segments nor the fillbetween
library. Personally I would also refrain from redefining alpha
, beta
etc. since you may need these Greek symbols.
documentclass[margin=10pt]standalone
usepackagetikz
usetikzlibrarycalc
begindocument
begintikzpicture%[x=1cm, y=1cm]
defrsmall2
defrlarge4
defmyalpha60
defmybeta40
defgamma20
defAoutmyalpha+gamma-90
defBin270-mybeta-gamma
filldraw[fill=gray!20, thick]
(180:2*rsmall) arc (180:0:rsmall) arc (180:0:rlarge);
coordinate (A) at ($(-rsmall,0)+(myalpha:rsmall)$);
coordinate (B) at ($(rlarge,0)+(180-mybeta:rlarge)$);
draw[red,fill=blue!20, thick] (A) to[out=Aout, in=Bin] (B)
arc(180-mybeta:180:rlarge) arc(0:myalpha:rsmall) -- cycle;
endtikzpicture
enddocument
add a comment |Â
up vote
14
down vote
accepted
You only need to add a [reverse]
to one of the segments.
documentclass[margin=10pt]standalone
usepackagetikz
usepackagepgfplots
pgfplotssetcompat=newest
usepgfplotslibraryfillbetween
usetikzlibraryintersections
begindocument
begintikzpicture%[x=1cm, y=1cm]
defrsmall2
defrlarge4
defalpha60
defbeta40
defgamma20
defAoutalpha+gamma-90
defBin270-beta-gamma
pgfmathsetmacroax-rsmall+cos(alpha)*rsmall
pgfmathsetmacroaysin(alpha)*rsmall
pgfmathsetmacrobxrlarge-cos(beta)*rlarge
pgfmathsetmacrobysin(beta)*rlarge
filldraw[name path=arcs, fill=gray!20, thick]
(180:2*rsmall) arc (180:0:rsmall) arc (180:0:rlarge);
coordinate (A) at (ax, ay);
coordinate (B) at (bx, by);
draw[name path=unduloid, thick] (A) to[out=Aout, in=Bin] (B);
path[%draw=red,thick,
fill=blue!20,intersection segments=of=unduloid and arcs,sequence=L2--R2[reverse]];
endtikzpicture
enddocument
How can one debug this? Just draw curves with arrows on the segments in question. Here one would add
draw[red,thick,-latex,
intersection segments=of=unduloid and arcs,sequence=L2];
draw[blue,thick,-latex,
intersection segments=of=unduloid and arcs,sequence=R2];
and then get
This means that the paths start and end at the same points. To fix this, i.e. to produce a cycle, you have to run through one of the paths in the reverse
direction. If you don't, TikZ will close the path on its own by a straight line. That's why you got the straight line for one of the bounding curves.
ADDENDUM: In this situation you do not really need all the segments nor the fillbetween
library. Personally I would also refrain from redefining alpha
, beta
etc. since you may need these Greek symbols.
documentclass[margin=10pt]standalone
usepackagetikz
usetikzlibrarycalc
begindocument
begintikzpicture%[x=1cm, y=1cm]
defrsmall2
defrlarge4
defmyalpha60
defmybeta40
defgamma20
defAoutmyalpha+gamma-90
defBin270-mybeta-gamma
filldraw[fill=gray!20, thick]
(180:2*rsmall) arc (180:0:rsmall) arc (180:0:rlarge);
coordinate (A) at ($(-rsmall,0)+(myalpha:rsmall)$);
coordinate (B) at ($(rlarge,0)+(180-mybeta:rlarge)$);
draw[red,fill=blue!20, thick] (A) to[out=Aout, in=Bin] (B)
arc(180-mybeta:180:rlarge) arc(0:myalpha:rsmall) -- cycle;
endtikzpicture
enddocument
add a comment |Â
up vote
14
down vote
accepted
up vote
14
down vote
accepted
You only need to add a [reverse]
to one of the segments.
documentclass[margin=10pt]standalone
usepackagetikz
usepackagepgfplots
pgfplotssetcompat=newest
usepgfplotslibraryfillbetween
usetikzlibraryintersections
begindocument
begintikzpicture%[x=1cm, y=1cm]
defrsmall2
defrlarge4
defalpha60
defbeta40
defgamma20
defAoutalpha+gamma-90
defBin270-beta-gamma
pgfmathsetmacroax-rsmall+cos(alpha)*rsmall
pgfmathsetmacroaysin(alpha)*rsmall
pgfmathsetmacrobxrlarge-cos(beta)*rlarge
pgfmathsetmacrobysin(beta)*rlarge
filldraw[name path=arcs, fill=gray!20, thick]
(180:2*rsmall) arc (180:0:rsmall) arc (180:0:rlarge);
coordinate (A) at (ax, ay);
coordinate (B) at (bx, by);
draw[name path=unduloid, thick] (A) to[out=Aout, in=Bin] (B);
path[%draw=red,thick,
fill=blue!20,intersection segments=of=unduloid and arcs,sequence=L2--R2[reverse]];
endtikzpicture
enddocument
How can one debug this? Just draw curves with arrows on the segments in question. Here one would add
draw[red,thick,-latex,
intersection segments=of=unduloid and arcs,sequence=L2];
draw[blue,thick,-latex,
intersection segments=of=unduloid and arcs,sequence=R2];
and then get
This means that the paths start and end at the same points. To fix this, i.e. to produce a cycle, you have to run through one of the paths in the reverse
direction. If you don't, TikZ will close the path on its own by a straight line. That's why you got the straight line for one of the bounding curves.
ADDENDUM: In this situation you do not really need all the segments nor the fillbetween
library. Personally I would also refrain from redefining alpha
, beta
etc. since you may need these Greek symbols.
documentclass[margin=10pt]standalone
usepackagetikz
usetikzlibrarycalc
begindocument
begintikzpicture%[x=1cm, y=1cm]
defrsmall2
defrlarge4
defmyalpha60
defmybeta40
defgamma20
defAoutmyalpha+gamma-90
defBin270-mybeta-gamma
filldraw[fill=gray!20, thick]
(180:2*rsmall) arc (180:0:rsmall) arc (180:0:rlarge);
coordinate (A) at ($(-rsmall,0)+(myalpha:rsmall)$);
coordinate (B) at ($(rlarge,0)+(180-mybeta:rlarge)$);
draw[red,fill=blue!20, thick] (A) to[out=Aout, in=Bin] (B)
arc(180-mybeta:180:rlarge) arc(0:myalpha:rsmall) -- cycle;
endtikzpicture
enddocument
You only need to add a [reverse]
to one of the segments.
documentclass[margin=10pt]standalone
usepackagetikz
usepackagepgfplots
pgfplotssetcompat=newest
usepgfplotslibraryfillbetween
usetikzlibraryintersections
begindocument
begintikzpicture%[x=1cm, y=1cm]
defrsmall2
defrlarge4
defalpha60
defbeta40
defgamma20
defAoutalpha+gamma-90
defBin270-beta-gamma
pgfmathsetmacroax-rsmall+cos(alpha)*rsmall
pgfmathsetmacroaysin(alpha)*rsmall
pgfmathsetmacrobxrlarge-cos(beta)*rlarge
pgfmathsetmacrobysin(beta)*rlarge
filldraw[name path=arcs, fill=gray!20, thick]
(180:2*rsmall) arc (180:0:rsmall) arc (180:0:rlarge);
coordinate (A) at (ax, ay);
coordinate (B) at (bx, by);
draw[name path=unduloid, thick] (A) to[out=Aout, in=Bin] (B);
path[%draw=red,thick,
fill=blue!20,intersection segments=of=unduloid and arcs,sequence=L2--R2[reverse]];
endtikzpicture
enddocument
How can one debug this? Just draw curves with arrows on the segments in question. Here one would add
draw[red,thick,-latex,
intersection segments=of=unduloid and arcs,sequence=L2];
draw[blue,thick,-latex,
intersection segments=of=unduloid and arcs,sequence=R2];
and then get
This means that the paths start and end at the same points. To fix this, i.e. to produce a cycle, you have to run through one of the paths in the reverse
direction. If you don't, TikZ will close the path on its own by a straight line. That's why you got the straight line for one of the bounding curves.
ADDENDUM: In this situation you do not really need all the segments nor the fillbetween
library. Personally I would also refrain from redefining alpha
, beta
etc. since you may need these Greek symbols.
documentclass[margin=10pt]standalone
usepackagetikz
usetikzlibrarycalc
begindocument
begintikzpicture%[x=1cm, y=1cm]
defrsmall2
defrlarge4
defmyalpha60
defmybeta40
defgamma20
defAoutmyalpha+gamma-90
defBin270-mybeta-gamma
filldraw[fill=gray!20, thick]
(180:2*rsmall) arc (180:0:rsmall) arc (180:0:rlarge);
coordinate (A) at ($(-rsmall,0)+(myalpha:rsmall)$);
coordinate (B) at ($(rlarge,0)+(180-mybeta:rlarge)$);
draw[red,fill=blue!20, thick] (A) to[out=Aout, in=Bin] (B)
arc(180-mybeta:180:rlarge) arc(0:myalpha:rsmall) -- cycle;
endtikzpicture
enddocument
edited Aug 23 at 4:03
answered Aug 23 at 3:36
marmot
55.4k460121
55.4k460121
add a comment |Â
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f447265%2ffill-the-area-between-two-curves%23new-answer', 'question_page');
);
Post as a guest
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
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
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