The problem I described in this blog post was about intersecting two implicit surfaces. That's not what you're trying to do here, but the solution I described actually works. The reason is that the approach I described was to create a mesh from the first implicit surface and then intersect that with the second. In your case, you have a mesh already, and the surface you want to intersect it with is simply So, let's sneak up on it. We'll start with this:
[x,y] = meshgrid(-2:0.25:2,-2:0.25:2);
z = x.*exp(-x.^2-y.^2);
mesh(x,y,z)
Now we'll insert those vertices into our implicit equation.
We can look at what we have like this:
surf(x,y,z,t,'FaceColor','interp')
colormap(lines(6))
So we want the line between the purple and the orange. On simple way of getting that would be this:
tol = 1e-8;
mask = abs(t) < tol;
x2 = x(mask);
y2 = y(mask);
z2 = z(mask);
plot3(x2,y2,z2)
Notice that I didn't compare t to 0 exactly. That's to avoid roundoff error problems.
Now we'll go back to 2D.
And you have a plot of the diagonal. That's pretty simple. It's actually too simple.
That only worked in this case because the points of the mesh actually lay on the diagonal. If you used some other implicit function you would have found that it went in between the points of your mesh and the mask didn't select any. In that case you need to find points which are on opposite sides of the line and compute the X,Y,Z where they edge connecting them crosses the line. That's what I was describing in that blog post . I'll leave that step as an exercise for you. The one hint is that I had a triangle mesh in that case, but you've got a quad mesh. That means that your case will be a little different where it comes to identifying edges that connect points on opposite sides. Does that give you a good enough start?