Code covered by the BSD License

### Highlights from Fast Line Segment Intersection

5.0
5.0 | 10 ratings Rate this file 55 Downloads (last 30 days) File Size: 3.5 KB File ID: #27205 Version: 1.1

# Fast Line Segment Intersection

### U. Murat Erdem (view profile)

08 Apr 2010 (Updated )

Finds the pairwise intersection points between line segments in 2D Cartesian space.

File Information
Description

OUT = LINESEGMENTINTERSECT(XY1,XY2) generates intersection analysis between the line segment sets given in XY1 and XY2. Code can handle coincident and parallel lines.

The main emphasis is on speed. The code is fully vectorized and it runs pretty fast (orders of magnitude) compared to some of the previous postings.

Acknowledgements

Fast And Robust Curve Intersections inspired this file.

This file inspired Segments Intersection Test Functions.

MATLAB release MATLAB 7.9 (R2009b)
23 Jul 2015 Matthias Faes

18 Nov 2014 Sam

### Sam (view profile)

Please consider changing the parallelism check to abs(denominator) < some small number. This will catch lines that are parallel to within some threshold.

08 Aug 2013 Matthew Bays

### Matthew Bays (view profile)

12 Jun 2013 Ulrik

### Ulrik (view profile)

18 Mar 2012 Francesco Montorsi

### Francesco Montorsi (view profile)

I've found your function very useful, thanks! However I recently wanted to squeeze out some additional performance and ended up rewriting the thing in MEX C code, which can be compiled and run from MATLAB... I posted my code at http://www.mathworks.it/matlabcentral/fileexchange/35492-segments-intersection-test-functions .

03 Aug 2011 Brandon

### Brandon (view profile)

16 Jun 2011 piet fue

### piet fue (view profile)

07 Apr 2011 Maher HAMDI

05 Nov 2010 Alex

### Alex (view profile)

Quick and effective. However, I believe there is a typo in the documentation:

'intNormalizedDistance2To1' : N1xN2 matrix where the (i,j) entry is the normalized distance from the start point of line segment XY1(j,:) to the intersection point with XY2(i,:).

This description is the same as intNormalizedDistance1To2 except that i and j are swapped in the description, and that doesn't really make any sense. I believe XY1 and XY2 should also be swapped.

Comment only
05 Nov 2010 Alex

### Alex (view profile)

30 Apr 2010 Fabio Pinna

### Fabio Pinna (view profile)

It worked fine and fast for me! Good work!
Good vectorization.
The complex output prevent further vectorization but it is already fast enough