%Chapter 7,  Fig 7.10
%Eric Dubois, updated 2018-12-13
%Plot the RGB cube and maxwell triangle
%Required function:  ds2nfu by Michelle Hirsch

clear all
close all

figure

axis equal
axis off
hold on
%set region
xlim([-6, 7]);
ylim([-6, 7]);
%Plot cube faces

rectangle('Position',[0,0,5,5],'EdgeColor','black');
rectangle('Position',[-3.5,-3.5,5,5],'EdgeColor','black');
line([-3.5 0],[1.5 5],'color','black');
line([1.5 5],[1.5 5],'color','black');
line([-3.5 0],[-3.5 0],'color','black');
line([1.5 5],[-3.5 0],'color','black');

%plot maxwell triangle
triangle = polyshape([-3.5 0 5],[-3.5 5 0]);
plot(triangle,'FaceColor',[.9 .9 .9],'EdgeColor','black','LineStyle','--');
streqn= '$$C_R+C_G+C_B=1$$';
text(1.,4.5,streqn,'Interpreter','latex');
[axx,axy] = ds2nfu([2.5 1.5],[4.2 3]);
annotation('arrow',axx,axy,'headlength',5,'headwidth',5);



%label axes
text(6.5,.5,'\itC_R','FontName','times');
text(.25,6.75,'\itC_G','FontName','times');
text(-4.75,-5,'\itC_B','FontName','times');
%label axis values
text(5,-.25,'1','FontName','times');
text(-.4,5.05,'1','FontName','times');
text(-3.85,-3.3,'1','FontName','times');

%plot the color
point = plot(4.5,1.5,'k.');
point.MarkerSize= 12;
point = plot(2.7,0.9,'kx');
point.MarkerSize= 12;
text(4.15,1.8,'[\bfC\rm]','FontName','times');
line([0 6.3],[0 2.1],'color','black');
text(2,.45,'(\itc_R\rm, \itc_G\rm, \itc_B)','FontName','times');

%plot axes
[xaxx,xaxy] = ds2nfu([0 7], [0 0]);
annotation('arrow',xaxx,xaxy,'headlength',5,'headwidth',5);
[yaxx,yaxy] = ds2nfu([0.075 0.075],[0 7]);
annotation('arrow',yaxx,yaxy,'headlength',5,'headwidth',5);
[zaxx,zaxy] = ds2nfu([0.075 -3.8],[0 -5]); 
annotation('arrow',zaxx,zaxy,'headlength',5,'headwidth',5);

set(gcf,'Color',[1 1 1]);
set(gca,'fontname','times')          %set the plot font to Times
