title: drawing a polygon that has semicircles at its sides
body: <p>I need to draw a polygon in Pascal(dev-pascal) which has semicircles at its sides. I'll give the code I have come up so far. It has diagonals too. </p>
  
  <pre><code>uses crt,graph;
  var a,b:smallint;
      x0,y0,n,j,k,r:integer;
      xevi,yoni:array[1..50] of integer;
      i:real;
  
  begin
   write('n?.. ');readln(n);
   detectgraph(a,b);
   initgraph(a,b,'');
   x0:=getmaxx div 2;
   y0:=getmaxy div 2;
   j:=0;
   i:=0;
   repeat
    inc(j);
    xevi[j]:=trunc( x0+200*cos(i) );
    yoni[j]:=trunc( y0-200*sin(i) );
    i:=i+2*pi/n;
   until i&gt;2*pi;
  
  
   r:=trunc( sqrt( sqr((xevi[1]-xevi[2])) + sqr((yoni[1]-yoni[2])))) div 2;
  
   for j:=1 to n do begin
      if (xevi[j+1]-xevi[j])&lt;&gt;0 then begin
      k:=trunc( arctan(
      //abs(
      ((yoni[j+1]-yoni[1])/(xevi[j+1]-xevi[j])-1)
      /(1+(yoni[j+1]-yoni[1])/(xevi[j+1]-xevi[j]))
      //)
      )*180/pi); end
      else k:=90;
      if k&gt;0 then arc( (xevi[j]+xevi[j+1]) div 2, (yoni[j]+yoni[j+1]) div 2, k, k+180, r )
             else begin
                  k:=360+k;
                  if k+180&gt;360 then k:=360-k;
                  arc( (xevi[j]+xevi[j+1]) div 2, (yoni[j]+yoni[j+1]) div 2, k, k+180, r );
                  end;
  
   end;
  
  
   for j:=1 to n do
       for k:=1 to n do
           line( xevi[j],yoni[j],xevi[k],yoni[k]);
  
  
   readln;
   closegraph;
  end.
  </code></pre>
  
  <p>As you can see, I tried using analytic geometry to find the slope between two adjacent vertices of the polygon, then calculating the angle of a line with that slope, and then using the angle to draw an arc.</p>
  
  <p>So basically, I don't know why it doesn't work, and I'm also sure there's a much simpler way to do it! Any help at all will be appreciated!</p>
  
  <p>Thank you!</p>