3

I would like to visualize the convolution of two 2D Gaussians (or something looking similar). To do this, I declare them in a tikzfadingfrompicture environment. However, to get the desired result and not a whole in the middle when the centres are too close to each other, I need to set the transparency range between transparent!50 and transparent!0, making the out-coming images very hard to see. Is there a way to increase the intensity? or rescale the transparency afterwards to make the images more black in this case?

MWE:

\documentclass[border=2mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest} 
\usepackage{tikz} 
\usetikzlibrary{fadings} 
\usetikzlibrary{shadings} 
\begin{document} 
\tikzfading[name=fade in, inner color=transparent!100, outer color=transparent!0]
\newcommand\DetFading[4]{ 
  % % 1+2: xy a, 3+4; xy coords b 
  \begin{tikzfadingfrompicture}[name=fadingpict] 
  \begin{scope} 
    \clip (#1,#2) circle(1.5cm); % clip away the non-overlapping parts 
    \clip (#3,#4) circle(1.5cm); 
    \fill [black,path fading=fade in] (#1,#2) circle(1.5cm); 
    \fill [black,path fading=fade in] (#3,#4) circle(1.5cm); 
  \end{scope} 
  \draw [draw=black,line width=2cm] (#1,#2) circle (2.4cm); % remove borders due to clipping 
  \draw [draw=black,line width=2cm] (#3,#4) circle (2.4cm);
\end{tikzfadingfrompicture} 
\node [fill=white,inner sep=0pt,outer sep=0pt,rotate=0,minimum width=3cm,minimum height=3cm] at (#1,#2) (textnode) {}; 
\shade[fill=black,path fading=fadingpict,fit fading=false,fading transform={xshift=#1,yshift=#2},rotate=0] (textnode.south west) rectangle (textnode.north east); } 

\tikzfading[name=fade in half, inner color=transparent!50, outer color=transparent!0] 
\newcommand\DetFadingHalf[4]{ % % 1+2: xy a, 3+4; xy coords b 
\begin{tikzfadingfrompicture}[name=fadingpict] 
    \begin{scope}  
      \clip (#1,#2) circle(1.5cm); % clip away the non-overlapping parts  
      \clip (#3,#4) circle(1.5cm);  
      \fill [black,path fading=fade in half] (#1,#2) circle(1.5cm);  
      \fill [black,path fading=fade in half] (#3,#4) circle(1.5cm);  
    \end{scope}  
    \draw [draw=black,line width=2cm] (#1,#2) circle (2.4cm); % remove borders due to clipping  
    \draw [draw=black,line width=2cm] (#3,#4) circle (2.4cm);  
  \end{tikzfadingfrompicture}  
  \node [fill=white,inner sep=0pt,outer sep=0pt,rotate=0,minimum width=3cm,minimum height=3cm] at (#1,#2) (textnode) {};  
  \shade[fill=black,path fading=fadingpict,fit fading=false,fading transform={xshift=#1,yshift=#2},rotate=0] (textnode.south west) rectangle (textnode.north east); }  
  \begin{tikzpicture}  
    \DetFading{0}{3cm}{1.5cm}{3cm}  
    \DetFading{0}{0cm}{0}{0cm}  
    \DetFadingHalf{3cm}{3cm}{4.5cm}{3cm}  
    \DetFadingHalf{3cm}{0}{3cm}{0} %\node at (3,4) {a};  
  \end{tikzpicture}  
  \end{document}

result:

enter image description here

pluton
  • 16,421
Heinrich
  • 123
  • Maybe a better approach would be to go with PGFPlots, adapting the answer from Draw a bivariate normal distribution in TikZ? You can turn the 3D example into 2D by setting view={0}{90}, shader=interp. – Jake Oct 16 '13 at 10:13
  • Thanks that is a very promising approach. Is it possible to put two of these distributions in different colors next to each other in an overlapping way (say, red and green so that where they overlap there is a yellow region)? Adding a second term to the function will result in the same color (as the same map applies). I tried putting two axes one above another but the white background renders the first graph invisible.. – Heinrich Oct 16 '13 at 11:26
  • @Heinrich pgfplots can draw surface plots in which the color is explicitly given as, say, RGB triple - and each R, G, B can be bound to the input of your plot. I might be pointing into the wrong direction, so just a question: If you could bind (say) "R" to the first distribution and "G" to the second (or some similar "manual" approach to map input to color components), would that help you? In that case, you could read the pgfplots manual, section "Surface Plots with Explicit Color" – Christian Feuersänger Oct 19 '13 at 16:41
  • Potentially related: http://tex.stackexchange.com/questions/60584/tikz-3d-library-and-circle-fading/60607#60607 – Christian Feuersänger Oct 20 '13 at 11:03

0 Answers0