MATLAB Answers

Naime
0

Do not understand Curve intersections code

Asked by Naime
on 6 Oct 2019
Latest activity Commented on by 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);

  0 Comments

Sign in to comment.

1 Answer

Answer by darova
on 6 Oct 2019

Intersections just loops through all segments of curves and find all intersections
112Untitled.png
Many of segments have intersections, but intersection point has to be on these segments
11Untitled.png
Here are equations need to be solved to find intersection point
22Untitled.png
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

  2 Comments

Thank you. but I have problem to get the formulation111.jpg
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

Sign in to comment.