function framedesign(handles);
    keyboard
    hand_fig = figure('color', [1 1 1]);
    h = axes();
    view(-79, 20)
    handles.DM.q = handles.DM.q(2:end, :);
   handles.DM.fase = 1;


    for (i=1:size(handles.DM.q,1))
        
        handles.DM.fase = i;
%         handles.DM.XYZRef(i,1) = handles.DM.XYZRef(i,1)+0.50*(i-1);

        A = CinDir20dof( handles.DM ); 
        handles.GP.def = CoordJuntas( A,handles.DM,handles.GP.def );

        hand = DesenharRobo_framedesign( handles.GP, h );
        axis([-.2 .2 -.2 .2 -.1 .7])
        view(180,0)
        if(i>3)
            if(i==4)
                circle(handles.GP.def.P, 2);
%                 cd imagens\Movimentos\Rotação\3\
%                 saveas(hand_fig, [num2str(i) '_inter.jpg']);
%                 cd ..\..\..\..\
            end
            
            circle(handles.GP.def.P, 0);

            
            for inc=1:4,
                set(hand.Eh(inc), 'FaceAlpha', 0.1);
                set(hand.Jh(inc), 'EdgeAlpha', 0.01);
            end
            
            for inc=3:4,
                set(hand.Fh(inc), 'FaceAlpha', 0.1);
            end
        end

%         cd imagens\Movimentos\Rotação\3\
%         saveas(hand_fig, [num2str(i) '.jpg']);
%         cd ..\..\..\..\
%         keyboard
    end
    
return

function circle(P, what)

    persistent raio;
    persistent centro;
    
    if (isempty(raio))
        raio = P(14,2)-P(8,2);
    end
    if (isempty(centro))
        centro = P(8,1:2);
    end
    
    % circle
    x = centro(1)+(-raio:1/100:raio);
    y(1,:) = centro(2) + real(sqrt(raio^2-x.^2));
    y(2,:) = centro(2) - real(sqrt(raio^2-x.^2));
    z = repmat(P(14,3), 1, length(x));
    
    %stick
    z2 = 0:1/100:P(8,3)+.2;
    x2 = repmat(centro(1), 1, length(z2));
    y2 = repmat(centro(2), 1, length(z2));
    
    hold on
    switch(what),
        case 0, plot3(x, y(1,:), z, 'r', x, y(2,:), z, 'r','LineWidth', 2)   % Plot da circunferencia
                plot3(x2, y2, z2, 'r', 'LineWidth', 2);
        case 1, plot3(x, y(1,:), z, 'r', x, y(2,:), z, 'r','LineWidth', 2)   % Plot da circunferencia
        case 2, plot3(x2, y2, z2, 'r', 'LineWidth', 2);
    end
    
    hold off
    
return

 
    

function handles = DesenharRobo_framedesign( GP, axis_h )
% keyboard

P = GP.def.P;       % endoesqueleto
C = GP.def.C;       % juntas rotacionais
F = GP.def.F;       % pé
H = GP.def.H;       % anca
W = GP.def.W;       % tronco
E = GP.def.E;       % exoesqueleto
COG = GP.def.COG;
COG_mi2R = GP.def.COG_mi2R;

axes(axis_h);
[AZ,EL] = view;
cla
hr = hggroup;
%-- Elementos da superficie -----------------------------------------
    % Tapete
    if (isfield(GP.def, 'T'))
        T = GP.def.T;       % tapete
        handles.Th = patch(T(1,:), T(2,:), T(3,:),'c', 'Visible', 'Off');
%         axis([T(1,1) T(1,2) T(2,1) T(2,3) 0 0.70]), 
    else
        
    end
    axis('off'), axis('equal'),
    hold on
    % Escadas
    if(isfield(GP.def, 'S'))
        S = GP.def.S;       % escadas
        handles.Esh = patch(S(:,:,1),S(:,:,2),S(:,:,3), S(1,:,4), 'Visible', 'Off'); 
    end
    % Bola
    if(isfield(GP.def, 'Sp'))
        Sp = GP.def.Sp;     % Bola
        color = repmat(0.3, size(Sp,1), size(Sp,2));
        color(:,:,2) = repmat(1, size(Sp,1), size(Sp,2));
        color(:,:,3) = repmat(0.3, size(Sp,1), size(Sp,2));
        handles.Sph = surface(Sp(:,:,1),Sp(:,:,2),Sp(:,:,3), color, 'Visible', 'Off', 'LineStyle','none');
    end
%-- Elos mecanicos: endoesqueleto ("stick diagram") ----------------
    plot3(  0,0,0,'k.', 'Parent', hr);
    handles.E1(1)  = plot3( P( 1:14,1), P( 1:14,2), P( 1:14,3),'b','XDataSource', 'P( 1:14,1)', 'YDataSource', 'P( 1:14,2)', 'ZDataSource', 'P( 1:14,3)', 'Parent', hr, 'LineWidth', 2.0); %-- Pernas
    handles.E1(2)  = plot3( P(15:18,1), P(15:18,2), P(15:18,3),'b','XDataSource', 'P(15:18,1)', 'YDataSource', 'P(15:18,2)', 'ZDataSource', 'P(15:18,3)', 'Parent', hr, 'LineWidth', 2.0); %-- Tronco
    handles.E1(3)  = plot3( P(19:21,1), P(19:21,2), P(19:21,3),'b','XDataSource', 'P(19:21,1)', 'YDataSource', 'P(19:21,2)', 'ZDataSource', 'P(19:21,3)', 'Parent', hr, 'LineWidth', 2.0); %-- Cabeça
    handles.E1(4)  = plot3( P(22:24,1), P(22:24,2), P(22:24,3),'b','XDataSource', 'P(22:24,1)', 'YDataSource', 'P(22:24,2)', 'ZDataSource', 'P(22:24,3)', 'Parent', hr, 'LineWidth', 2.0); %-- Braço direito
    handles.E1(5)  = plot3( P(25:27,1), P(25:27,2), P(25:27,3),'b','XDataSource', 'P(25:27,1)', 'YDataSource', 'P(25:27,2)', 'ZDataSource', 'P(25:27,3)', 'Parent', hr, 'LineWidth', 2.0); %-- Braço esquerdo
%-- Elos mecanicos: exoesqueleto -----------------------------------
    for i=1:size(E,3), handles.Eh(i) = patch(   E(1,:,i),E(2,:,i),E(3,:,i),'y',...
                                                'Parent', hr);
    end
%-- Juntas rotacionais ---------------------------------------------
    for i=1:size(C,3),
        handles.Jh(i) = surface([C(1,:,i); C(2,:,i)],...
                                [C(3,:,i); C(4,:,i)],...
                                [C(5,:,i); C(6,:,i)],...
                                'Parent', hr);
    end
%-- Pe de suporte e pe livre --------------------------------------
    for i=1:size(F,3),
        handles.Fh(i) = patch(  F(1,:,i),F(2,:,i),F(3,:,i),'y',...
                                'Parent', hr);
    end
%-- Secçao da Anca ------------------------------------------------
    for i=1:size(H,3), 
        handles.Hh(i) = patch(  H(1,:,i),H(2,:,i),H(3,:,i),'y',...
                                'Parent', hr); 
    end
%-- Secçao do Tronco ----------------------------------------------
    for i=1:size(W,3), 
        handles.Wh(i) = patch(  W(1,:,i),W(2,:,i),W(3,:,i),'y',...
                                'Parent', hr);
    end
%-- Esfera na extremidade -----------------------------------------
    [X,Y,Z] = sphere(100);     %-- Esfera de raio unitario
    R = 0.025; X = R*X+P(28,1); Y = R*Y+P(28,2); Z = R*Z+P(28,3);
    handles.Sh = surface(X,Y,Z,'Parent', hr);
%-- COG -----------------------------------------------------------
    handles.CG = plot3(COG(1), COG(2), COG(3), 'or', 'Visible', 'Off', 'XDataSource', 'COG(1)', 'YDataSource', 'COG(2)', 'ZDataSource', 'COG(3)', 'Parent', hr, 'LineWidth', 2.0);
    handles.CP = plot3(COG(1), COG(2), 0, 'or', 'Visible', 'Off', 'XDataSource', 'COG(1)', 'YDataSource', 'COG(2)', 'Parent', hr, 'LineWidth', 2.0);
    for i=1:size(COG_mi2R, 2),
        handles.Cg(i) = plot3(COG_mi2R(1,i), COG_mi2R(2,i), COG_mi2R(3,i), 'xg', 'Visible', 'Off', 'XDataSource', ['COG_mi2R(1,' num2str(i) ')'], 'YDataSource', ['COG_mi2R(2,' num2str(i) ')'], 'ZDataSource', ['COG_mi2R(3,' num2str(i) ')'], 'Parent', hr, 'LineWidth', 2.0);
    end

    handles.hr = hr;
return