%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Draw Platform 
% Load platform data from 'model1' folder. 
% scale, rotate and translate model to the points.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [p_handle] = plot_platform( Filename , Radius , Translate  , Rot, Thickness, Color, p_handles )
%nargin=2 
if nargin < 7 ,     p_handles=0;   end
if nargin < 6 , color = [0.8,0.3,0.3]; end


    load(Filename);
    
    
 
%% Translation of the STL model
    Translation =  [ Translate(1) * ones(1,length(Vertices)) ; 
                     Translate(2) * ones(1,length(Vertices)) ; 
                     Translate(3) * ones(1,length(Vertices)) ; 
                    ];

%% Scale 
    Vertices(:,1 ) = Vertices(:,1) * 2*Radius/edit_sizeX;
    Vertices(:,2 ) = Vertices(:,2) * 2*Radius/edit_sizeY;
    Vertices(:,3 ) = Vertices(:,3) * Thickness/edit_sizeZ;
%     axis auto;

%% Rotate Model    
    V = Rot * Vertices' + Translation;
        
 
if nargin == 6 
 
%% Plot     
    p_handle  =  patch('faces', Faces, 'vertices' ,V' );   

    
    set(p_handle, 'facec', 'b');              % Set the face color (force it)
    
    set(p_handle, 'facec', 'flat');            % Set the face color flat

    set(p_handle, 'facecolor', Color );       % Set the color (from file)    
%     set(p_handle, 'FaceVertexCData', Color );       % Set the color (from file)
    
    set(p_handle, 'facealpha',.8)             % Use for transparency
    
    set(p_handle, 'EdgeColor','none');         % Set the edge color
    
    %set(handles.p, 'EdgeColor',[1 0 0 ]);      % Use to see triangles, if needed.    
    
else 
    
    set(p_handles,'vertices',V);
    p_handle = p_handles;

end             