File Exchange

## Fast and Robust Self-Intersections

version 1.0.0.0 (3.36 KB) by
Computes the self-intersections of a curve.

Updated 13 Dec 2006

This function computes the locations where a curve self-intersects in a fast and robust way. The curve can be broken with NaNs or have vertical segments. Segments of the curve involved in each of the self-interesections are also provided.

Example of use:
N=201;
th=linspace(-3*pi,4*pi,N);
R=1;
x=R*cos(th)+linspace(0,6,N);
y=R*sin(th)+linspace(0,1,N);
t0=clock;
[x0,y0,segments]=selfintersect(x,y)
etime(clock,t0)
plot(x,y,'b',x0,y0,'.r');
axis ('equal'); grid

### Cite As

Antoni J. Canós (2020). Fast and Robust Self-Intersections (https://www.mathworks.com/matlabcentral/fileexchange/13351-fast-and-robust-self-intersections), MATLAB Central File Exchange. Retrieved .

Thank you very much.
You almost save my life !
my whole thesis was depend on this.

Christian

Hamsini Suresh

Hauke Gravenkamp

There appear to be exceptions where it does not work properly though, or at least it happens to find additional points which are not intersections.
I tried it with the "usapolygon" as provided by matlab:

[x0,y0,segments]=selfintersect(uslon,uslat)
plot(uslon,uslat,'o-r')
hold all
plot(x0,y0,'kx')

For this example, x0,y0 contains points that are obviously no intersections.

nasrin

Thayjes Srivas

Hi, I have a questions. Is it possible to use this to reorder a polygon such that all the self intersections are removed but the same points are conserved?

Muyun

Mr. Canos,

It's an awesome program. But could you explain in what way is the following block of code useful, and why does it appear twice?

remove = isnan(sum(dxy1(i,:) + dxy2(j,:),2));
i(remove) = [];
j(remove) = [];

Thank you.

Ilya

it would be helpful to show how to get the (all) values of "t", at which the intersections occur.

Namely, two values of the parameter "t" correspond to each self-intersection.

Ilya

it would be helpful to show how to get the (all) values of "t", at which the intersections occur.

David Bazalar

Evgeny Pr

Robert Beardmore

It certainly is very good and saved me a lot of bother!!

Joseph Marks

This is really great !!!

And I just needed it, too !!!

THANKS VERY MUCH !!!

Sincerely,
Joseph

##### MATLAB Release Compatibility
Created with R13
Compatible with any release
##### Platform Compatibility
Windows macOS Linux