Find the intersection between two datasets

I create two arrays like this:

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

The second array has an offset to the first.

I would like to find the intersection space of both of these arrays A and B.

I used a spherical function in this case, but this can be done for any two data arrays that are not necessarily spherical. Is there any way to do this?

I include an image for what I am looking for. I want to find the intersection between these two areas. But the values ​​will not necessarily be the same as you can see.

If I have an equation for the limits of each of the spaces, will this alleviate the problem?

enter image description here

+6
source share
1 answer

I said in the comments that convhull and inpolygon can be used to solve this problem, only inpolygon does not seem to be applicable to 3D polygons. We will use delaunayTriangulation and pointLocation to get the result.

Full code:

 [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') 

Exit:

enter image description here

EDIT - 2D Example:

 [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'); 

Exit:

enter image description here

Edit 2:

If you want your code to automatically adapt to 2D or 3D arrays, you just need to change the plot calls. Just write an if that will check the number of columns in A and B

+9
source

All Articles