# Do not understand Curve intersections code

1 view (last 30 days)
Na on 6 Oct 2019
Commented: darova on 7 Oct 2019
I used Curve intersections code and it gives the answer
But the problem is that I do not understand some part of the code and the algorithm.
For examle what this line do
hF = @le; % line 50
C1 = feval(hF,D(bsxfun(@times,dx1,y2)-bsxfun(@times,dy1,x2),S1),0); % line 63
C2 = feval(hF,D((bsxfun(@times,y1,dx2)-bsxfun(@times,x1,dy2))',S2'),0)'; % line 65
function u = D(x,y)
u = bsxfun(@minus,x(:,1:end-1),y).*bsxfun(@minus,x(:,2:end),y);
end
what is 'signed distances'
%...Determine 'signed distances'
S1 = dx1.*y1(1:end-1) - dy1.*x1(1:end-1);
S2 = dx2.*y2(1:end-1) - dy2.*x2(1:end-1);

darova on 6 Oct 2019
Intersections just loops through all segments of curves and find all intersections
Many of segments have intersections, but intersection point has to be on these segments
Here are equations need to be solved to find intersection point
Try to find x,y and see if this solution has something in common with this
function u = D(x,y)
u = bsxfun(@minus,x(:,1:end-1),y).*bsxfun(@minus,x(:,2:end),y);
end

Na on 7 Oct 2019
Thank you. but I have problem to get the formulation
darova on 7 Oct 2019
Look here: Intersections
Piece of explanation from there:
% In principle, we have to perform this computation on every pair of line
% segments in the input data. This can be quite a large number of pairs so
% we will reduce it by doing a simple preliminary check to eliminate line
% segment pairs that could not possibly cross. The check is to look at the
% smallest enclosing rectangles (with sides parallel to the axes) for each
% line segment pair and see if they overlap.
% ...
I think the piece of code you posted do the same - checks if enclosing rectangles overlap