Ok, so all we have is
plot = ContourPlot[{g[x, y, 0] == 0, f[x, y, 0] == 0}, {x, -10, 10}, {y, -10, 10}]
In order to view all of the information we have about the curves we can use FullForm[plot]
. We see that we have all of the points that make up the lines, and that they are wrapped by Line
. We can extract the points like this:
lines = Cases[Normal[plot], _Line, Infinity];
{pts1, pts2} = lines /. Line -> Identity;
We now have the points corresponding to each of the lines. In order to find the intersection between the lines it would be suitable to linearly interpolate between the points. In order to interpolate with Interpolation
we need to introduce an independent variable, and I will introduce the distance along the curve as that independent variable.
createInterpolation[pts_] := Interpolation[Transpose[{
Prepend[0]@Accumulate@Map[Norm, Differences@pts],
pts
}], InterpolationOrder -> 1]
curve1 = createInterpolation[pts1];
curve2 = createInterpolation[pts2];
We can plot the interpolated functions to see that we got it right:
Show[
ParametricPlot[curve1[d], {d, 0, 23.9}],
ParametricPlot[curve2[d], {d, 0, 9.48},
PlotStyle -> ColorData[97][2]],
PlotRange -> 10, Axes -> False, Frame -> True
]
Now that we have functions that are continuous over the relevant domain, we can use NMinimize
to find the intersections.
sol1 = Last@NMinimize[{
Norm[curve1[d1] - curve2[d2]]^2,
0 < d1 < 23.9 && 0 < d2 < 9.49
}, {d1, d2}]
{d1 -> 12.2012, d2 -> 4.63393}
To find the other intersection we can change the constraints to exclude the intersection that has already been found:
sol2 = Last@NMinimize[{
Norm[curve1[d1] - curve2[d2]]^2,
0 < d1 < 10 && 0 < d2 < 9.48
}, {d1, d2}]
{d1 -> 8.97608, d2 -> 9.48}
Finally we can plot the solutions to gauge whether they are correct:
Show[
ParametricPlot[curve1[d], {d, 0, 23.9}],
ParametricPlot[curve2[d], {d, 0, 9.48},
PlotStyle -> ColorData[97][2]],
PlotRange -> 10, Axes -> False, Frame -> True,
Epilog -> {
Red, PointSize[Large],
Point[{curve1[d1] /. sol1, curve1[d1] /. sol2}]
}
]