Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Now I am looking if there is any easy way to create venn-diagrams where the circles/ellipses change size relative to its content. I am basically looking for simple compliments either on the form

[\img]http://i.stack.imgur.com/8Irn9.gif[img] or with three elements

The output I am looking for is somewhat along these lines enter image description here

Where the size of the circles are relative to their percentages or probability. (Larger circles, larger probability) and the largest circle represents 1 or 100%

Now is it possible creating a macro that allows one to create such images? Example, given that A=40 , B=60 , A \cap B = 20

share|improve this question
3  
In principle yes, but the math will be horrible –  Tom Bombadil Jul 9 '12 at 21:32
    
Horrible? You are speaking to a math undergrad ;) I am sure a solution can be aquired using the \calc package. –  N3buchadnezzar Jul 9 '12 at 21:45
    
Horrible. Try solving for d in equation (14) in mathworld.wolfram.com/Circle-CircleIntersection.html –  JLDiaz Jul 9 '12 at 22:10
    
I did, gave me 4 solutions. However latex was not able to interpret the input, I probably did something wrong. –  N3buchadnezzar Jul 9 '12 at 22:11
2  
Recommend that you consider using rectangles instead of circles. Because there are many combination which cannot be displayed with circles. eg Sample space=100 A=60, B=40, A \cap B =20; cannot be done with circles. Additionally the computations with rectangles will be trivial. –  R. Schumacher Jul 10 '12 at 3:07
show 7 more comments

1 Answer

The answer is "impossible". You can't draw circles with the requested values : A=.40 , B=.60 , A \cap B = .20 like R. Schumacher wrote.

enter image description here

\documentclass[11pt]{scrartcl} 
\usepackage[utf8]{inputenc}
\usepackage{fourier}
\usepackage{tikz,verbatim}
\usetikzlibrary{arrows,patterns}

\begin{document}

\begin{tikzpicture}[scale=4,>=latex']
  \draw[magenta] circle[radius=1cm]; 
  \node[above right,magenta] at (0,1) {$\mathcal{C}$};  
  \draw (0.63245-1,0) circle [radius=0.63245cm];   % sqrt(0.4) 
  \draw (1-0.77459,0) circle [radius=0.77459cm];   % sqrt(0.6)
  \node[above right] at (-1,0) {$\mathcal{C}_a$};
  \node[above left] at ( 1,0) {$\mathcal{C}_b$};
  \draw[->] (-1,0)--(1.2,0); 
  \draw[->] (0,-1)--(0,1.2);
  \filldraw[blue] (0.63245-1,0) circle(.4pt) -- node[above right]{$ra\approx 0.632$}++(60:0.63245); 
  \filldraw[blue] (1-0.77459,0) circle(.4pt) -- node[above right]{$rb\approx 0.774$}++(60:0.77459);
    \draw[magenta,<->] (0,0) -- node[below]{1} (1,0);  
   \clip (0.63245-1,0) circle [radius=0.63245cm];   % sqrt(0.4) 
   \clip (1-0.77459,0) circle [radius=0.77459cm];   % sqrt(0.6)
   \fill[pattern=north east lines,fill opacity=.5]  circle[radius=1cm];
   \draw[red,<->] (0.63245-1,-0.05) -- node[below]{0.59296} (1-0.77459,-0.05);

   \node at (-0.25,-0.4){$\mathcal{A}$};     
\end{tikzpicture}

\begin{verbatim}
Macro to determine the area of the asymmetric lens.
\pgfmathsetmacro{\ra}{sqrt(0.4)} 
\pgfmathsetmacro{\rb}{sqrt(0.6)}
\pgfmathsetmacro{\d}{2-0.63245-0.77459}    
\pgfmathsetmacro{\area}{%
   (  \ra*\ra*acos((\d*\d-\rb*\rb+\ra*\ra)/(2*\d*\ra))/180*3.1415     
     +\rb*\rb*acos((\d*\d+\rb*\rb-\ra*\ra)/(2*\d*\rb))/180*3.1415
     -0.5*sqrt((-\d+\ra+\rb)*(\d+\ra-\rb)*(\d-\ra+\rb)*(\d+\ra+\rb))
     )/3.1415}  
\end{verbatim} 

\pgfmathsetmacro{\d}{2-0.63245-0.77459} 
\pgfmathsetmacro{\ra}{sqrt(0.4)} 
\pgfmathsetmacro{\rb}{sqrt(0.6)}   
\pgfmathsetmacro{\area}{%
   (  \ra*\ra*acos((\d*\d-\rb*\rb+\ra*\ra)/(2*\d*\ra))/180*3.1415     
     +\rb*\rb*acos((\d*\d+\rb*\rb-\ra*\ra)/(2*\d*\rb))/180*3.1415
     -0.5*sqrt((-\d+\ra+\rb)*(\d+\ra-\rb)*(\d-\ra+\rb)*(\d+\ra+\rb))
     )/3.1415}  

The area of the circle $\mathcal{C}$  is $1\times \pi$.

The area of the circle $\mathcal{C}_a$  is $0.4\times \pi$.

The area of the circle $\mathcal{C}_b$  is $0.6\times \pi$.   

If $d=0.59296$  then $\mathcal{A}=\area\times \pi$.


\pgfmathsetmacro{\d}{0.681}
\pgfmathsetmacro{\area}{%
   (  \ra*\ra*acos((\d*\d-\rb*\rb+\ra*\ra)/(2*\d*\ra))/180*3.1415     
     +\rb*\rb*acos((\d*\d+\rb*\rb-\ra*\ra)/(2*\d*\rb))/180*3.1415
     -0.5*sqrt((-\d+\ra+\rb)*(\d+\ra-\rb)*(\d-\ra+\rb)*(\d+\ra+\rb))
     )/3.1415} 

If $d=0.681$  then $\mathcal{A}=\area\times \pi$ but  $0.59296$  is the maximum value of $d$, so it's impossible to draw circles with the requested values.

\end{document}   

For others values it's possible to use an iterative approach via nesting intervals (dichotomy) . I find 0.681 with a manual approach but I think it's not very difficult to build an algorithm to find this value.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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