function Eg10_2Rev()

R1 = MakeRect(10,20,5,20);
R2 = MakeRect(11,19,6, 15);
R3 = MakeRect(15,25,6,15);

close all
figure
hold on
ShowRect(R1,'y')
ShowRect(R2,'g')
title(sprintf('OneOrTheOther = %1d',OneOrTheOther(R1,R2)))
axis([0 25 0 25])

figure
hold on
ShowRect(R1,'y')
ShowRect(R2,'g')
title(sprintf('OneOrTheOther = %1d',OneOrTheOther(R1,R2)))
axis([0 25 0 25])

figure
hold on
ShowRect(R1,'y')
ShowRect(R2,'g')
title(sprintf('OneOrTheOther = %1d',OneOrTheOther(R2,R1)))
axis([0 25 0 25])

figure
hold on
ShowRect(R1,'y')
ShowRect(R3,'g')
title(sprintf('OneOrTheOther = %1d',OneOrTheOther(R2,R1)))
axis([0 25 0 25])

hold off

function R = MakeRect(a,b,c,d)
% a and b are real numbers that satisfy a <= b.
% c and d are real numbers that satisfy c <= d.
% R is a rectangle: the set of all (x,y) that satisfy
% R.a <= x <= R.b, R.c <= y <= R.d

R = struct('left',a,'right',b,'bot',c,'top',d);

function ShowRect(R,s)
% R is rectangle
% s is one of the characters 'k','w','r','g','b','m','c','y'
% Displays R in the current figure window using the color s
% Assumes hold is on

fill([R.left R.right R.right R.left],[R.bot R.bot R.top R.top],s)
plot([R.left R.right R.right R.left],[R.bot R.bot R.top R.top],...
'k','Linewidth',2)

function alfa = Disjoint(R1,R2)
% R1 and R2 are rectangles.
% alfa is true if R1 and R2 are disjoint.
% Otherwise alfa is false.

R1_Is_Above = R1.bot > R2.top;
R1_Is_Below = R2.bot > R1.top;
R1_Is_Right = R1.left > R2.right;
R1_Is_Left = R2.left > R1.right;
alfa = R1_Is_Above || R1_Is_Below || R1_Is_Left || R1_Is_Right;

function alfa = OneOrTheOther(R1,R2)
% R1 and R2 are rectangles.
% alfa is true if either R1 is inside of R2 or R2 is inside of R1.M
% Otherwise alfa is false.
alfa = 1;