首页 > 解决方案 > 如何在 MatLab 中的两个曲面的交点处获取切片数据

问题描述

我在 NxMxP 数组中有流数据,我想在两个表面的交点处找到数据的值。目前,我正在使用平面和圆柱体,但将来我想使用其他形状并在可能的情况下找到相交弧上的数据。

下面是飞机和圆柱体的图片,以及我制作它们的代码。红线是我想要获取数据的交叉点。

AR = 5;    R = 2.5;
Ny = 200;
% generate plane
[x, y] = meshgrid(-(AR+1):(AR+1)/Ny:0, ...
        -0.7344:(0.7031- -0.7344)/Ny:0.7031); % Generate x and y data
z = zeros(size(x, 1)); % Generate z data
% I needed to rotate the plane by an angle about y-axis for my purposes
V1 = [reshape(x,1,(Ny+1)^2);
    reshape(y,1,(Ny+1)^2);
    reshape(z,1,(Ny+1)^2)];
dphi = 7.5;    % angle to rotate in degrees
MR = [cosd(dphi) 0 -sind(dphi);...
    0 1 0;...
    sind(dphi) 0 cosd(dphi)];
% slice going through the center of the wing
VR1 = MR*V1;
xP = reshape(VR1(1,:),Ny+1,Ny+1);
yP = reshape(VR1(2,:),Ny+1,Ny+1);
zP = reshape(VR1(3,:),Ny+1,Ny+1);

% generate cylinder
Nt = floor(2.1*Ny*R);   % specify the number of nodes along the tangential axis
[Xc,Zc,Yc] = cylinder(R*ones(1,Ny),Nt);
% matrix for correcting the height of cylindrical slice
ty = -0.7344;
sy = 0.7031 - -0.7344;
Mt = [1 0 0 0;
    0 1 0 ty;   % vertical translation
    0 0 1 0;
    0 0 0 1];
Ms = [1 0 0 0;
    0 sy 0 0;   % vertical stretching
    0 0 1 0;
    0 0 0 1];
H = Mt*Ms*[ones(1,Ny);Yc(:,1)';ones(1,Ny);ones(1,Ny)];
Yc = repmat(H(2,1:Ny)',1,Nt+1);

% draw figure
figure
hold on
h1 = slice(Xw,Yw,Zw,ur,xP,yP,zP,'linear');
plane_sli = h1.CData;
set(plane_sli,'edgecolor','none')
h2 = slice(Xw,Yw,Zw,ur,Xc,Yc,Zc,'linear');
cyl_sli = h2.CData;
set(cyl_sli,'edgecolor','none')
axis equal

附加工作:尝试inShape 遵循 MathWorks 网站上关于 inShape 的说明,如下所示。

shp = alphaShape(xP(:),yP(:),zP(:));
tf = inShape(shp,xC(:),yC(:),zC(:));

tf变量只是一个空 ( Nt* Ny) x 1 数组。也许我做错了什么,但它似乎不起作用。

两个表面

标签: matlabslicematlab-figure

解决方案


这是一个开始:您可以在平面 (Xa,Ya,Za) 上进行迭代,并使用 inShape 查看它与圆柱体 (Xb,Yb,Zb) 相交的位置;请参阅https://www.mathworks.com/matlabcentral/answers/392798-finding-intersecting-points-of-two-3d-bodies

将来,您可以将其概括为迭代可能是平面的横截面(例如长方体),然后尝试使用二进制搜索,这样您就不必遍历所有横截面。有趣的问题!


推荐阅读