别人的问题,
两个点集都有不少点。
要找这两个点集相交的集合。
By the way, I will be dead soon. So if u have problem about this code, contact me please.
meatball1982@163.com.
- clear all
- clc
- clf
- load('../data/data1.mat');
- load('../data/data2.mat');
- a=M6ofR2;
- b=M6ofR3;
- clear M6ofR2 M6ofR3
- % choose part of the points
- ind1 = a(:,1) > -6 & a(:,1) < -2 & a(:,2) > 2 & a(:,2) < 5 ;
- ind2 = b(:,1) > -6 & b(:,1) < -2 & b(:,2) > 2 & b(:,2) < 5 ;
- p1= a(ind1,:);
- p2= b(ind2,:);
- % the multi distance of two point sets
- D = pdist2(p1,p2);
- % chose intersect part (with radius 0.1)
- indsmall1 = min(D)<0.1;
- p2(~indsmall1,:)=[];
- indsmall2 = min(D')<0.1;
- p1(~indsmall2,:)=[];
- %
- points1=p1;
- points2=p2;
- %
- [chull1,cf1,df1]=convhull_nd(points1);
- inconvhull1=~any(cf1*points2'+df1(:,ones(1,size(points2,1)))>0,1);
- inter_points1=points2(inconvhull1,:);
- [chull2,cf2,df2]=convhull_nd(points2);
- inconvhull2=~any(cf2*points1'+df2(:,ones(1,size(points1,1)))>0,1);
- inter_points2=points1(inconvhull2,:);
- % inter points
- inter_points=[inter_points1;inter_points2];
- % the boundary of inter points
- k_all=boundary(inter_points,0.8);
- x_bou = inter_points(k_all,1);
- y_bou = inter_points(k_all,2);
- h=figure(1)
- set(h, 'Position', [1000, 100, 900, 800]);
- hold on
- plot(a(:,1),a(:,2),'c.')
- plot(b(:,1),b(:,2),'m.')
- plot(points1(:,1),points1(:,2),'o','MarkerEdgeColor','b','LineWidth',2)
- plot(points2(:,1),points2(:,2),'o','MarkerEdgeColor','r','LineWidth',2)
- plot(inter_points(:,1),inter_points(:,2),'s','MarkerEdgeColor','g','LineWidth',1,'markersize',10);
- plot(x_bou,y_bou,'k-','linewidth',3)
- leg_str={'dat 1','dat 2','int part in dat 1','int part in dat 2',' int points','boundary points'};
- legend(leg_str,'location','northwest')
复制代码
需要几个函数。
|