Skip to content

Instantly share code, notes, and snippets.

@taroyabuki
Created December 23, 2017 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taroyabuki/5d54e56965ef9d58c4018eb27d2db75d to your computer and use it in GitHub Desktop.
Save taroyabuki/5d54e56965ef9d58c4018eb27d2db75d to your computer and use it in GitHub Desktop.
I rewrote the code published in http://mathworld.wolfram.com/VennDiagram.html to work with the latest version of Mathematica.
VennDiagram[n_, ineqs_: {}] := Module[{i, r = .6, R = 1, v, x, y, f},
v = Table[Circle[r {Cos[#], Sin[#]} &[2 Pi (i - 1)/n], R], {i, n}];
{
If[ineqs == {}, {},
f = And @@ (v /. Circle[{xx_, yy_}, rr_] :> (x - xx)^2 + (y - yy)^2 < rr^2)[[ineqs]];
RegionPlot[ImplicitRegion[f,
{x, y}], Axes -> False,
DisplayFunction -> Identity][[1]]
],
v
}
]
Show[GraphicsGrid[
Partition[
Graphics[VennDiagram[2, #], PlotRange -> All,
AspectRatio -> Automatic,
PlotLabel -> TraditionalForm[And @@ (Subscript[A, #] & /@ #)] /.
True -> \[EmptySet]] & /@ Sort@Subsets[Range[2]], 2]
]]
Show[GraphicsGrid[
Partition[
Graphics[VennDiagram[3, #], PlotRange -> All,
AspectRatio -> Automatic,
PlotLabel ->
TraditionalForm[And @@ (Subscript[A, #] & /@ #)] /.
True -> \[EmptySet]] & /@ Sort@Subsets[Range[3]], 4]
]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment