function [plt, rplt, tplt, yplt] = paintbody(pos, phi,the,psi,tout,xout,tlim)

    R = [cos(psi)*cos(the)   cos(psi)*sin(the)*sin(phi)-sin(psi)*cos(phi)   cos(psi)*sin(the)*cos(phi)+sin(psi)*sin(phi);
         sin(psi)*cos(the)   sin(psi)*sin(the)*sin(phi)+cos(psi)*cos(phi)   sin(psi)*sin(the)*cos(phi)-cos(psi)*sin(psi);
         -sin(the)           cos(the)*sin(phi)                              cos(the)*cos(phi)];

    % initialize body frame 
    Fo =[1  0  0;
        -1 0  0;
        0  1  0;
        0 -1  0;
        0  0  0.5]';

    F = R*Fo + pos';

    %fore
    fx  = [pos(1)  F(1,1)];
    fy  = [pos(2)  F(2,1)];
    fz  = [pos(3)  F(3,1)];
    %aft
    ax  = [pos(1)  F(1,2)];
    ay  = [pos(2)  F(2,2)];
    az  = [pos(3)  F(3,2)];
    %port
    px  = [pos(1)  F(1,3)];
    py  = [pos(2)  F(2,3)];
    pz  = [pos(3)  F(3,3)];
    %starboard
    sx  = [pos(1)  F(1,4)];
    sy  = [pos(2)  F(2,4)];
    sz  = [pos(3)  F(3,4)];

    %body Z
    zx  = [pos(1)  F(1,5)];
    zy  = [pos(2)  F(2,5)];
    zz  = [pos(3)  F(3,5)];

    subplot(2,2,1)
    plt = plot3(fx, fy,fz,'r',ax, ay,az,'m',px,py,pz,'b',sx,sy,sz,'c',zx,zy,zz,'g');
    plt(1).LineWidth=2;
    plt(3).LineWidth=2;
    plt(5).LineWidth=2;        
    axis([pos(1)-2 pos(1)+2 pos(2)-2 pos(2)+2 pos(3)-2 pos(3)+2])
    xlabel('X');
    title('Body Animation: forward body X axis in red');
    grid on
    
    ymin = -90;
    ymax = 90;
    
    subplot(2,2,2)
    rplt = plot(tout,xout(1,:)*180/pi);
    title('Body Roll');
    xlabel('time (s)');
    ylabel('degrees')
    axis([0 tlim ymin, ymax])
    xticks(0:tlim)
    yticks(ymin:15:ymax)
    grid on
    
    subplot(2,2,3)
    tplt = plot(tout,xout(3,:)*180/pi);
    title('Body Pitch');
    xlabel('time (s)');
    ylabel('degrees')
    axis([0 tlim -90 90])
    xticks(0:tlim)
    yticks(ymin:15:ymax)
    grid on

    subplot(2,2,4)
    yplt = plot(tout,xout(5,:)*180/pi);
    title('Body Yaw');
    xlabel('time (s)');
    ylabel('degrees')
    axis([0 tlim -90 90])
    xticks(0:tlim)    
    yticks(ymin:15:ymax)
    grid on
    
end