-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvennplot
More file actions
63 lines (50 loc) · 2.5 KB
/
vennplot
File metadata and controls
63 lines (50 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
load(draw)$
load(basic)$
fun(n):=/* To plot n-circles at equal distance from each other, find coordinates using roots of complex function of order n */
map(lambda([s],[realpart(s),imagpart(s)]),makelist(cos(2*k*%pi/n)+%i*sin(2*k*%pi/n),k,1,n))$
liss(n):=/* Create equations for circles using the coordinates obtained from fun()) */
block([pts:fun(n)],pts:map(lambda([w],(x-first(w))^2+(y-last(w))^2=n),pts))$
collectatoms(rel):=/* Collect all atoms from the relation provided to be plotted,
eg, (a and b or not(c))=>[a,b,c], calls findatoms() to get job done */
block([final:[]],findatoms(rel),flatten(reverse(final)))$
findatoms(rel):=block([temp,ntemp],ntemp:args(rel),/* Collects atoms in logical relation iteratively */
temp:sublist(ntemp,lambda([s],atom(s))),
if(temp#[]) then push(temp,final),
for item in temp do ntemp:delete(item,ntemp),
map(findatoms,ntemp))$
transform(eq,args,lis):=/* Substitutes the equations of circles into logical relation,
maxima automatically handles it as (x^2+y^2<const) in case of inclusion and not(x^2+y^2<const)
equal to (x^2+y^2>const) in case of exclusion */
block([temp],
eq:map(lambda([s],lhs(s)<rhs(s)),eq),
temp:map("=",lis,eq),
args:psubst(temp,args),args)$
randomcolor():=/*create a random color for each circle plotted */
block([temp:[],final:[]],for i:1 thru 6 do
(temp:[],for j:1 thru 4 do push(random(2),temp),push(temp,final)),
final:psubst([[0,0,0,0]=0,[0,0,0,1]=1,[0,0,1,0]=2,[0,0,1,1]=3,[0,1,0,0]=4,
[0,1,0,1]=5,[0,1,1,0]=6,[0,1,1,1]=7,[1,0,0,0]=8,[1,0,0,1]=9,
[1,0,1,0]=a,[1,0,1,1]=b,[1,1,0,0]=c,[1,1,0,1]=d,[1,1,1,0]=e,[1,1,1,1]=f],final),
final)$
vennplot(args):=/* Does plotting work for the logical relation and is the only function needed by user */
block([pts,reg,form,temp,wee,colr,i:1],
lis:collectatoms(args),
form:liss(length(lis)),
n:length(lis),
pts:(fun(n)),
temp:transform(form,args,lis),
wee:[title=string(args),proportional_axes=xy,
grid= true,line_type= solid,x_voxel = 50,y_voxel = 50],
reg:apply(lambda([s],region(s,x,-(n+1),n+1,y,-(n+1),n+1)),[transform(form,args,lis)]),
wee:endcons(reg,wee),
wee:endcons(grid=false,wee),
wee:endcons(font="Courier-Oblique",wee),
wee:endcons(font_size=15,wee),
wee:endcons(line_width=3,wee),
for item in form do
( colr:apply(concat,cons("#",randomcolor())),
wee:endcons(key=string(part(lis,i)),wee),
wee:endcons(color= (colr),wee),
wee:endcons(label([string(part(lis,i)),first(part(pts,i)),last(part(pts,i))-0.4]),wee),i:i+1,
wee:endcons(implicit(item,x,-(n+1),n+1,y,-(n+1),n+1),wee)),
apply(draw2d,wee))$