matlab----三维曲面 (mesh 或者 surf) 上截取三维曲线(沿x轴方向,沿y轴方向,平行于xoy平面,对角线方向)
clear allclose allclc% generate the data in domain [-1,1]N_points = 500;X = linspace(-1,1,500);Y = linspace(-1,1,500);[meshX,meshY] = meshgrid(X,Y);meshU = sin(meshX.^2+meshY.^2);% construct the mesh
·
clear all
close all
clc
% generate the data in domain [-1,1]
N_points = 500;
X = linspace(-1,1,500);
Y = linspace(-1,1,500);
[meshX,meshY] = meshgrid(X,Y);
% construct the mesh solution by meshgrid of XY
meshU = sin(meshX.^2+meshY.^2);
% plot the mesh solution
figure('name','meshU')
mesh(meshX, meshY, meshU);
hold on
xlabel('x')
ylabel('y')
zlabel('u')
% extracting the diagonal parts from [-1,-1] to [1,1]
size2cutslice = size(meshU,1);
utrue_cut = zeros(size2cutslice, 1);
cutX_coord = zeros(size2cutslice, 1);
cutY_coord = zeros(size2cutslice, 1);
row = 30;
for i=1:size2cutslice
meshu_cut(i,1) = meshU(i,i);
cutX_coord(i,1) = meshX(i,i);
cutY_coord(i,1) = meshY(i,i);
end
plot3(cutX_coord, cutY_coord, meshu_cut, 'r*', 'linewidth', 2)
hold on
% extracting the cut line for a given xcoord
size2cutslice2 = size(meshU,1);
utrue_cut1 = zeros(size2cutslice2, 1);
cutX_coord1 = zeros(size2cutslice2, 1);
cutY_coord1 = zeros(size2cutslice2, 1);
row = 250;
for i=1:size2cutslice
meshu_cut1(i,1) = meshU(i,row);
cutX_coord1(i,1) = meshX(i,row);
cutY_coord1(i,1) = meshY(i,row);
end
plot3(cutX_coord1, cutY_coord1, meshu_cut1, 'b+', 'linewidth', 2)
hold on
figure('name','cutline')
plot(meshu_cut, 'b--', 'linewidth', 2)
hold on
plot(meshu_cut1, 'm:', 'linewidth', 2)
hold on
% 对于沿固定的y轴方向,类似上述操作。
% 对于截取平行于xoy平面的曲线使用 matlab自带命令 contour 就好
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
已为社区贡献5条内容
所有评论(0)