我对matlab不太熟悉,但我试图绘制一个平面(x + y + z = 1)与曲面的交点。表面是隐式定义的(x,y和z是alpha,beta的函数)。这是我的代码:
alpha = linspace(0,pi);
beta = linspace(0,pi);
[alpha,beta]=meshgrid(alpha,beta);
L= 4*exp(-.6*beta).*sin(alpha);
%转换为x,y,z坐标:
x = L.*sin(alpha).*cos(beta);
y = L.*cos(alpha);
z= L.*sin(alpha).*sin(beta);
绘制这个我通常会使用surf(x,y,z)。但在这种情况下,我想绘制其与平面的交点,例如由z2 = 1-x + y定义的平面。 (我不确定为新的x,y值定义单独的矩阵是否更好,或者是否更好地使用现有的矩阵。)我希望这个问题不会太混乱。如果您有任何建议,请帮忙。
答案 0 :(得分:0)
如果您尝试以下操作会怎么样:(我的代码基于前一个问题Plotting Implicit Algebraic equations in MATLAB的答案)并且它并不完美,但它可以帮助您:
clear
clc
alpha = linspace(0,pi);
beta = linspace(0,pi);
[alpha,beta]=meshgrid(alpha,beta);
L= 4*exp(-.6*beta).*sin(alpha);
x = L.*sin(alpha).*cos(beta);
y = L.*cos(alpha);
z= L.*sin(alpha).*sin(beta);
% Use an anonymous function to define the plane you want to plot
[X,Y] = meshgrid(min(x(:)):.5:max(x(:)),min(y(:)):0.5:max(y(:))); % x and y limits
f = @(X,Y) -X+Y+1; % sorry for the choice of capital letters; it was the most intuitive I thought.
hold on
surf(x,y,z);
contour3(X,Y,f(X,Y),200); % the 200 is arbitrary; play with it to change the # of lines making up the plane
hold off
rotate3d on
结果如下:
正如我所说,我不是百分之百的自信这是最强劲的方式,但它对我来说很好看:))