% Script P2
% Tests PolygonCrossings...

% Generate an example with lots of intersection points...

% Set the seed so we all get the same examples...
randn('seed',0)

% An example with many intersection points...
n = 10; x = randn(n,1); y = randn(n,1);
[u,v] = PolygonCrossings(x,y);
% Display the polgon...
plot([x; x(1)],[y; y(1)])
if ~isempty(u)
% Display the intersection points (if there are any...
hold on
plot(u,v,'.r','Markersize',20)
hold off
end
title(sprintf('The number of intersection points = %1d',length(u)))
shg
pause(3)

% An example with no intersection points...
n = 5; x = randn(n,1); y = randn(n,1);
[u,v] = PolygonCrossings(x,y);
% Display the polygon..
plot([x; x(1)],[y; y(1)])
if ~isempty(u)
% Display the intersection points (if there are any)...
hold on
plot(u,v,'.r','Markersize',20)
hold off
end
axis([-1 1 -2 1])
title(sprintf('The number of intersection points = %1d',length(u)))
shg

% Benchmark...
n = 500; x = randn(n,1); y = randn(n,1);
tic
[u,v] = PolygonCrossingsCVL(x,y);
tCVL = toc;
tic
[u,v] = PolygonCrossings(x,y);
tYou = toc;
fprintf('\n\n tYou/tCVL = %5.2f\n',tYou/tCVL)