clear vetor;
vetor=[];

AOx=0;
AOy=0;
BOx=6.5;
BOy=1;
Ax=-1.5;
Ay=2.75;
Bx=4.5;
By=6;
Px=-1;
Py=6.5;
deltatheta2=1*pi/180;

MC=[1 1 0 1 0
    1 1 1 0 1
    0 1 1 1 1
    1 0 1 1 0
    0 1 1 0 1];

AO=AOx + i*AOy;
BO=BOx + i*BOy;
A=Ax + i*Ay;
B=Bx + i*By;
P=Px + i*Py;

n=2*pi/deltatheta2;

r(1)=BO - AO;
r(2)=A - AO;
r(3)=B - A;
r(4)=B - BO;
r(5)=P - A;
r(6)=B - P;

gama=angle(r(4))-angle(r(3));

if gama > pi
        gama=gama-2*pi;
else
        if gama <= -pi
                gama=gama+2*pi;
             end
end
signumgama=sign(gama);
alfa=angle(r(5))-angle(r(3));
if alfa > pi
         alfa=alfa-2*pi;
else
        if alfa <= -pi
                  alfa=alfa+2*pi;
        end
end

theta2=angle(r(2));

for m=0:n+1
        D=r(1)-r(2);
        delta=acos((abs(r(3))^2+abs(D)^2-abs(r(4))^2)/(2*abs(r(3))*abs(D)));
        if abs(cos(delta)) > 1
                 break
        else
                 delta=signumgama*delta;
                 sigma=acos((abs(r(4))^2+abs(D)^2-abs(r(3))^2)/(2*abs(r(4))*abs(D)));
                 sigma=signumgama*sigma;
                 theta3=angle(D)+delta;
                 theta4=angle(D)+(pi-sigma);
                 j=3;
                 while j < 5
                       thetaj=eval(['theta' int2str(j)]);
                       if thetaj > pi
                           thetaj=thetaj-2*pi;
                           eval(['theta' int2str(j) '=thetaj;']);
                           j=j+1;
                 else
                       if thetaj < -pi
                       thetaj=thetaj+2*pi;
                       eval(['theta' int2str(j)  '=thetaj;']);
                       j=j+1;
                        else
                            j=j+1;
                         end
                    end
           end
           r(5)=abs(r(5))*exp(i*(theta3+alfa));
           P=r(2)+r(5);
           theta2=theta2+deltatheta2;
           r(2)=abs(r(2))*exp(i*theta2);
           r(3)=abs(r(3))*exp(i*theta3);
           xy=[AOx		    AOy
	       real(r(2))           imag(r(2))
               real(r(2)+r(3))      imag(r(2)+r(3))
               BOx                  BOy
               real(P)              imag(P)];

   
           axis([-4.5 8 -3 7]);
           %axes('Position',[0.05 0.05 0.75 0.80]);
           if m==0 
              vetor=[real(P) imag(P)];
           end
           plot(vetor(:,1),vetor(:,2),'y-')
           if m < n+1,
               gplot(MC,xy)
               drawnow
               clg
           end
           hold on
           
           axis('off')

          
        end

vetor=[vetor(:,1) vetor(:,2)
       real(P)    imag(P)];
end


gplot(MC,xy)