I'm trying to calculate where two objects in a picture are pointing at one another. I figured I would use intersecting lines to perform this as the objects can be converted into a straight line. One problem though is I seem to be finding code mostly for finding intersection between infinite lines which is something I don't need.
I found this code from a matlab blog which details how to find intersecting infinite lines.
A = [lineA(1,:) - lineA(2,:); lineB(2,:) - lineB(1,:)]';
if rank(A) < 2
disp('Parallel')
B = [lineA(1,:) - lineA(2,:); lineA(1,:) - lineB(1,:)]';
if rank(B) < 2
disp('Collinear')
if all( (sort(lineA(:,1),'descend')-sort(lineB(:,1))) ...
.*[-1;1] <= sqrt(eps) )
tf = true;
else
tf = false;
end
else
tf = false;
end
else
pq = linsolve(A,(lineB(2,:) - lineA(2,:))');
tf = all(pq>=-sqrt(eps)) & all(pq<=1+sqrt(eps));
end
I have also located old questions about line + circle intersections which looks closer to what I might need.
However the problem is that I am trying to check for 1 line to intersect with a finite line. The picture represents what I'm trying to draw between. The blue line has a limited length while the red line is infinite and I am trying to determine if they intersect.