## Curve intersection

Version 1.2.0.0 (1.81 KB) by
Finds intersections of two piecewise linear plane curves.

Updated 6 Oct 2009

[xs,ys] = cint(x1,y1,x2,y2) finds intersection points of the curves defined by straight lines between the length(x1) points in the plane, (x1,y1), and the length(x2) points in the plane (x2,y2).

The function essentially solves

x1(m) + t*diff(x1)(m) = x2(n) + s*diff(x2)(n);
y1(m) + t*diff(y1)(m) = y2(n) + s*diff(y2)(n);

for each combination of line segments and returns

xs = x1 + t*dx1;
ys = y1 + t*dy1;

for all t for which 0<t<1 and 0<s<1 corresponding to an intersection.

For efficiency the function uses bsxfun to construct the length(x1) x length(x2) matrices involved in the calculation.

Points shared by the two arrays (x1,y1) and (x2,y2) are also returned.

### Cite As

Johan Rønby (2023). Curve intersection (https://www.mathworks.com/matlabcentral/fileexchange/25501-curve-intersection), MATLAB Central File Exchange. Retrieved .

##### MATLAB Release Compatibility
Created with R2007b
Compatible with any release
##### Platform Compatibility
Windows macOS Linux
##### Categories
Find more on Interpolation in Help Center and MATLAB Answers

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.2.0.0

Fixed bug introduced by wrong use of unique in last bug fix :-)

1.1.0.0

Bug fixed: Earlier version did not return intersection points where a data point from one of the input curves was placed exactly on the line connecting two data points of the other input curve.

1.0.0.0