# Find intersection of curves

I have a curve (not a function) as a list of points and I would like to find the intersection of the curve with another curve (another set of points). To be more concrete about the problem I am solving :

The curve is a spiral, whose points are https://drive.google.com/file/d/1TtkKPgIxSKmdeWZDYQ1-Dd2aUvxqGDyF/view?usp=sharing. It looks like :

and I need to find intersection with another curve, say a straight line $$y=x$$. Is there a way to do this in Mathematica.

A canonical procedure is to find the interpolating function from the points (if this were a function) say $$f(x)$$ and solve $$f-g=0$$ to find intersection with the the curve $$g(x)$$.

How does one do the same for a curve where an interpolating function makes no sense? Other alternatives?

Thanks for reading and any help is appreciated.

Edit: I think one way is to check for intersection of all possible line segments, but the number of checks is $$O(n^2)$$. Maybe someone in the community could suggest a clever way to remove some of these checks, or suggest another method.

• Mar 28, 2022 at 22:54
• You can find a parametrized interpolation by interpolating x(t) and y(t)separately. Mar 29, 2022 at 0:05

ListLinePlot[data,
MeshFunctions -> {Function[{x, y}, x - y]},
Mesh -> {{0}},
MeshStyle -> Directive[PointSize[Medium], Red],
Prolog -> {Orange, InfiniteLine[{{0, 0}, {1, 1}}]},
PlotRange -> All, ImageSize -> Large]


intersections = Cases[Normal @ llp, Point[x_] :> x, All]


• Why are the double curly braces needed around zero in Mesh-> {{0}}? The intersections vanish if I remove one of them. Mar 28, 2022 at 22:08
• @Shubham, See Mesh >> Details for details of the settings for Mesh.
– kglr
Mar 28, 2022 at 22:13
• I see. Thanks for the answer and comment! Mar 28, 2022 at 22:15

Another way which does not depend on the order of points.We select the points close to the region y==x.

pts = RandomSample[data];
reg = ImplicitRegion[x == y, {x, y}];
dist = RegionDistance[reg];
inters = Select[pts, dist[#] < .01 &]
ListPlot[{inters, pts},
PlotStyle -> {Directive[PointSize[.02], Red],
Directive[AbsoluteThickness[1], Blue]}, AspectRatio -> Automatic]