MathGroup Archive 2011

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

Search the Archive

Re: Venn diagrams?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg118273] Re: Venn diagrams?
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Tue, 19 Apr 2011 06:58:07 -0400 (EDT)

This is 700 times faster at my machine:

Clear[area, d, r1, r2, venn]
area[r1_, r2_,
    d_] = -(1/2)
       Sqrt[(d + r1 - r2) (d - r1 + r2) (-d + r1 + r2) (d + r1 + r2)] +
     r1^2 ArcCos[(d^2 + r1^2 - r2^2)/(2 d r1)] +
    r2^2 ArcCos[(d^2 - r1^2 + r2^2)/(2 d r2)];
venn[area1_?Positive, area2_?Positive, overlap_?NonNegative] /;
   overlap <= Min[area1, area2] :=
  Module[{x2, r1 = Sqrt[area1/Pi], r2 = Sqrt[area2/Pi], d},
   d = Which[overlap == 0, r1 + r2,
     overlap == Min[area1, area2], r1 - r2,
     True, Chop[d /. FindRoot[area[r1, r2, d] == overlap, {d, r1}]]];
   Graphics[{Red, Circle[{0, 0}, r1], Blue, Circle[{d, 0}, r2]}]]
venn[5, 3, 1]

http://mathworld.wolfram.com/Circle-CircleIntersection.html

Bobby

On Mon, 18 Apr 2011 05:50:23 -0500, Bob Hanlon <hanlonr at cox.net> wrote:

>
> venn[
>    area1_?Positive,
>    area2_?Positive,
>    overlap_?NonNegative ] /;
>   overlap <= Min[area1, area2] :=
>  Module[{area, m, x2,
>    r1 = Sqrt[area1/Pi],
>    r2 = Sqrt[area2/Pi]},
>   m = Max[r1, r2];
>   area[x0_?NumericQ] :=
>    NIntegrate[
>     Boole[x^2 + y^2 <= r1^2 &&
>       (x0 - x)^2 + y^2 <= r2^2],
>     {x, -r1, r1}, {y, -m, m}];
>   x2 = If[overlap == 0,
>     r1 + r2,
>     If[overlap == Min[area1, area2],
>      r1 - r2,
>      Chop[x0 /.
>        FindRoot[area[x0] == overlap,
>         {x0, r1}]]]];
>   Graphics[{
>     Red, Circle[{0, 0}, r1],
>     Blue, Circle[{x2, 0}, r2]}]]
>
> venn[5, 3, 1]
>
>
> Bob Hanlon
>
> ---- dantimatter <google at dantimatter.com> wrote:
>
> =============
>
> Hey Everyone,
> Is there a nice and easy way to make pretty Venn diagrams with
> Mathematica, where the areas of the circles and intersecting regions
> are to scale?
> Cheers
> Dan
>
>
>


-- 
DrMajorBob at yahoo.com


  • Prev by Date: Re: BezierCurve vs. BezierFunction
  • Next by Date: Re: trouble printing to PDF
  • Previous by thread: Re: Venn diagrams?
  • Next by thread: Re: Venn diagrams?