4

I have prepared a code in which there are two circles. I want to fill the space between them with the same color. Here is my code

\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}

The result of this code is

enter image description here

but I want to have something like

enter image description here

How can I do it?

6

I would use backgrounds and tangent cs, which comes with the calc library, for that.

\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}

enter image description here

A second possibility, which keeps your opacity, is to use a 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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.