繁体   English   中英

找到两个数据集之间的交集

[英]Find intersection between two data sets

我正在生成两个类似于此的数组:

[x,y,z] = sphere;
A=[x,y,z]
B=[x+0.5,y+0.5,z+0.5]

第二个数组与第一个数组偏移。

我想找到这两个阵列A和B的交叉空间。

在这种情况下我使用了球体函数,但是这可以用于任何两个数据数组,不一定是球形的。 有没有办法做到这一点?

我正在寻找我正在寻找的图像。 我想找到这两个区域之间的交集。 但是价值观不一定与你所看到的相同。

如果我有一个关于每个空间限制的等式,那会使问题更容易吗?

在此输入图像描述

我在一个可以使用注释中规定convhullinpolygon来解决这个问题,只能inpolygon似乎并不适用于3D多边形。 我们将使用delaunayTriangulationpointLocation来获得结果

完整代码:

[x,y,z] = sphere;
A=[x(:),y(:),z(:)];
B=[x(:)+0.5,y(:)+0.5,z(:)+0.5];

tess1=delaunayTriangulation(A); % delaunay Triangulation of points set A
tess2=delaunayTriangulation(B); % delaunay Triangulation of points set B

Tmp=[A;B];

% Point location searches for the triangles in the given delaunay     
% triangulation that contain the points specified in Tmp, here Tmp is 
% the reunion of sets A and B and we check for both triangulations
ids1=~isnan(pointLocation(tess1,Tmp));
ids2=~isnan(pointLocation(tess2,Tmp));

% ids1&ids2 is a logical array indicating which points
% in Tmp are in the intersection
IntersectPoints=Tmp(ids1&ids2,:);


plot3(A(:,1),A(:,2),A(:,3),'+b'); hold on
plot3(B(:,1),B(:,2),B(:,3),'+g');
plot3(IntersectPoints(:,1),IntersectPoints(:,2),IntersectPoints(:,3),'*r')

输出:

在此输入图像描述

编辑 - 2D示例:

[x,y,z] = sphere;
A=[x(:),y(:)];
B=[x(:)+0.5,y(:)+0.5];

tess1=delaunayTriangulation(A); % delaunay Triangulation of points set A
tess2=delaunayTriangulation(B); % delaunay Triangulation of points set B

Tmp=[A;B];

% Point location searches for the triangles in the given delaunay     
% triangulation that contain the points specified in Tmp, here Tmp is 
% the reunion of sets A and B and we check for both triangulations
ids1=~isnan(pointLocation(tess1,Tmp));
ids2=~isnan(pointLocation(tess2,Tmp));

% ids1&ids2 is a logical array indicating which points
% in Tmp are in the intersection
IntersectPoints=Tmp(ids1&ids2,:);


plot(A(:,1),A(:,2),'+b'); hold on
plot(B(:,1),B(:,2),'+g');
plot(IntersectPoints(:,1),IntersectPoints(:,2),'*r');

输出:

在此输入图像描述

编辑2:

如果您希望代码自动适应2D或3D数组,您只需要修改绘图调用。 只需编写一个if语句来检查A和B中的列数

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM