フィルターのクリア

Plotting three planes and their intersections

14 ビュー (過去 30 日間)
Dimitrios Anagnostou
Dimitrios Anagnostou 2022 年 2 月 17 日
回答済み: Dimitrios Anagnostou 2022 年 2 月 17 日
I have three planes described the by the cartesian equations.
I want to plot the planes and their intersections.
I have written the following script which plots the planes and their point of intersection.
% premier plan
x1 = 0:0.5:10; x2 = 0:0.5:3;
[X Y] = meshgrid(x1,x2);
Z = 3-Y-(3/10)*X;
H1 = surf(X,Y,Z);
set(H1,'facecolor', 'r','FaceAlpha',0.3, 'EdgeColor' ,'none')
hold on
% deuxième plan
x1 = 0:0.5:2; x2 = 0:0.5:20;
[X Y] = meshgrid(x1,x2);
Z = 2-X-(1/10)*Y;
H2 = surf(X,Y,Z);
set(H2,'facecolor', 'b','FaceAlpha',0.3, 'EdgeColor','none')
% troisième plan
x1 = 0:0.5:5; x2 = 0:0.5:10;
[X Y] = meshgrid(x1,x2);
Z = 0.5*(1-(1/5)*X-(1/10)*Y);
H3 = surf(X,Y,Z);
set(H3,'facecolor', 'g','FaceAlpha',0.3, 'EdgeColor' ,'none')
% point d'intersection
A = [1/10, 1/3, 1/3; 1/2, 1/20, 1/2; 1/5, 1/10, 1/0.5]; C = [1, 1, 1]';
x_sol = A\C;
plot3(x_sol(1), x_sol(2), x_sol(3), 'k.', 'MarkerSize', 30)
xlabel('x'), ylabel('y'), zlabel('z')
axis square, grid on, grid minor, box on
xlabel('x_1'),ylabel('x_2'),zlabel('x_3')
set(gca,'FontSize',16)
xlim([0 10]) , ylim([0 20]), zlim([0 3])
set(gca, 'Xdir', 'reverse', 'YDir', 'reverse')
How can I plot the lines of intersection of the planes?
Thank you very much in advance.

採用された回答

Dimitrios Anagnostou
Dimitrios Anagnostou 2022 年 2 月 17 日
Finalement, I found the solution. I post the script in case anyoone is interested in.
clc, clear all close all
set(0,'defaultTextInterpreter','latex');
% visualisation des plans
% premier plan
x1 = 0:0.5:10; x2 = 0:0.5:3;
[X Y] = meshgrid(x1,x2);
Z = 3-Y-(3/10)*X;
H1 = surf(X,Y,Z);
set(H1,'facecolor', 'r','FaceAlpha',0.3, 'EdgeColor' ,'none')
hold on
% deuxième plan
x1 = 0:0.5:2; x2 = 0:0.5:20;
[X Y] = meshgrid(x1,x2);
Z = 2-X-(1/10)*Y;
H2 = surf(X,Y,Z);
set(H2,'facecolor', 'b','FaceAlpha',0.3, 'EdgeColor','none')
% troisième plan
x1 = 0:0.5:5; x2 = 0:0.5:10;
[X Y] = meshgrid(x1,x2);
Z = 0.5*(1-(1/5)*X-(1/10)*Y);
H3 = surf(X,Y,Z);
set(H3,'facecolor', 'g','FaceAlpha',0.3, 'EdgeColor' ,'none')
% point d'intersection
% point d'intersection
A = [1/10, 1/3, 1/3; 1/2, 1/20, 1/2; 1/5, 1/10, 1/0.5]; C = [1, 1, 1]';
X_sol = A\C;
plot3(X_sol(1), X_sol(2), X_sol(3), 'k.', 'MarkerSize', 30)
plot3(X_sol(1), X_sol(2), X_sol(3), 'k.', 'MarkerSize', 30)
% lines of intersections
% line of intersection of first two planes
% calculate intersection in plane z = 0
A1 = [ 1/10 1/3 ; 1/2 1/20 ];
B1 = [ 1; 1 ];
X1 = A1\B1;
P1 = [ X1; 0 ];
% calculate intersection in plane x = 0
A2 = [ 1/3 1/3 ; 1/20 1/2 ];
B2 = [ 1; 1 ];
X2 = A2\B2;
P2 = [ 0; X2 ];
P1P2 = [P1, P2];
line(P1P2(1,:), P1P2(2,:), P1P2(3,:), 'Color',...
'black', 'linewidth',1.5); view(3)
% line of interesection of first and third plane
% calculate intersection in plane z = 0
A1 = [ 1/10 1/3 ; 1/5 1/10 ];
B1 = [ 1; 1 ];
X1 = A1\B1;
P1 = [ X1; 0 ];
% calculate intersection in plane x = 0
A2 = [ 1/3 1/3 ; 1/10 1/0.5 ];
B2 = [ 1; 1 ];
X2 = A2\B2;
P2 = [ 0; X2 ];
P1P2 = [P1, P2];
line(P1P2(1,:), P1P2(2,:), P1P2(3,:), 'Color','black',...
'linewidth',1.5); view(3)
% line of interesection of second and third plane
% calculate intersection in plane z = 0
A1 = [ 1/2 1/20 ; 1/5 1/10 ];
B1 = [ 1; 1 ];
X1 = A1\B1;
P1 = [ X1; 0 ];
% calculate intersection in plane y = 0
A2 = [1/2 1/2; 1/5 1/0.5];
B2 = [ 1; 1 ];
X2 = A2\B2;
P2 = [X2(1); 0; X2(2)];
P1P2 = [P1, P2];
line(P1P2(1,:), P1P2(2,:), P1P2(3,:), 'Color',...
'black', 'linewidth',1.5); view(3)
% plot settings and labeling
axis square, grid on, grid minor, box on
xlabel('$x_1$'), ylabel('$x_2$'), zlabel('$x_3$')
set(gca,'FontSize',16)
xlim([0 10]) , ylim([0 20]), zlim([0 3])
set(gca, 'Xdir', 'reverse', 'YDir', 'reverse')
title({'Trois plans et leurs intersections',...
'$\frac{1}{10}x_1+\frac{1}{3}x_2+\frac{1}{3}x_3=1$ (red)',...
'$\frac{1}{2}x_1+\frac{1}{20}x_2+\frac{1}{2}x_3=1$ (blue)',...
'$\frac{1}{5}x_1+\frac{1}{10}x_2+\frac{1}{0.5}x_3=1$ (green)'})
hold off
set(0,'defaultTextInterpreter','none');

その他の回答 (1 件)

Matt J
Matt J 2022 年 2 月 17 日
First, you must compute the lines of intersection. Then you can use the line() command to add them to your plot.

カテゴリ

Help Center および File ExchangeVector Fields についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by