Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugs in intersectEdges.m #157

Closed
nuitlejour opened this issue Jul 6, 2023 · 2 comments
Closed

Bugs in intersectEdges.m #157

nuitlejour opened this issue Jul 6, 2023 · 2 comments
Assignees

Comments

@nuitlejour
Copy link

nuitlejour commented Jul 6, 2023

I am using the lastest matGeom, in source code mmTrace\intersectEdges.m: 79
`
% Process colinear edges

% colinear edges may have 0, 1 or infinite intersection
% Discrimnation based on position of edge2 vertices on edge1
if sum(col) > 0
% array for storing results of colinear edges
resCol = Inf * ones(size(col));

% compute position of edge2 vertices wrt edge1
t1 = edgePosition(edge2(col, 1:2), edge1(col, :));
t2 = edgePosition(edge2(col, 3:4), edge1(col, :));

% control location of vertices: we want t1<t2
if t1 > t2
    tmp = t1;
    t1  = t2;
    t2  = tmp;
end

% edge totally before first vertex or totally after last vertex
resCol(col(t2 < -tol))  = NaN;
resCol(col(t1 > 1+tol)) = NaN;
    
% set up result into point coordinate
x0(col) = resCol(col);
y0(col) = resCol(col);

% touches on first point of first edge
touch = col(abs(t2) < tol);
x0(touch) = edge1(touch, 1);
y0(touch) = edge1(touch, 2);

% touches on second point of first edge
touch = col(abs(t1-1) < tol);
x0(touch) = edge1(touch, 3);
y0(touch) = edge1(touch, 4);

end
`

It is apparent that t1, t2 should be single-valued, but edgePosition() does not guaranty that.

I made the following change, could you please check and make sure the sementics are correct?

`
% Process colinear edges

% colinear edges may have 0, 1 or infinite intersection
% Discrimnation based on position of edge2 vertices on edge1
if sum(col) > 0
% array for storing results of colinear edges
resCol = Inf * ones(size(col));

% compute position of edge2 vertices wrt edge1
t1 = edgePosition(edge2(col, 1:2), edge1(col, :));
t2 = edgePosition(edge2(col, 3:4), edge1(col, :));

% control location of vertices: we want t1<t2
for ii = 1:size(t1, 1)
    if t1(ii, 1) > t2(ii, 1)
        t1_ii  = t2(ii);
        t2_ii  = t1(ii);
    else
        t1_ii  = t1(ii);
        t2_ii  = t2(ii);
    end

    % edge totally before first vertex or totally after last vertex
    resCol(col(t2_ii < -tol))  = NaN;
    resCol(col(t1_ii > 1+tol)) = NaN;

    % set up result into point coordinate
    x0(col) = resCol(col);
    y0(col) = resCol(col);

    % touches on first point of first edge
    touch = col(abs(t2_ii) < tol);
    x0(touch) = edge1(touch, 1);
    y0(touch) = edge1(touch, 2);

    % touches on second point of first edge
    touch = col(abs(t1_ii-1) < tol);
    x0(touch) = edge1(touch, 3);
    y0(touch) = edge1(touch, 4);

end

end
`

@dlegland
Copy link
Member

dlegland commented Jul 7, 2023

Hi,
thanks for reporting!
yes, this can be improved. I have started to check, but ran out of time. I'll have another llok next week. Stay tuned...

@dlegland
Copy link
Member

Hi,
just made a correction in commit a4be530. Should work better now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants