我准备了一个代码,其中有两个圆圈。我想用相同的颜色填充它们之间的空间。这是我的代码
\documentclass{standalone}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{color}
\usepackage{tikz,pgfplots}
\usepackage{graphicx}
\begin{document}
\begin{tikzpicture}
\pgfmathdeclarerandomlist{color}{{red}{black}}
\foreach \a in {1,...,90}{
\pgfmathrandominteger{\x}{0}{50}
\pgfmathrandominteger{\y}{0}{50}
\pgfmathrandominteger{\r}{3}{3}
\pgfmathrandomitem{\c}{color}
\pgfpathcircle{
\pgfpoint{\x }{\y }}{\r mm}
\color{\c!70!white}
\pgfsetstrokecolor{\c!20!black}
\pgfusepath{stroke, fill}
}
% shape of the nucleus
\fill[opacity=0.15,rotate=30] (0,0) ellipse (4 and 3);
% field around the nucleus
\fill[opacity=0.15,color=blue] (0.8,0.8) circle (1.7);
% the single neutron or proton
\fill[black] (-1.5,-1.5) circle (0.3);
\fill[red] (-1.5,-1.2) arc (90:-90:0.3);
% field around the single particle
\fill[opacity=0.15,color=blue] (-1.5,-1.5) circle (0.7);
\end{tikzpicture}
\end{document}
这段代码的结果是
但我想要的是
我该怎么做?
答案1
为此,我将使用库tangent cs
中自带的背景和。calc
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{backgrounds,calc}
\begin{document}
\begin{tikzpicture}
\pgfmathdeclarerandomlist{color}{{red}{black}}
\foreach \a in {1,...,90}{
\pgfmathrandominteger{\x}{0}{50}
\pgfmathrandominteger{\y}{0}{50}
\pgfmathrandominteger{\r}{3}{3}
\pgfmathrandomitem{\c}{color}
\pgfpathcircle{
\pgfpoint{\x }{\y }}{\r mm}
\color{\c!70!white}
\pgfsetstrokecolor{\c!20!black}
\pgfusepath{stroke, fill}
}
\begin{scope}[on background layer]
% shape of the nucleus
\fill[white!85!black,rotate=30] (0,0) ellipse (4 and 3);
% field around the nucleus
\node[circle,fill=blue!15,minimum size=3.4cm] (A) at (0.8,0.8) {};
% field around the single particle
\node[circle,fill=blue!15,minimum size=1.4cm] (B) at (-1.5,-1.5){};
\fill[fill=blue!15] (tangent cs:node=A,point={(B.center)},solution=1)
to[bend right=25] (tangent cs:node=B,point={(A.center)},solution=2)
-- (tangent cs:node=B,point={(A.center)},solution=1) to[bend right=25]
(tangent cs:node=A,point={(B.center)},solution=2) --
cycle;
% the single neutron or proton
\fill[black] (-1.5,-1.5) circle (0.3);
\fill[red] (-1.5,-1.2) arc (90:-90:0.3);
\end{scope}
\end{tikzpicture}
\end{document}
保持不透明度的第二种可能性是使用transparency group
。
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\pgfmathdeclarerandomlist{color}{{red}{black}}
\foreach \a in {1,...,90}{
\pgfmathrandominteger{\x}{0}{50}
\pgfmathrandominteger{\y}{0}{50}
\pgfmathrandominteger{\r}{3}{3}
\pgfmathrandomitem{\c}{color}
\pgfpathcircle{
\pgfpoint{\x }{\y }}{\r mm}
\color{\c!70!white}
\pgfsetstrokecolor{\c!20!black}
\pgfusepath{stroke, fill}
}
% shape of the nucleus
\fill[opacity=0.15,rotate=30] (0,0) ellipse (4 and 3);
% the single neutron or proton
\fill[black] (-1.5,-1.5) circle (0.3);
\fill[red] (-1.5,-1.2) arc (90:-90:0.3);
\begin{scope}[transparency group,opacity=0.15]
% field around the nucleus
\node[circle,fill=blue,minimum size=3.4cm] (A) at (0.8,0.8) {};
% field around the single particle
\node[circle,fill=blue,minimum size=1.4cm] (B) at (-1.5,-1.5){};
\fill[blue] (tangent cs:node=A,point={(B.center)},solution=1)
to[bend right=25] (tangent cs:node=B,point={(A.center)},solution=2)
-- (tangent cs:node=B,point={(A.center)},solution=1) to[bend right=25]
(tangent cs:node=A,point={(B.center)},solution=2) -- cycle;
\end{scope}
\end{tikzpicture}
\end{document}