MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Venn diagrams?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg118315] Re: Venn diagrams?
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Thu, 21 Apr 2011 03:12:06 -0400 (EDT)

It's just more of the same.

areaOverlap[r1_, r2_, d_] = 
  r2^2 * ArcCos[(d^2 + r2^2 - r1^2)/(2 d r2)] +
   r1^2 * ArcCos[(d^2 + r1^2 - r2^2)/(2 d r1)] -
   Sqrt[(-d + r2 + r1) (d + r2 - r1) (d - r2 + r1) (d + r2 + r1)]/2;


separation[r1_?Positive, r2_?Positive, overlap_?NonNegative] /;
   overlap <= (Min[r1, r2]^2 * Pi) :=
  Chop[d /. FindRoot[
      areaOverlap[r1, r2, d] == overlap, 
      {d, Max[r1, r2]}][[1]]];


venn[area1_?Positive, area2_?Positive, area3_?Positive, 
    overlap12_?NonNegative, overlap13_?NonNegative,
    overlap23_?NonNegative] /;
   (overlap12 <= Min[area1, area2] && 
     overlap13 <= Min[area1, area3] &&
     overlap23 <= Min[area2, area3]) :=
  Module[{d12, d13, d23, x, y,
    r1 = Sqrt[area1/Pi], r2 = Sqrt[area2/Pi], r3 = Sqrt[area3/Pi]},
   d12 = separation[r1, r2, overlap12];
   {x, y} = ({x, y} /. NSolve[{
         Norm[{x, y}] == separation[r1, r3, overlap13],
         Norm[{x, y} - {d12, 0}] == separation[r2, r3, overlap23]},
        {x, y}][[1]]);
   Graphics[{
     Red, Circle[{0, 0}, r1],
     Blue, Circle[{d12, 0}, r2],
     Green, Circle[{x, y}, r3]}]];


venn[25, 16, 9, 0, 0, 0]

venn[25, 16, 9, 4, 3, 1]

With[{c = Pi/3 - Sqrt[3]/2}, venn[Pi, Pi, Pi, c, c, c]]


Bob Hanlon

---- dantimatter <google at dantimatter.com> wrote: 

=============
Thanks DrMajorBob, Murray, and Bob Hanlon!  To the Bobs especially:  your math and coding chops are most impressive.  :)   

Any thoughts on extensions to three sets?  At first I had hoped that it would be straight-forward, but after fiddling a bit myself I'm not so sure.

I'm kinda surprised that Mathematica doesn't have this as a built-in function ....

Cheers
dan




  • Prev by Date: Re: Solve vs. nonlinearity
  • Next by Date: Printing "full version" or "publication version" of same notebook?
  • Previous by thread: Re: Venn diagrams?
  • Next by thread: Re: Venn diagrams?