% Script P1
% Line segment intersection
close all
figure
axis([0 1 0 1])
axis equal manual
hold on
% The first point..
title('Enter Point 1','fontsize',14)
[a(1), b(1)] = ginput(1);
plot(a(1),b(1),'.r','Markersize',30)
% The second point...
title('Enter Point 2','fontsize',14)
[a(2), b(2)] = ginput(1);
plot(a(2),b(2),'.r','Markersize',30)
plot([a(1) a(2)],[b(1) b(2)],'r','linewidth',2)
% The third point..
title('Enter Point 3','fontsize',14)
[a(3), b(3)] = ginput(1);
plot(a(3),b(3),'.g','Markersize',30)
% The fourth point...
title('Enter Point 4','fontsize',14);
[a(4), b(4)] = ginput(1);
plot(a(4),b(4),'.g','Markersize',30)
plot([a(3) a(4)],[b(3) b(4)],'g','linewidth',2)
% Do the intersect?
z = Intersect(a,b);
if ~isempty(z)
% Yes...
plot(z(1),z(2),'.k','Markersize',30)
title(sprintf('Intersection at (%5.2f,%5.2f)',z(1),z(2)),'Fontsize',14)
else
% No..
title('No Intersection Point','Fontsize',14)
end
hold off