File Exchange

## Fast and Robust Self-Intersections

version 1.0 (3.36 KB) by

Computes the self-intersections of a curve.

Updated

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

Hauke Gravenkamp

### Hauke Gravenkamp (view profile)

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

### Thayjes Srivas (view profile)

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

### Muyun (view profile)

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

### Ilya (view profile)

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

### Ilya (view profile)

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

### Robert Beardmore (view profile)

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 6.5 (R13)