function P = P_outer(a,b,n)
%P_OUTER computes perimeter of circumscribed polygon

theta=2*pi/n;
c=(1-cos(theta))/sin(theta);

sum=0;

for k=1:n
    xk=a*( cos(k*theta)-c*sin(k*theta) );
    yk=b*( sin(k*theta)+c*cos(k*theta) );

    xkp1=a*( cos((k+1)*theta)-c*sin((k+1)*theta) );
    ykp1=b*( sin((k+1)*theta)+c*cos((k+1)*theta) );

    dk=sqrt((xk-xkp1)^2 + (yk-ykp1)^2);
    sum=sum+dk;
end

P=sum;

end

