Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #1814

Re: Venn diagrams?

From Bob Hanlon <hanlonr@cox.net>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Venn diagrams?
Date 2011-04-21 07:11 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <ioolbt$bqf$1@smc.vnet.net> (permalink)

Show all headers | View raw


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@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


Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: Venn diagrams? Bob Hanlon <hanlonr@cox.net> - 2011-04-21 07:11 +0000

csiph-web