function P1()
% Checks out InsideDist
close all
clc
% The polygon is an "m star" centered at (x0,y0) with inner
% radius r1 and outer radius r2. You can play with these parameters
% but keep (0,0) outside the polygon.
m = 10; n = 2*m; x0 = 3; y0 = 1.1; r1 = 1; r2 = 3;
% Display the polygon and (0,0)...
delPhi = 2*pi/m;
phi1 = linspace(0,2*pi-delPhi,m)'; phi2 = phi1+delPhi/2;
x = zeros(n,1); y = zeros(n,1);
x(1:2:n) = x0 + r1*cos(phi1); y(1:2:n) = y0 + r1*sin(phi1);
x(2:2:n) = x0 + r2*cos(phi2); y(2:2:n) = y0 + r2*sin(phi2);
fill(x,y,'y')
hold on
plot(0,0,'.m','markersize',20)
axis equal off manual
set(gcf,'color','k')
set(gcf,'position',[300 200 800,800])
shg
% Shoot N rays into the right half plane...
N = 100; thetaVals = linspace(-pi/2,pi/2,N); dValues = [];
for theta = thetaVals
    % Plot the ray...
    plot([0 100*cos(theta)],[0 100*sin(theta)],'m')
    % Determine the intersection points...
    [d,u,v] = InsideDist(x,y,theta);
    if d>0
        % Highlight those portions of the ray that are inside
        % the polygon...
        for k=1:2:length(u)
           plot([u(k) u(k+1)],[v(k) v(k+1)],'g','linewidth',3)
        end
    end
    title(sprintf('Distance = %10.6f',d),'fontsize',24,'color','w');
    pause(2/N)
    dValues = [dValues d];
end
% Plot the distance values. (Only interesting for large N.)
if N>=50
   figure
   plot(dValues)
   shg
end


