% P3
% Checks InsideDist

% Set up the polygon...
n = 23; r1 = 1; r2 = 3; a = 5; b = 2;
x = zeros(n,1); y = zeros(n,1); tau = linspace(0,2*pi,n+1)';
x(1:2:n) = r1; x(2:2:n) = r2; x = a + x.*cos(tau(1:n));
y(1:2:n) = r1; y(2:2:n) = r2; y = b + y.*sin(tau(1:n));

% Display the polygon...
close all
plot(0,0,'*r','Markersize',10)
hold on
fill(x,y,'y')
axis equal off

q = 19;
theta = linspace(-pi/13,pi/3,q); R = 9;
clc
disp('Ray Inside Distance')
disp('------------------------------')
for k=1:q
% Process the kth ray...
[d,u,v] = InsideDist(x,y,theta(k));
if d>0
plot(u,v,'.k','Markersize',5)
end
plot([0 R*cos(theta(k))],[0,R*sin(theta(k))],'-r')
fprintf('%3d %20.15f\n',k,d)
end
set(gcf,'position',[100 100 800 600])