4

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 :

enter image description here

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.

Charlie
  • 506
  • 2
  • 8
  • Duplicate: https://mathematica.stackexchange.com/questions/98329/how-to-get-the-coordinates-of-the-intersection-of-two-lines-from-a-listlineplot/98341#98341 -- Related: https://mathematica.stackexchange.com/questions/42304/finding-the-intersection-of-a-curve-with-an-interpolation-function, https://mathematica.stackexchange.com/questions/275/updating-wagons-findallcrossings2d-function – Michael E2 Mar 28 '22 at 22:54
  • You can find a parametrized interpolation by interpolating x(t) and y(t)separately. – Daniel Lichtblau Mar 29 '22 at 00:05

2 Answers2

8
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]

enter image description here

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

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896
5

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]

enter image description here

cvgmt
  • 72,231
  • 4
  • 75
  • 133