Code covered by the BSD License  

Highlights from
Curve intersections

5.0

5.0 | 7 ratings Rate this file 29 Downloads (last 30 days) File Size: 2.47 KB File ID: #22441
image thumbnail

Curve intersections

by NS

 

14 Dec 2008 (Updated 24 Sep 2010)

Fast computation of intersections and self-intersections of curves using vectorization.

| Watch this File

File Information
Description

While a few other functions already exist in FEX that compute the intersection points of curves, this short piece of code was written with speed being the highest priority. No loops are used throughout, taking full advantage of MATLAB's vectorization capabilities

I welcome any comments, suggestions, bug reports etc.

------------------------------------------------------------------------------

INTERX Intersection of curves
    P = INTERX(L1,L2) returns the intersection points of two curves L1
    and L2. The curves L1,L2 can be either closed or open and are described
    by two-row-matrices, where each row contains its x- and y- coordinates.
    The intersection of groups of curves (e.g. contour lines, multiply
    connected regions etc) can also be computed by separating them with a
    column of NaNs as for example
 
          L = [x11 x12 x13 ... NaN x21 x22 x23 ...;
                y11 y12 y13 ... NaN y21 y22 y23 ...]
 
    P has the same structure as L1 and L2, and its rows correspond to the
    x- and y- coordinates of the intersection points of L1 and L2. If no
    intersections are found, the returned P is empty.
 
    P = INTERX(L1) returns the self-intersection points of L1. To keep
    the code simple, the points at which the curve is tangent to itself are
    not included. P = INTERX(L1,L1) returns all the points of the curve
    together with any self-intersection points.
    
    Example:
        t = linspace(0,2*pi);
        r1 = sin(4*t)+2; x1 = r1.*cos(t); y1 = r1.*sin(t);
        r2 = sin(8*t)+2; x2 = r2.*cos(t); y2 = r2.*sin(t);
        P = InterX([x1;y1],[x2;y2]);
        plot(x1,y1,x2,y2,P(1,:),P(2,:),'ro')

Acknowledgements
This submission has inspired the following:
Accurate polygon extension, Fast Parsing of Line Segments in a BW Mask
MATLAB release MATLAB 7.6 (R2008a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (7)
15 May 2009 Oguzcan

useful, efficient, and fast

27 Oct 2009 Adam

Does exactly what it says. No problems.

01 Dec 2009 Zhang Yanxiang  
30 Nov 2010 ayesha sohail

really very helpful..... many thanks

20 Apr 2011 Valerian  
25 Jul 2011 Jeroen van Nugteren  
18 Jan 2012 Adam

Thanks a lot for this function!!!Works correct where other intersection functions didn't!!

Please login to add a comment or rating.
Updates
26 Nov 2009

Faster execution & better memory management

24 Sep 2010

Fixed a bug identified by Liu Minjie that would sometimes occur for two-point line segments.

Tag Activity for this File
Tag Applied By Date/Time
curves Cristina McIntire 15 Dec 2008 15:43:26
intersections Cristina McIntire 15 Dec 2008 15:43:26
polygons Cristina McIntire 15 Dec 2008 15:43:26
polygons NS 15 Dec 2008 15:43:35
curves NS 15 Dec 2008 15:43:35
intersection NS 15 Dec 2008 15:43:35
selfintersections NS 15 Dec 2008 15:43:35
points NS 15 Dec 2008 15:43:35
crossings NS 15 Dec 2008 15:43:35

Contact us at files@mathworks.com