Do not understand Curve intersections code

1 次查看(过去 30 天)
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);

回答(1 个)

darova
darova 2019-10-6
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
  1 个评论
darova
darova 2019-10-7
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by