如何创建曲面图的一部分来创建一条线? (Matlab)
How can I create a slice of a surface plot to create a line? (Matlab)
给定一些函数 z = f(x,y),我有兴趣沿着 x,y,z 中的任意切割平面创建 (1D) 线图。我如何在 Matlab 中执行此操作?例如,Slice 提供了更高维度的版本(密度数据的颜色图),但这不是我要找的。
例如:
z = peaks(50);
surf(z);
%->plot z along some defined plane in x,y,z...
这已经被问过,例如here,但是这个给出的答案是将3D数据还原为2D数据,谷歌搜索也没有明显的答案。谢谢
如果要对表面进行切片的平面的法向量始终位于 xy 平面中,则可以沿切片线中的 x、y 坐标在表面上插值数据,例如, 将平面定义为从点 (0,15) 到点 (50,35)
% Create Data
z=peaks(50);
% Create x,y coordinates of the data
[x,y]=meshgrid(1:50);
% Plot Data and the slicing plane
surf(z);
hold on
patch([0,0,50,50],[15,15,35,35],[10,-10,-10,10],'w','FaceAlpha',0.7);
% Plot an arbitrary origin axis for the slicing plane, this will be relevant later
plot3([0,0],[15,15],[-10,10],'r','linewidth',3);
因为是平面,相对比较容易得到切片平面的x,y坐标linspace
,我取100个点,然后把这100个点插值到原始数据中。
% Create x and y over the slicing plane
xq=linspace(0,50,100);
yq=linspace(15,35,100);
% Interpolate over the surface
zq=interp2(x,y,z,xq,yq);
现在我们有了 z 的值,我们需要根据什么来绘制它们,这就是您需要为拼接平面定义任意原点轴的地方,为了方便起见,我将我的定义为 (0,15) , 然后计算每对 x,y 到这个轴的距离,然后我们可以根据这个距离绘制得到的 z。
dq=sqrt((xq-0).^2 + (yq-15).^2);
plot(dq,zq)
axis([min(dq),max(dq),-10,10]) % to mantain a good perspective
给定一些函数 z = f(x,y),我有兴趣沿着 x,y,z 中的任意切割平面创建 (1D) 线图。我如何在 Matlab 中执行此操作?例如,Slice 提供了更高维度的版本(密度数据的颜色图),但这不是我要找的。
例如:
z = peaks(50);
surf(z);
%->plot z along some defined plane in x,y,z...
这已经被问过,例如here,但是这个给出的答案是将3D数据还原为2D数据,谷歌搜索也没有明显的答案。谢谢
如果要对表面进行切片的平面的法向量始终位于 xy 平面中,则可以沿切片线中的 x、y 坐标在表面上插值数据,例如, 将平面定义为从点 (0,15) 到点 (50,35)
% Create Data
z=peaks(50);
% Create x,y coordinates of the data
[x,y]=meshgrid(1:50);
% Plot Data and the slicing plane
surf(z);
hold on
patch([0,0,50,50],[15,15,35,35],[10,-10,-10,10],'w','FaceAlpha',0.7);
% Plot an arbitrary origin axis for the slicing plane, this will be relevant later
plot3([0,0],[15,15],[-10,10],'r','linewidth',3);
因为是平面,相对比较容易得到切片平面的x,y坐标linspace
,我取100个点,然后把这100个点插值到原始数据中。
% Create x and y over the slicing plane
xq=linspace(0,50,100);
yq=linspace(15,35,100);
% Interpolate over the surface
zq=interp2(x,y,z,xq,yq);
现在我们有了 z 的值,我们需要根据什么来绘制它们,这就是您需要为拼接平面定义任意原点轴的地方,为了方便起见,我将我的定义为 (0,15) , 然后计算每对 x,y 到这个轴的距离,然后我们可以根据这个距离绘制得到的 z。
dq=sqrt((xq-0).^2 + (yq-15).^2);
plot(dq,zq)
axis([min(dq),max(dq),-10,10]) % to mantain a good perspective