restart; with(plots):unprotect(gamma):

_EnvHorizontalName := 'x';_EnvVerticalName := 'y';

line := proc (x1, y1, x2, y2) options operator, arrow; (x-x1)*(y2-y1)-(y-y1)*(x2-x1) end proc:

R := 3:

ang := [0, (1/3)*Pi, 3*Pi*(1/4)+.2, 7*Pi*(1/6)+.4, 8*Pi*(1/5), 13*Pi*(1/7)]:

for i to 6 do P || i := [R*cos(ang[i]), R*sin(ang[i])] end do:

pts := [seq(P || i, i = 1 .. 6)]:

for i to 6 do tang || i := x*P || i[1]+y*P || i[2] = R^2 end do:

sol:=solve({tang1,tang3},{x,y}):Q13:=[subs(sol,x),subs(sol,y)]:

sol := solve({tang1, tang2}, {x, y}): Q1 := [subs(sol, x), subs(sol, y)]:

sol := solve({tang2, tang3}, {x, y}): Q2 := [subs(sol, x), subs(sol, y)]:

sol := solve({tang3, tang4}, {x, y}): Q3 := [subs(sol, x), subs(sol, y)]:

sol := solve({tang4, tang5}, {x, y}): Q4 := [subs(sol, x), subs(sol, y)]:

sol := solve({tang5, tang6}, {x, y}): Q5 := [subs(sol, x), subs(sol, y)]:

sol := solve({tang1, tang6}, {x, y}): Q6 := [subs(sol, x), subs(sol, y)]:

ptQ := [seq(Q || i, i = 1 .. 6)]:

line14 := line(Q1[1], Q1[2], Q4[1], Q4[2]): L14 := implicitplot(line14, x = -10 .. 10, y = -10 .. 10, color = red):

line25 := line(Q2[1], Q2[2], Q5[1], Q5[2]): L25 := implicitplot(line25, x = -10 .. 10, y = -10 .. 10, color = red):

line36 := line(Q3[1], Q3[2], Q6[1], Q6[2]): L36 := implicitplot(line36, x = -10 .. 10, y = -10 .. 10, color = red):

sol := solve({line14, line25}, {x, y}): I1 := [subs(sol, x), subs(sol, y)]:

lineP23 := line(P2[1], P2[2], P3[1], P3[2]): lineP56 := line(P5[1], P5[2], P6[1], P6[2]):

sol := solve({lineP23, lineP56}, {x, y}): gamma := [subs(sol, x), subs(sol, y)]:

lineP12 := line(P1[1], P1[2], P2[1], P2[2]): lineP45 := line(P4[1], P4[2], P5[1], P5[2]):

sol := solve({lineP12, lineP45}, {x, y}): beta := [subs(sol, x), subs(sol, y)]:

lineP34 := line(P3[1], P3[2], P4[1], P4[2]): lineP16 := line(P1[1], P1[2], P6[1], P6[2]):

sol := solve({lineP16, lineP34}, {x, y}): alpha := [subs(sol, x), subs(sol, y)]:

pl:= line(alpha[1], alpha[2], gamma[1], gamma[2]):

hexa := seq(implicitplot(tang||i, x = -20 .. 20, y = -20 .. 20, linestyle=3,color = blue),i=1..6):

#hexa:=plot([seq([P||i,P||(i mod 6)+1],i=1..6),color=green):

#hexa:=plot([seq([P||i,P||(i+1)],i=1..6)],thickness=4,color=green):

hex:=plot([[Q1,Q2],[Q2,Q3],[Q3,Q4],[Q4,Q5],[Q5,Q6],[Q6,Q1]],thickness=4,color=green):

tp := textplot({seq([op(pts[i]), cat("P", i)], i = 1 .. 6)}, 'align' = {'above', 'left'}):

tpq := textplot({seq([op(ptQ[i]), cat("Q", i)], i = 1 .. 6)}, 'align' = {'above', 'left'}):

TP:=textplot([[I1[],"I"],[alpha[],"alpha"],[beta[],"beta"],[gamma[],"gamma"]],'align' = {'above', 'left'}):

slopes:=[seq(((dx,dy)->dy/dx)((pts[i]-pts[(i mod 6)+1])[]),i=1..6)]:

lines:=zip((pt,slope)->y=slope*(x-pt[1])+pt[2],pts,slopes):

plotpts:=plot(pts,style=point,colour=red,symbol=solidcircle,symbolsize=5):

plotptQ:=plot(ptQ,style=point,colour=black,symbol=solidcircle,symbolsize=5):

plotlines:=plot(rhs~(lines),style=line,linestyle=3,colour=magenta):

cir:=implicitplot(x^2+y^2=R^2,x=-R..R,y=-R..R,color=black):

PL:=implicitplot(pl,x=-1..15,y=-15..6,color=blue,thickness=3):

display(plotpts,plotptQ,plotlines,hex,cir,L14,L25,L36,PL,tp,tpq,TP,axis = [gridlines = [4, color = blue]],

view=[-6..10,-15..6],scaling=constrained,axes=none,size=[800,800]):

How to simplify this program ? Thank you.