如何在MatLab中的两个曲面的交点处获取切片数据

问题描述 投票:1回答:1

我在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数组。也许我做错了什么,但它似乎没有用。

Two surfaces

matlab slice matlab-figure
1个回答
0
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.