function cube_plot(Tobject,X,Y,Z,color)
% CUBE_PLOT plots a cube with dimension of X, Y, Z.
% Reference frame is located at a vertex in the top face (i.e. the top face
% is in the z-plane).
%
% INPUTS:
% origin = set origin point for the cube in the form of [x,y,z].
% X      = cube length along x direction.
% Y      = cube length along y direction.
% Z      = cube length along z direction.
% color  = STRING, the color patched for the cube.
%         List of colors
%         b blue
%         g green
%         r red
%         c cyan
%         m magenta
%         y yellow
%         k black
%         w white
% OUPUTS:
% Plot a figure in the form of cubics.
%
% EXAMPLES
% cube_plot(2,3,4,'red')
%
% ------------------------------Code Starts Here------------------------------ %
% Define the vertexes of the unit cubic
ver = [X Y 0;
    0 Y 0;
    0 Y -Z;
    X Y -Z;
    0 0 -Z;
    X 0 -Z;
    X 0 0;
    0 0 0];
%apply Tobject to the cube vertices
V = Tobject*cat(1,ver',ones(1,size(ver',2)));
ver=V([1 2 3],:)';

%  Define the faces of the cube
fac = [1 2 3 4;
    4 3 5 6;
    6 7 8 5;
    1 2 8 7;
    6 7 1 4;
    2 3 5 8];
cube = [ver(:,1),ver(:,2),ver(:,3)];
h=patch('Faces',fac,'Vertices',cube,'FaceColor',color);
set(h,'facealpha',.2);%transparency
end

