0

I am trying to find the intersection between two planes in MATLAB.

x = -10:10;
y = x;

[X Y] = meshgrid(x,y);
Z1 = 3+X+Y;
Z2 = 4-2.*X-4.*Y;

mesh(X,Y,Z1)
hold on
mesh(X,Y,Z2)

I know I can find the locations of the elements of Z1 and Z2 where they are equal by setting a new array equal to (Z1==Z2), but that only gives me an arrays of 0s and 1s. How do I find the array containing the actual values of the line segment?

4

3 回答 3

3

The following equation results from setting Z1=Z2:

3+X+Y=4-2X-4Y

solve it and you will get the equation of the intersection line.

于 2012-09-17T18:39:16.380 回答
0

The output from Z1 == Z2 is a logical array that can be used to index into Z1 or Z2. This will give you the array of points you are after, if I understood the question. If this is homework, I can't imagine that an array of points would be a valid answer, so you may want to include the motivation for this question.

于 2012-09-17T18:37:41.910 回答
0

If I understand the question correctly, you are asking what is the syntax to use logicals to index a matrix? If so, no one has provided it thus far, so here it is:

S = Z1(Z1 == Z2);

Or equivalently in your case, S = Z2(Z1 == Z2). This is essentially what macduff is talking about, but without providing the syntax (sorry macduff I would have made this a comment on your answer but I don't have the rep).

于 2012-09-18T00:04:00.287 回答