MATLAB 中隐函数 f(x,y,z)=0 的等高线
contours of an implicit function f(x,y,z)=0 in MATLAB
我已经知道如何使用 isosurface
函数绘制 3d 隐式函数 f(x,y,z)=0。现在我很好奇如何绘制它的轮廓。喜欢这个:
f(x,y,z) = sin((x.*z-0.5).^2+2*x.*y.^2-0.1*z) - z.*exp((x-0.5-exp(z-y)).^2+y.^2-0.2*z+3)
您可以在 Z 上用数字 运行 并查找符号何时更改,创建一个包含 Z 值的矩阵,这并不优雅,但它有效。
%Create function to evaluate
eq=eval(['@(x,y,z)',vectorize('sin((x*z-0.5)^2+2*x*y^2-0.1*z) - z*exp((x-0.5-exp(z-y))^2+y^2-0.2*z+3)'),';'])
%Create grid of x and y values
[x,y]=meshgrid(0:0.01:15,-2:0.01:2);
%Create dummy to hold the zero transitions
foo=zeros(size(x));
%Run over Z and hold the values where the sign changes
for i=0:0.001:0.04
aux=eq(x,y,i)>0;
foo(aux)=i;
end
%Contour those values
contour(foo)
编辑:我使用函数 scatteredInterpolant
找到了一个更优雅的解决方案
%Create function to evaluate
eq=eval(['@(x,y,z)',vectorize('sin((x*z-0.5)^2+2*x*y^2-0.1*z) - z*exp((x-0.5-exp(z-y))^2+y^2-0.2*z+3)'),';']);
%Create grid to evaluate volume
[xm,ym,zm]=meshgrid(0:0.1:15,-2:0.1:2,-0.01:0.001:0.04);
$Find the isosurface
s=isosurface(xm,ym,zm,eq(xm,ym,zm), 0);
$Use the vertices of the surface to create a interpolated function
F=scatteredInterpolant(s.vertices(:,1),s.vertices(:,2),s.vertices(:,3));
%Create a grid to plot
[x,y]=meshgrid(0:0.1:15,-2:0.1:2);
%Contour this function
contour(x,y, F(x,y),30)
我已经知道如何使用 isosurface
函数绘制 3d 隐式函数 f(x,y,z)=0。现在我很好奇如何绘制它的轮廓。喜欢这个:
f(x,y,z) = sin((x.*z-0.5).^2+2*x.*y.^2-0.1*z) - z.*exp((x-0.5-exp(z-y)).^2+y.^2-0.2*z+3)
您可以在 Z 上用数字 运行 并查找符号何时更改,创建一个包含 Z 值的矩阵,这并不优雅,但它有效。
%Create function to evaluate
eq=eval(['@(x,y,z)',vectorize('sin((x*z-0.5)^2+2*x*y^2-0.1*z) - z*exp((x-0.5-exp(z-y))^2+y^2-0.2*z+3)'),';'])
%Create grid of x and y values
[x,y]=meshgrid(0:0.01:15,-2:0.01:2);
%Create dummy to hold the zero transitions
foo=zeros(size(x));
%Run over Z and hold the values where the sign changes
for i=0:0.001:0.04
aux=eq(x,y,i)>0;
foo(aux)=i;
end
%Contour those values
contour(foo)
编辑:我使用函数 scatteredInterpolant
找到了一个更优雅的解决方案%Create function to evaluate
eq=eval(['@(x,y,z)',vectorize('sin((x*z-0.5)^2+2*x*y^2-0.1*z) - z*exp((x-0.5-exp(z-y))^2+y^2-0.2*z+3)'),';']);
%Create grid to evaluate volume
[xm,ym,zm]=meshgrid(0:0.1:15,-2:0.1:2,-0.01:0.001:0.04);
$Find the isosurface
s=isosurface(xm,ym,zm,eq(xm,ym,zm), 0);
$Use the vertices of the surface to create a interpolated function
F=scatteredInterpolant(s.vertices(:,1),s.vertices(:,2),s.vertices(:,3));
%Create a grid to plot
[x,y]=meshgrid(0:0.1:15,-2:0.1:2);
%Contour this function
contour(x,y, F(x,y),30)