function pt =intersect( pt1, pt2, style )
% INTERSECT Calculates the intersection of two lines,
%  each line defined by two points. Style is used to
%  plot the intersection point.

A = [diff(pt1)' -diff(pt2)'];
b = pt2-pt1;
q = A\b(1,:)';
pt = pt1(1,:) + q(1)*A(:,1)';
%pt = pt2(1,:) - q(2)*A(:,2)'; % solution based on second line
if nargin>2
    hold on
    plot(pt(1),pt(2),style);
    hold off
end