% zowie.m
% Try to produce zowie graphics for the Rigid Body using Matlab!

% Close current figure
close

% Create a figure for display of the Rigid Body Dyanmics
% Color         : black 
% InvertHardCopy: on
% Name:         : Rigid Body Dynamics
% NumberTitle   : off
% Children      : coadaxes
rbbfig = figure('Color','k',...
         'InvertHardCopy','on','Name','Rigid Body Dynamics',...
         'NumberTitle','off');

% Create axes to display the momentum sphere and energy ellipse
% Box          : off
% Color        : black
% GridLineStyle: dashed '-'
% NextPlot     : add
% View         : [az = -37.5,el = 30]
%              : The aximuth revolves around the z axis, causing the
%              : viewpoint to rotate in a counter-clockwise direction.       
%              : The elevation specifies an angle above or below the object.
% Children: [msphere, eellipse]
coadaxes = axes('Box','off','Color','k','GridLineStyle','-',...
          'NextPlot','add','View',[-37.5,30],...
          'XColor','w','XGrid','on',...
          'YColor','w','YGrid','on',...
          'ZColor','w','ZGrid','on');

% Create Labels for Axes
xtext = text(0,0,0,'Major Axis');
ytext = text(0,0,0,'Intermediate Axis');
ztext = text(0,0,0,'Minor Axis');
set(gca,'xlabel',xtext);
set(gca,'ylabel',ytext);
set(gca,'zlabel',ztext);

% Generate Data for the Body Angular Momentum Sphere
k=6;
n=2^k-1;
theta = pi*[-n:2:n]/n;
theta(9:20) = nan*theta(9:20);
phi = (pi/2)*[-n:2:n]'/n;
Xs = cos(phi)*cos(theta);
Ys = cos(phi)*sin(theta);
Zs = sin(phi)*ones(size(theta));

% Generate Data for the Energy Ellipse
k=6;
n=2^k-1;
theta = pi*[-n:2:n]/n;
phi = (pi/2)*[-n:2:n]'/n;
Xe = cos(phi)*cos(theta);
Ye = 2*cos(phi)*sin(theta);
Ze = .25*sin(phi)*ones(size(theta));

% Set the Colormap
colormap([gray(30);copper(30)])

% Create Cdata for the sphere and the ellipse
cds = Zs + abs(min(min(Zs)));
cde = cds + max(max(cds)) + 1;

% Draw sphere and ellipse using different colormaps
msphere=surf(Xs,Ys,Zs,cds);
eellipse=surf(Xe,Ye,Ze,cde);

shading flat;

