Code covered by the BSD License

### Highlights from Curve Intersect 2

4.94737
4.9 | 19 ratings Rate this file 21 Downloads (last 30 days) File Size: 11 KB File ID: #8908 Version: 1.0

# Curve Intersect 2

### Sebastian Hölz (view profile)

02 Nov 2005 (Updated )

Finds the intersection points between two arbitrary polygons.

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 file inspired Minimum Distance Between Two Polygons and Fast And Robust Curve Intersections.

MATLAB release MATLAB 7.0.1 (R14SP1)
19 Dec 2013 Johannes

### Johannes (view profile)

why does this result in an empty matrix? curveintersect([-1 -0.9],[0 3],[-0.9 0],[3 0])

18 Aug 2012 Daphne

### Daphne (view profile)

06 Sep 2011 KYAW KYAW

### KYAW KYAW (view profile)

I am looking for the intersection of dynamic waves and base line. SO far, I could manage to get few of the intersection points using ratio (Y data of dynamic wave/ Y data of base line) for whole of samples. Pls advise me how should I continue since I was stuck in here so long.

I used your function but mine is dynamic wave form and base straing line so the X -axis is not constant line. So the array is only (1900x1) for wave form and base line. The Y values of wave form is changing but the base line is seems like constant. Let say, there is 64 intersection points visuality but what i can get is only 47 but some are not accutare positions.

Thanks and best regards
Kyaw

Comment only
26 May 2011 Weylan Yutani

### Weylan Yutani (view profile)

Forgot to say thanks and congrats!

03 May 2011 minoo

17 Mar 2011 Zak

### Zak (view profile)

Worked great for me, though my application was quite simple.

15 Feb 2011 Martin Fuchs

### Martin Fuchs (view profile)

Extremly good code ! Thx sharing it !!!

02 Jul 2010 Andreas Lobinger

### Andreas Lobinger (view profile)

One of our students came up with the usage of curveintersect and afaics it works correctly. However the profiler tells me now, that from 300s program runtime 120s are spend in curveintersect and most of the time in the calls to interp1 in curveintersect_l.

Are they really neccessary?

Comment only
21 Jan 2010 Tyler Jandreau

15 Oct 2009 Yan

### Yan (view profile)

works great! thanks

24 Aug 2009 Nitin

### Nitin (view profile)

Great job !!

06 Mar 2009 Damir

### Damir (view profile)

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')

Comment only
17 Nov 2008 Carlos G-M

### Carlos G-M (view profile)

Excellent job!! Thanks!

Comment only
17 Nov 2008 Carlos G-M

### Carlos G-M (view profile)

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 !!!!

30 Jun 2008 Sathish Athreya

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

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 Jul 2007 Dick Benson

Overcomes limitations of the D. Hanselman version. THANKS!

25 Jul 2007 Huy Pham

Could we use it for a higher dimension?

Comment only
13 Jul 2007 leila k
11 Jul 2007 Mat Cop

very useful

11 May 2007 Peter Krug

Works well for me

17 Jan 2007 xiaoxu wang
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]