How to stop overlap between different circles randomly generated
Clash Royale CLAN TAG#URR8PPP
This question is similar to this question tikz: Distribute evenly and randomly circles (which is also where I got some of the code for this TiKz picture) but is different. I wish to draw multiple circles that do not overlap but some of these circles are different. Currently this is my code:
documentclassarticle
usepackagetikz
usepackage[margin=0.5in]geometry
newcommandfillrandomly[5]
xdefxlist4
xdefylist4
pgfmathsetmacrodiametersqr(#3*2)^2
foreach i in 1,...,#4
foreach k in 1,...,20
pgfmathsetmacroxrnd*#1
pgfmathsetmacroyrnd*#2
xdefcollision0
foreach element [count=i] in xlist
pgfmathtruncatemacroji-1
pgfmathsetmacrocheckdistancesqr ( (xlist[j]-(x))^2 + (ylist[j]-(y))^2 )
ifdimcheckdistancesqr pt<diametersqr pt
xdefcollision1
breakforeach
fi
ifnumcollision=0
xdefxlistxlist,x
xdefylistylist,y
draw (x,y) circle [radius=#3] node[anchor=center] #5;
breakforeach
fi
begindocument
beginfigure
begintikzpicture
beginscope[xshift=0.2cm,yshift=0.2cm]
fillrandomly3.63.80.1512$-$
fillrandomly3.63.80.1512$+$
endscope
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) concentrated strong acid;
beginscope[xshift=5cm]
foreach X in 1,...,3
draw (2+1.8*rand,2+1.9*rand) circle (0.15) node[anchor=center] $+$;
draw (2+1.8*rand,2+1.9*rand) circle (0.15) node[anchor=center] $-$;
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) dilute strong acid;
endscope
beginscope[xshift=10cm]
beginscope[xshift=0.2cm,yshift=0.2cm]
fillrandomly3.63.80.158$-$
fillrandomly3.63.80.158$+$
endscope
foreach X in 1,...,8
draw[fill=black!10] (2+1.8*rand,2+1.9*rand) circle (0.15);
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) concentrated weak acid;
endscope
beginscope[xshift=15cm]
foreach X in 1,...,2
draw (2+1.8*rand,2+1.9*rand) circle (0.15) node[anchor=center] $+$;
draw (2+1.8*rand,2+1.9*rand) circle (0.15) node[anchor=center] $-$;
draw[fill=black!10] (2+1.8*rand,2+1.9*rand) circle (0.15);
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) dilute weak acid;
endscope
draw[fill=black!10] (0,-1) circle (0.15) node[right=0.1cm] Unionised;
draw (0,-1.5) circle (0.15) node[anchor=center] $+$ node[right=0.1cm] Positive Ion;
draw (0,-2) circle (0.15) node[anchor=center] $-$ node[right=0.1cm] Negative Ion;
endtikzpicture
vspace-2cm
captionConcentrated and dilute solutions of weak and strong acids
endfigure
enddocument
Which produces this image:
I am unsure how to stop overlapping between the three different types of circles especially in the first and third beaker counting from the left. XeLaTeX answer please
tikz-pgf
add a comment |
This question is similar to this question tikz: Distribute evenly and randomly circles (which is also where I got some of the code for this TiKz picture) but is different. I wish to draw multiple circles that do not overlap but some of these circles are different. Currently this is my code:
documentclassarticle
usepackagetikz
usepackage[margin=0.5in]geometry
newcommandfillrandomly[5]
xdefxlist4
xdefylist4
pgfmathsetmacrodiametersqr(#3*2)^2
foreach i in 1,...,#4
foreach k in 1,...,20
pgfmathsetmacroxrnd*#1
pgfmathsetmacroyrnd*#2
xdefcollision0
foreach element [count=i] in xlist
pgfmathtruncatemacroji-1
pgfmathsetmacrocheckdistancesqr ( (xlist[j]-(x))^2 + (ylist[j]-(y))^2 )
ifdimcheckdistancesqr pt<diametersqr pt
xdefcollision1
breakforeach
fi
ifnumcollision=0
xdefxlistxlist,x
xdefylistylist,y
draw (x,y) circle [radius=#3] node[anchor=center] #5;
breakforeach
fi
begindocument
beginfigure
begintikzpicture
beginscope[xshift=0.2cm,yshift=0.2cm]
fillrandomly3.63.80.1512$-$
fillrandomly3.63.80.1512$+$
endscope
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) concentrated strong acid;
beginscope[xshift=5cm]
foreach X in 1,...,3
draw (2+1.8*rand,2+1.9*rand) circle (0.15) node[anchor=center] $+$;
draw (2+1.8*rand,2+1.9*rand) circle (0.15) node[anchor=center] $-$;
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) dilute strong acid;
endscope
beginscope[xshift=10cm]
beginscope[xshift=0.2cm,yshift=0.2cm]
fillrandomly3.63.80.158$-$
fillrandomly3.63.80.158$+$
endscope
foreach X in 1,...,8
draw[fill=black!10] (2+1.8*rand,2+1.9*rand) circle (0.15);
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) concentrated weak acid;
endscope
beginscope[xshift=15cm]
foreach X in 1,...,2
draw (2+1.8*rand,2+1.9*rand) circle (0.15) node[anchor=center] $+$;
draw (2+1.8*rand,2+1.9*rand) circle (0.15) node[anchor=center] $-$;
draw[fill=black!10] (2+1.8*rand,2+1.9*rand) circle (0.15);
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) dilute weak acid;
endscope
draw[fill=black!10] (0,-1) circle (0.15) node[right=0.1cm] Unionised;
draw (0,-1.5) circle (0.15) node[anchor=center] $+$ node[right=0.1cm] Positive Ion;
draw (0,-2) circle (0.15) node[anchor=center] $-$ node[right=0.1cm] Negative Ion;
endtikzpicture
vspace-2cm
captionConcentrated and dilute solutions of weak and strong acids
endfigure
enddocument
Which produces this image:
I am unsure how to stop overlapping between the three different types of circles especially in the first and third beaker counting from the left. XeLaTeX answer please
tikz-pgf
Lualatex ok?...
– JPi
Dec 16 at 12:23
Sorry I prefer XeLaTeX, forgot to mention
– sab hoque
Dec 16 at 12:23
add a comment |
This question is similar to this question tikz: Distribute evenly and randomly circles (which is also where I got some of the code for this TiKz picture) but is different. I wish to draw multiple circles that do not overlap but some of these circles are different. Currently this is my code:
documentclassarticle
usepackagetikz
usepackage[margin=0.5in]geometry
newcommandfillrandomly[5]
xdefxlist4
xdefylist4
pgfmathsetmacrodiametersqr(#3*2)^2
foreach i in 1,...,#4
foreach k in 1,...,20
pgfmathsetmacroxrnd*#1
pgfmathsetmacroyrnd*#2
xdefcollision0
foreach element [count=i] in xlist
pgfmathtruncatemacroji-1
pgfmathsetmacrocheckdistancesqr ( (xlist[j]-(x))^2 + (ylist[j]-(y))^2 )
ifdimcheckdistancesqr pt<diametersqr pt
xdefcollision1
breakforeach
fi
ifnumcollision=0
xdefxlistxlist,x
xdefylistylist,y
draw (x,y) circle [radius=#3] node[anchor=center] #5;
breakforeach
fi
begindocument
beginfigure
begintikzpicture
beginscope[xshift=0.2cm,yshift=0.2cm]
fillrandomly3.63.80.1512$-$
fillrandomly3.63.80.1512$+$
endscope
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) concentrated strong acid;
beginscope[xshift=5cm]
foreach X in 1,...,3
draw (2+1.8*rand,2+1.9*rand) circle (0.15) node[anchor=center] $+$;
draw (2+1.8*rand,2+1.9*rand) circle (0.15) node[anchor=center] $-$;
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) dilute strong acid;
endscope
beginscope[xshift=10cm]
beginscope[xshift=0.2cm,yshift=0.2cm]
fillrandomly3.63.80.158$-$
fillrandomly3.63.80.158$+$
endscope
foreach X in 1,...,8
draw[fill=black!10] (2+1.8*rand,2+1.9*rand) circle (0.15);
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) concentrated weak acid;
endscope
beginscope[xshift=15cm]
foreach X in 1,...,2
draw (2+1.8*rand,2+1.9*rand) circle (0.15) node[anchor=center] $+$;
draw (2+1.8*rand,2+1.9*rand) circle (0.15) node[anchor=center] $-$;
draw[fill=black!10] (2+1.8*rand,2+1.9*rand) circle (0.15);
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) dilute weak acid;
endscope
draw[fill=black!10] (0,-1) circle (0.15) node[right=0.1cm] Unionised;
draw (0,-1.5) circle (0.15) node[anchor=center] $+$ node[right=0.1cm] Positive Ion;
draw (0,-2) circle (0.15) node[anchor=center] $-$ node[right=0.1cm] Negative Ion;
endtikzpicture
vspace-2cm
captionConcentrated and dilute solutions of weak and strong acids
endfigure
enddocument
Which produces this image:
I am unsure how to stop overlapping between the three different types of circles especially in the first and third beaker counting from the left. XeLaTeX answer please
tikz-pgf
This question is similar to this question tikz: Distribute evenly and randomly circles (which is also where I got some of the code for this TiKz picture) but is different. I wish to draw multiple circles that do not overlap but some of these circles are different. Currently this is my code:
documentclassarticle
usepackagetikz
usepackage[margin=0.5in]geometry
newcommandfillrandomly[5]
xdefxlist4
xdefylist4
pgfmathsetmacrodiametersqr(#3*2)^2
foreach i in 1,...,#4
foreach k in 1,...,20
pgfmathsetmacroxrnd*#1
pgfmathsetmacroyrnd*#2
xdefcollision0
foreach element [count=i] in xlist
pgfmathtruncatemacroji-1
pgfmathsetmacrocheckdistancesqr ( (xlist[j]-(x))^2 + (ylist[j]-(y))^2 )
ifdimcheckdistancesqr pt<diametersqr pt
xdefcollision1
breakforeach
fi
ifnumcollision=0
xdefxlistxlist,x
xdefylistylist,y
draw (x,y) circle [radius=#3] node[anchor=center] #5;
breakforeach
fi
begindocument
beginfigure
begintikzpicture
beginscope[xshift=0.2cm,yshift=0.2cm]
fillrandomly3.63.80.1512$-$
fillrandomly3.63.80.1512$+$
endscope
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) concentrated strong acid;
beginscope[xshift=5cm]
foreach X in 1,...,3
draw (2+1.8*rand,2+1.9*rand) circle (0.15) node[anchor=center] $+$;
draw (2+1.8*rand,2+1.9*rand) circle (0.15) node[anchor=center] $-$;
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) dilute strong acid;
endscope
beginscope[xshift=10cm]
beginscope[xshift=0.2cm,yshift=0.2cm]
fillrandomly3.63.80.158$-$
fillrandomly3.63.80.158$+$
endscope
foreach X in 1,...,8
draw[fill=black!10] (2+1.8*rand,2+1.9*rand) circle (0.15);
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) concentrated weak acid;
endscope
beginscope[xshift=15cm]
foreach X in 1,...,2
draw (2+1.8*rand,2+1.9*rand) circle (0.15) node[anchor=center] $+$;
draw (2+1.8*rand,2+1.9*rand) circle (0.15) node[anchor=center] $-$;
draw[fill=black!10] (2+1.8*rand,2+1.9*rand) circle (0.15);
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) dilute weak acid;
endscope
draw[fill=black!10] (0,-1) circle (0.15) node[right=0.1cm] Unionised;
draw (0,-1.5) circle (0.15) node[anchor=center] $+$ node[right=0.1cm] Positive Ion;
draw (0,-2) circle (0.15) node[anchor=center] $-$ node[right=0.1cm] Negative Ion;
endtikzpicture
vspace-2cm
captionConcentrated and dilute solutions of weak and strong acids
endfigure
enddocument
Which produces this image:
I am unsure how to stop overlapping between the three different types of circles especially in the first and third beaker counting from the left. XeLaTeX answer please
tikz-pgf
tikz-pgf
edited Dec 16 at 12:26
asked Dec 16 at 12:07
sab hoque
1,255318
1,255318
Lualatex ok?...
– JPi
Dec 16 at 12:23
Sorry I prefer XeLaTeX, forgot to mention
– sab hoque
Dec 16 at 12:23
add a comment |
Lualatex ok?...
– JPi
Dec 16 at 12:23
Sorry I prefer XeLaTeX, forgot to mention
– sab hoque
Dec 16 at 12:23
Lualatex ok?...
– JPi
Dec 16 at 12:23
Lualatex ok?...
– JPi
Dec 16 at 12:23
Sorry I prefer XeLaTeX, forgot to mention
– sab hoque
Dec 16 at 12:23
Sorry I prefer XeLaTeX, forgot to mention
– sab hoque
Dec 16 at 12:23
add a comment |
1 Answer
1
active
oldest
votes
It is clear why this happens: you draw two or more independent samples, so if you say e.g.
fillrandomly3.63.80.1512$-$
fillrandomly3.63.80.1512$+$
the + ions do not know about the - ones. But it is very simple to fix it. Just make the reset of the collision list not part of the fillrandomly
, but do it whenever you start a new group. That is, I redefined fillrandomly
such that it does not reset the collision list, and added a command resetlists
that issues the reset. I also defined an ion
style that gets changed along the way such that one can add the filled ions.
documentclassarticle
usepackagetikz
usepackage[margin=0.5in]geometry
newcommandresetlistsxdefxlist4xdefylist4
newcommandfillrandomly[5]
pgfmathsetmacrodiametersqr(#3*2)^2
foreach i in 1,...,#4
foreach k in 1,...,20
pgfmathsetmacroxrnd*#1
pgfmathsetmacroyrnd*#2
xdefcollision0
foreach element [count=i] in xlist
pgfmathtruncatemacroji-1
pgfmathsetmacrocheckdistancesqr ( (xlist[j]-(x))^2 + (ylist[j]-(y))^2 )
ifdimcheckdistancesqr pt<diametersqr pt
xdefcollision1
breakforeach
fi
ifnumcollision=0
xdefxlistxlist,x
xdefylistylist,y
draw[ion] (x,y) circle [radius=#3] node[anchor=center] #5;
breakforeach
fi
begindocument
beginfigure
begintikzpicture
beginscope[xshift=0.2cm,yshift=0.2cm]
resetlists
tikzsetion/.style=
fillrandomly3.63.80.1512$-$
fillrandomly3.63.80.1512$+$
endscope
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) concentrated strong acid;
% 2
beginscope[xshift=5cm]
foreach X in 1,...,3
draw (2+1.8*rand,2+1.9*rand) circle (0.15) node[anchor=center] $+$;
draw (2+1.8*rand,2+1.9*rand) circle (0.15) node[anchor=center] $-$;
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) dilute strong acid;
endscope
% 3
beginscope[xshift=10cm]
beginscope[xshift=0.2cm,yshift=0.2cm]
resetlists
tikzsetion/.style=
fillrandomly3.63.80.158$-$
fillrandomly3.63.80.158$+$
tikzsetion/.style=fill=black!10
fillrandomly3.63.80.158
endscope
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) concentrated weak acid;
endscope
%4
beginscope[xshift=15cm]
beginscope[xshift=0.2cm,yshift=0.2cm]
resetlists
tikzsetion/.style=
fillrandomly3.63.80.152$-$
fillrandomly3.63.80.152$+$
tikzsetion/.style=fill=black!10
fillrandomly3.63.80.151
endscope
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) dilute weak acid;
endscope
draw[fill=black!10] (0,-1) circle (0.15) node[right=0.1cm] Unionised;
draw (0,-1.5) circle (0.15) node[anchor=center] $+$ node[right=0.1cm] Positive Ion;
draw (0,-2) circle (0.15) node[anchor=center] $-$ node[right=0.1cm] Negative Ion;
endtikzpicture
vspace-2cm
captionConcentrated and dilute solutions of weak and strong acids
endfigure
enddocument
I may have misunderstood something, but is the only thing that was changed was the addition of an ion style. I can't see where the cahnge was made to prevent the resetting of the list? I like to understand the code before I use it
– sab hoque
Dec 16 at 14:04
2
@sabhoque No, the original code hasxdefxlist4xdefylist4
part offillrandomly
. This resets the collision list, i.e. the list of previous positions of ions. Whenever a new ion is placed,fillrandomly
checks if the would-be ion overlaps with one of the previous ones. If not, the ion is drawn. All I did was not to reset the list automatically. So in the first example the+
ions also know where the-
ions were. I only reset the list when I switch to the next container. Theion
style allows you to draw the shaded circles withfillrandomly
, too.
– marmot
Dec 16 at 14:09
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%2f466069%2fhow-to-stop-overlap-between-different-circles-randomly-generated%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
It is clear why this happens: you draw two or more independent samples, so if you say e.g.
fillrandomly3.63.80.1512$-$
fillrandomly3.63.80.1512$+$
the + ions do not know about the - ones. But it is very simple to fix it. Just make the reset of the collision list not part of the fillrandomly
, but do it whenever you start a new group. That is, I redefined fillrandomly
such that it does not reset the collision list, and added a command resetlists
that issues the reset. I also defined an ion
style that gets changed along the way such that one can add the filled ions.
documentclassarticle
usepackagetikz
usepackage[margin=0.5in]geometry
newcommandresetlistsxdefxlist4xdefylist4
newcommandfillrandomly[5]
pgfmathsetmacrodiametersqr(#3*2)^2
foreach i in 1,...,#4
foreach k in 1,...,20
pgfmathsetmacroxrnd*#1
pgfmathsetmacroyrnd*#2
xdefcollision0
foreach element [count=i] in xlist
pgfmathtruncatemacroji-1
pgfmathsetmacrocheckdistancesqr ( (xlist[j]-(x))^2 + (ylist[j]-(y))^2 )
ifdimcheckdistancesqr pt<diametersqr pt
xdefcollision1
breakforeach
fi
ifnumcollision=0
xdefxlistxlist,x
xdefylistylist,y
draw[ion] (x,y) circle [radius=#3] node[anchor=center] #5;
breakforeach
fi
begindocument
beginfigure
begintikzpicture
beginscope[xshift=0.2cm,yshift=0.2cm]
resetlists
tikzsetion/.style=
fillrandomly3.63.80.1512$-$
fillrandomly3.63.80.1512$+$
endscope
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) concentrated strong acid;
% 2
beginscope[xshift=5cm]
foreach X in 1,...,3
draw (2+1.8*rand,2+1.9*rand) circle (0.15) node[anchor=center] $+$;
draw (2+1.8*rand,2+1.9*rand) circle (0.15) node[anchor=center] $-$;
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) dilute strong acid;
endscope
% 3
beginscope[xshift=10cm]
beginscope[xshift=0.2cm,yshift=0.2cm]
resetlists
tikzsetion/.style=
fillrandomly3.63.80.158$-$
fillrandomly3.63.80.158$+$
tikzsetion/.style=fill=black!10
fillrandomly3.63.80.158
endscope
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) concentrated weak acid;
endscope
%4
beginscope[xshift=15cm]
beginscope[xshift=0.2cm,yshift=0.2cm]
resetlists
tikzsetion/.style=
fillrandomly3.63.80.152$-$
fillrandomly3.63.80.152$+$
tikzsetion/.style=fill=black!10
fillrandomly3.63.80.151
endscope
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) dilute weak acid;
endscope
draw[fill=black!10] (0,-1) circle (0.15) node[right=0.1cm] Unionised;
draw (0,-1.5) circle (0.15) node[anchor=center] $+$ node[right=0.1cm] Positive Ion;
draw (0,-2) circle (0.15) node[anchor=center] $-$ node[right=0.1cm] Negative Ion;
endtikzpicture
vspace-2cm
captionConcentrated and dilute solutions of weak and strong acids
endfigure
enddocument
I may have misunderstood something, but is the only thing that was changed was the addition of an ion style. I can't see where the cahnge was made to prevent the resetting of the list? I like to understand the code before I use it
– sab hoque
Dec 16 at 14:04
2
@sabhoque No, the original code hasxdefxlist4xdefylist4
part offillrandomly
. This resets the collision list, i.e. the list of previous positions of ions. Whenever a new ion is placed,fillrandomly
checks if the would-be ion overlaps with one of the previous ones. If not, the ion is drawn. All I did was not to reset the list automatically. So in the first example the+
ions also know where the-
ions were. I only reset the list when I switch to the next container. Theion
style allows you to draw the shaded circles withfillrandomly
, too.
– marmot
Dec 16 at 14:09
add a comment |
It is clear why this happens: you draw two or more independent samples, so if you say e.g.
fillrandomly3.63.80.1512$-$
fillrandomly3.63.80.1512$+$
the + ions do not know about the - ones. But it is very simple to fix it. Just make the reset of the collision list not part of the fillrandomly
, but do it whenever you start a new group. That is, I redefined fillrandomly
such that it does not reset the collision list, and added a command resetlists
that issues the reset. I also defined an ion
style that gets changed along the way such that one can add the filled ions.
documentclassarticle
usepackagetikz
usepackage[margin=0.5in]geometry
newcommandresetlistsxdefxlist4xdefylist4
newcommandfillrandomly[5]
pgfmathsetmacrodiametersqr(#3*2)^2
foreach i in 1,...,#4
foreach k in 1,...,20
pgfmathsetmacroxrnd*#1
pgfmathsetmacroyrnd*#2
xdefcollision0
foreach element [count=i] in xlist
pgfmathtruncatemacroji-1
pgfmathsetmacrocheckdistancesqr ( (xlist[j]-(x))^2 + (ylist[j]-(y))^2 )
ifdimcheckdistancesqr pt<diametersqr pt
xdefcollision1
breakforeach
fi
ifnumcollision=0
xdefxlistxlist,x
xdefylistylist,y
draw[ion] (x,y) circle [radius=#3] node[anchor=center] #5;
breakforeach
fi
begindocument
beginfigure
begintikzpicture
beginscope[xshift=0.2cm,yshift=0.2cm]
resetlists
tikzsetion/.style=
fillrandomly3.63.80.1512$-$
fillrandomly3.63.80.1512$+$
endscope
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) concentrated strong acid;
% 2
beginscope[xshift=5cm]
foreach X in 1,...,3
draw (2+1.8*rand,2+1.9*rand) circle (0.15) node[anchor=center] $+$;
draw (2+1.8*rand,2+1.9*rand) circle (0.15) node[anchor=center] $-$;
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) dilute strong acid;
endscope
% 3
beginscope[xshift=10cm]
beginscope[xshift=0.2cm,yshift=0.2cm]
resetlists
tikzsetion/.style=
fillrandomly3.63.80.158$-$
fillrandomly3.63.80.158$+$
tikzsetion/.style=fill=black!10
fillrandomly3.63.80.158
endscope
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) concentrated weak acid;
endscope
%4
beginscope[xshift=15cm]
beginscope[xshift=0.2cm,yshift=0.2cm]
resetlists
tikzsetion/.style=
fillrandomly3.63.80.152$-$
fillrandomly3.63.80.152$+$
tikzsetion/.style=fill=black!10
fillrandomly3.63.80.151
endscope
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) dilute weak acid;
endscope
draw[fill=black!10] (0,-1) circle (0.15) node[right=0.1cm] Unionised;
draw (0,-1.5) circle (0.15) node[anchor=center] $+$ node[right=0.1cm] Positive Ion;
draw (0,-2) circle (0.15) node[anchor=center] $-$ node[right=0.1cm] Negative Ion;
endtikzpicture
vspace-2cm
captionConcentrated and dilute solutions of weak and strong acids
endfigure
enddocument
I may have misunderstood something, but is the only thing that was changed was the addition of an ion style. I can't see where the cahnge was made to prevent the resetting of the list? I like to understand the code before I use it
– sab hoque
Dec 16 at 14:04
2
@sabhoque No, the original code hasxdefxlist4xdefylist4
part offillrandomly
. This resets the collision list, i.e. the list of previous positions of ions. Whenever a new ion is placed,fillrandomly
checks if the would-be ion overlaps with one of the previous ones. If not, the ion is drawn. All I did was not to reset the list automatically. So in the first example the+
ions also know where the-
ions were. I only reset the list when I switch to the next container. Theion
style allows you to draw the shaded circles withfillrandomly
, too.
– marmot
Dec 16 at 14:09
add a comment |
It is clear why this happens: you draw two or more independent samples, so if you say e.g.
fillrandomly3.63.80.1512$-$
fillrandomly3.63.80.1512$+$
the + ions do not know about the - ones. But it is very simple to fix it. Just make the reset of the collision list not part of the fillrandomly
, but do it whenever you start a new group. That is, I redefined fillrandomly
such that it does not reset the collision list, and added a command resetlists
that issues the reset. I also defined an ion
style that gets changed along the way such that one can add the filled ions.
documentclassarticle
usepackagetikz
usepackage[margin=0.5in]geometry
newcommandresetlistsxdefxlist4xdefylist4
newcommandfillrandomly[5]
pgfmathsetmacrodiametersqr(#3*2)^2
foreach i in 1,...,#4
foreach k in 1,...,20
pgfmathsetmacroxrnd*#1
pgfmathsetmacroyrnd*#2
xdefcollision0
foreach element [count=i] in xlist
pgfmathtruncatemacroji-1
pgfmathsetmacrocheckdistancesqr ( (xlist[j]-(x))^2 + (ylist[j]-(y))^2 )
ifdimcheckdistancesqr pt<diametersqr pt
xdefcollision1
breakforeach
fi
ifnumcollision=0
xdefxlistxlist,x
xdefylistylist,y
draw[ion] (x,y) circle [radius=#3] node[anchor=center] #5;
breakforeach
fi
begindocument
beginfigure
begintikzpicture
beginscope[xshift=0.2cm,yshift=0.2cm]
resetlists
tikzsetion/.style=
fillrandomly3.63.80.1512$-$
fillrandomly3.63.80.1512$+$
endscope
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) concentrated strong acid;
% 2
beginscope[xshift=5cm]
foreach X in 1,...,3
draw (2+1.8*rand,2+1.9*rand) circle (0.15) node[anchor=center] $+$;
draw (2+1.8*rand,2+1.9*rand) circle (0.15) node[anchor=center] $-$;
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) dilute strong acid;
endscope
% 3
beginscope[xshift=10cm]
beginscope[xshift=0.2cm,yshift=0.2cm]
resetlists
tikzsetion/.style=
fillrandomly3.63.80.158$-$
fillrandomly3.63.80.158$+$
tikzsetion/.style=fill=black!10
fillrandomly3.63.80.158
endscope
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) concentrated weak acid;
endscope
%4
beginscope[xshift=15cm]
beginscope[xshift=0.2cm,yshift=0.2cm]
resetlists
tikzsetion/.style=
fillrandomly3.63.80.152$-$
fillrandomly3.63.80.152$+$
tikzsetion/.style=fill=black!10
fillrandomly3.63.80.151
endscope
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) dilute weak acid;
endscope
draw[fill=black!10] (0,-1) circle (0.15) node[right=0.1cm] Unionised;
draw (0,-1.5) circle (0.15) node[anchor=center] $+$ node[right=0.1cm] Positive Ion;
draw (0,-2) circle (0.15) node[anchor=center] $-$ node[right=0.1cm] Negative Ion;
endtikzpicture
vspace-2cm
captionConcentrated and dilute solutions of weak and strong acids
endfigure
enddocument
It is clear why this happens: you draw two or more independent samples, so if you say e.g.
fillrandomly3.63.80.1512$-$
fillrandomly3.63.80.1512$+$
the + ions do not know about the - ones. But it is very simple to fix it. Just make the reset of the collision list not part of the fillrandomly
, but do it whenever you start a new group. That is, I redefined fillrandomly
such that it does not reset the collision list, and added a command resetlists
that issues the reset. I also defined an ion
style that gets changed along the way such that one can add the filled ions.
documentclassarticle
usepackagetikz
usepackage[margin=0.5in]geometry
newcommandresetlistsxdefxlist4xdefylist4
newcommandfillrandomly[5]
pgfmathsetmacrodiametersqr(#3*2)^2
foreach i in 1,...,#4
foreach k in 1,...,20
pgfmathsetmacroxrnd*#1
pgfmathsetmacroyrnd*#2
xdefcollision0
foreach element [count=i] in xlist
pgfmathtruncatemacroji-1
pgfmathsetmacrocheckdistancesqr ( (xlist[j]-(x))^2 + (ylist[j]-(y))^2 )
ifdimcheckdistancesqr pt<diametersqr pt
xdefcollision1
breakforeach
fi
ifnumcollision=0
xdefxlistxlist,x
xdefylistylist,y
draw[ion] (x,y) circle [radius=#3] node[anchor=center] #5;
breakforeach
fi
begindocument
beginfigure
begintikzpicture
beginscope[xshift=0.2cm,yshift=0.2cm]
resetlists
tikzsetion/.style=
fillrandomly3.63.80.1512$-$
fillrandomly3.63.80.1512$+$
endscope
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) concentrated strong acid;
% 2
beginscope[xshift=5cm]
foreach X in 1,...,3
draw (2+1.8*rand,2+1.9*rand) circle (0.15) node[anchor=center] $+$;
draw (2+1.8*rand,2+1.9*rand) circle (0.15) node[anchor=center] $-$;
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) dilute strong acid;
endscope
% 3
beginscope[xshift=10cm]
beginscope[xshift=0.2cm,yshift=0.2cm]
resetlists
tikzsetion/.style=
fillrandomly3.63.80.158$-$
fillrandomly3.63.80.158$+$
tikzsetion/.style=fill=black!10
fillrandomly3.63.80.158
endscope
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) concentrated weak acid;
endscope
%4
beginscope[xshift=15cm]
beginscope[xshift=0.2cm,yshift=0.2cm]
resetlists
tikzsetion/.style=
fillrandomly3.63.80.152$-$
fillrandomly3.63.80.152$+$
tikzsetion/.style=fill=black!10
fillrandomly3.63.80.151
endscope
draw (0,5) -- (0,1);
draw (0,1) .. controls (0,0) and (0,0) .. (1,0);
draw (1,0) -- (3,0);
draw (3,0) .. controls (4,0) and (4,0) .. (4,1);
draw (4,1) -- (4,5);
draw[densely dashed] (0,5) .. controls (0,4.5) and (0,4.5) .. (0.5,4.5);
draw[densely dashed] (0.5,4.5) -- (3.5,4.5);
draw[densely dashed] (3.5,4.5) .. controls (4,4.5) and (4,4.5) .. (4,5);
node[anchor=center] at (2,-0.5) dilute weak acid;
endscope
draw[fill=black!10] (0,-1) circle (0.15) node[right=0.1cm] Unionised;
draw (0,-1.5) circle (0.15) node[anchor=center] $+$ node[right=0.1cm] Positive Ion;
draw (0,-2) circle (0.15) node[anchor=center] $-$ node[right=0.1cm] Negative Ion;
endtikzpicture
vspace-2cm
captionConcentrated and dilute solutions of weak and strong acids
endfigure
enddocument
answered Dec 16 at 13:20
marmot
86.3k499184
86.3k499184
I may have misunderstood something, but is the only thing that was changed was the addition of an ion style. I can't see where the cahnge was made to prevent the resetting of the list? I like to understand the code before I use it
– sab hoque
Dec 16 at 14:04
2
@sabhoque No, the original code hasxdefxlist4xdefylist4
part offillrandomly
. This resets the collision list, i.e. the list of previous positions of ions. Whenever a new ion is placed,fillrandomly
checks if the would-be ion overlaps with one of the previous ones. If not, the ion is drawn. All I did was not to reset the list automatically. So in the first example the+
ions also know where the-
ions were. I only reset the list when I switch to the next container. Theion
style allows you to draw the shaded circles withfillrandomly
, too.
– marmot
Dec 16 at 14:09
add a comment |
I may have misunderstood something, but is the only thing that was changed was the addition of an ion style. I can't see where the cahnge was made to prevent the resetting of the list? I like to understand the code before I use it
– sab hoque
Dec 16 at 14:04
2
@sabhoque No, the original code hasxdefxlist4xdefylist4
part offillrandomly
. This resets the collision list, i.e. the list of previous positions of ions. Whenever a new ion is placed,fillrandomly
checks if the would-be ion overlaps with one of the previous ones. If not, the ion is drawn. All I did was not to reset the list automatically. So in the first example the+
ions also know where the-
ions were. I only reset the list when I switch to the next container. Theion
style allows you to draw the shaded circles withfillrandomly
, too.
– marmot
Dec 16 at 14:09
I may have misunderstood something, but is the only thing that was changed was the addition of an ion style. I can't see where the cahnge was made to prevent the resetting of the list? I like to understand the code before I use it
– sab hoque
Dec 16 at 14:04
I may have misunderstood something, but is the only thing that was changed was the addition of an ion style. I can't see where the cahnge was made to prevent the resetting of the list? I like to understand the code before I use it
– sab hoque
Dec 16 at 14:04
2
2
@sabhoque No, the original code has
xdefxlist4xdefylist4
part of fillrandomly
. This resets the collision list, i.e. the list of previous positions of ions. Whenever a new ion is placed, fillrandomly
checks if the would-be ion overlaps with one of the previous ones. If not, the ion is drawn. All I did was not to reset the list automatically. So in the first example the +
ions also know where the -
ions were. I only reset the list when I switch to the next container. The ion
style allows you to draw the shaded circles with fillrandomly
, too.– marmot
Dec 16 at 14:09
@sabhoque No, the original code has
xdefxlist4xdefylist4
part of fillrandomly
. This resets the collision list, i.e. the list of previous positions of ions. Whenever a new ion is placed, fillrandomly
checks if the would-be ion overlaps with one of the previous ones. If not, the ion is drawn. All I did was not to reset the list automatically. So in the first example the +
ions also know where the -
ions were. I only reset the list when I switch to the next container. The ion
style allows you to draw the shaded circles with fillrandomly
, too.– marmot
Dec 16 at 14:09
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.
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.
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%2f466069%2fhow-to-stop-overlap-between-different-circles-randomly-generated%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
Lualatex ok?...
– JPi
Dec 16 at 12:23
Sorry I prefer XeLaTeX, forgot to mention
– sab hoque
Dec 16 at 12:23