How do you plot the line of intersection between two planes in MATLAB
13 views (last 30 days)
Show older comments
Hey, my planes are:
>> Z1 = 2 -X + Y;
>> Z2 = (X + 3*Y -3)/2;
I've plotted them, but I'm not sure how to plot the line of intersection between them. I found it by hand, but its a 3 way equation:
27-12*X = 4*Y - 1=3*Z
This doesnt seem right to me. And I'm not sure what to do with it.
Would anyone be able to help me with how to plot the point of intersection between two planes.
My code for plotting the two planes so far is:
>> [X,Y] = meshgrid(0:0.01:5,0:0.01:5);
>> Z = X.^2 + Y.^2;
>> Z1 = 2 -X + Y;
>> Z2 = (X + 3*Y -3)/2;
>> surf(X,Y,Z1);
>> hold on
>> surf(X,Y,Z2);
>> shading interp
The question specified domains for X, Y and Z which is the reason for the restrictions on the variables in the meshgrid function.
1 Comment
Walter Roberson
on 31 May 2019
Equate the two z values to find the intersection
2 -X + Y == (X + 3*Y -3)/2
re-arrange terms and you can get y in terms of x.
Then you can substitute that y definition into Z1 to get Z in terms of x.
Y and Z are now linear equations in X, and you can plot3() that.
Answers (1)
KSSV
on 31 May 2019
[X,Y] = meshgrid(0:0.01:5,0:0.01:5);
Z = X.^2 + Y.^2;
Z1 = 2 -X + Y;
Z2 = (X + 3*Y -3)/2;
surf(X,Y,Z1);
hold on
surf(X,Y,Z2);
shading interp
zdiff = Z1 - Z2;
C = contours(X, Y, zdiff, [0 0]);
% Extract the x- and y-locations from the contour matrix C.
xL = C(1, 2:end);
yL = C(2, 2:end);
% Interpolate on the first surface to find z-locations for the intersection
% line.
zL = interp2(X, Y, Z1, xL, yL);
% Visualize the line.
line(xL, yL, zL, 'Color', 'r', 'LineWidth', 3);
1 Comment
Álvaro Pardo
on 3 Feb 2021
Edited: Álvaro Pardo
on 3 Feb 2021
Hello KSSV,
I have found your code very useful. Thanks for sharing it! However, it does not work for my purposes. I am currently trying to intersect two surfaces, one irregular and another smooth and regular. The X and Y coordinates are the same for both and, of course, the Z differs. Although one surface crosses the other, their nodes never coincide. This is why I did not manage to find a quick and precise solution to get the intersection points.
What I have been trying to do so far is to select the nodes whose height difference is closer to zero. Since there exist two intersection lines (I am trying to generate a sort of closed duct), I then generate both surfaces again using the intersection lines as baseline.
I am attaching to this post the X,Y and Z matrices. Maybe you (or anyone else) can help me to find out a better solution.
Many thanks in advance for the help!
Álvaro
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!