5.0

5.0 | 12 ratings Rate this file 286 downloads (last 30 days) File Size: 10.98 KB File ID: #8908

Curve Intersect 2

by Sebastian Hölz

 

02 Nov 2005 (Updated 16 Feb 2007)

Code covered by BSD License  

Finds the intersection points between two arbitrary polygons.

Download Now | Watch this File

File Information
Description

General

This file is based on the Curve Intersect function by Duane Hanselman. It extends the scope of the function to handle arbitrary lines / polygons, which may also have vertical segments or segments with non-increasing x-values.

Description
Calculate the intersection points of two 2D-lines / polygons.

Usage
[X,Y]=CURVEINTERSECT(H1,H2) or [X,Y]=CURVEINTERSECT([H1 H2]) or
[X,Y]=CURVEINTERSECT(X1,Y1,X2,Y2) or
 -> (H1,H2) handles to line objects
 -> (Xi,Yi) coordinates of lines
 -> (X,Y) coordinates of intersection

Example
x1=rand(10,1); y1=rand(10,1); x2=rand(10,1); y2=rand(10,1);
[x,y]=curveintersect(x1,y1,x2,y2);
plot(x1,y1,'k',x2,y2,'b',x,y,'ro')

Acknowledgements
This submission has inspired the following:
Fast and Robust Curve Intersections, Minimum distance between two polygons
MATLAB release MATLAB 7.0.1 (R14SP1)
Zip File Content  
Other Files CurveIntersect/curveintersect.m,
CurveIntersect/CurveIntersect_Example.png
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (15)
08 Feb 2006 gok gok

great command, thank you!
Are you planning to include the case of infinite line intersection?
Example:
x1=[0 1]; y1=[0 0];x2=[0.5 0.5]; y2=[0.1 1];
will "intersect" at [0.5,0]

17 Jan 2007 xiaoxu wang  
11 May 2007 Peter Krug

Works well for me

11 Jul 2007 Mat Cop

very useful

13 Jul 2007 leila k  
25 Jul 2007 Huy Pham

Could we use it for a higher dimension?

30 Jul 2007 Dick Benson

Overcomes limitations of the D. Hanselman version. THANKS!

30 Jan 2008 David Shepherd

I'm using this to quickly find the point at which two EXIT functions intersect, its perfect thanks mate.

30 Jun 2008 Sathish Athreya

Yes, Obviously it is very fast to find intersection point between curves

19 Oct 2008 C. Chaya Boughan

Wonderful program. Worked for some very sticky intensity plots where the points of intersection had been hard to find. Vielen dank Sebastian !!!!

17 Nov 2008 Carlos Guerrero Mosquera  
17 Nov 2008 Carlos Guerrero Mosquera

Excellent job!! Thanks!

06 Mar 2009 Damir

It is an excelent job, however I found a bug. The function finds wrong intersection, if one of the curves is almost vertical. Please try this:
x1=[0.1 0.1+1e-17]
y1=[-1 1]
x2=[-1 1]
y2=[-1 1]
[x,y]=curveintersect(x1,y1,x2,y2)
plot(x1,y1,'k',x2,y2,'b:',x,y,'ro')

24 Aug 2009 Smith Kumar

Great job !!

15 Oct 2009 Yan

works great! thanks

Please login to add a comment or rating.
Updates

Fixed small bug reported by Vadim Moldavsky

16 Feb 2007

Fixed small bug reported by Vadim Moldavsky

Tag Activity for this File
Tag Applied By Date/Time
intersection Cristina McIntire 10 Dec 2008 16:49:01
line Cristina McIntire 10 Dec 2008 16:49:01
curve Cristina McIntire 10 Dec 2008 16:49:01
polygon Cristina McIntire 10 Dec 2008 16:49:01
intersection Peter Chang 11 Dec 2008 12:22:16
polygon Ashok Prajapati 06 Feb 2009 19:22:21
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com