Do not understand Curve intersections code

1 回表示 (過去 30 日間)
NA
NA 2019 年 10 月 6 日
コメント済み: darova 2019 年 10 月 7 日
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 Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by