我需要找到我在双层蜂窝网络的六边形边界内随机生成的点数。边界是不规则的形状。
我将展示我的代码示例而不是完整代码:
final_y = [750 500 250 0 -250 -500 -750 -750 -1000 -1000 -1250 -1250 -1000 -1000 -750 -750 -500 -250 0 250 500 750 750 1000 1000 1250 1250 1000 1000 750 750]
final_y1 = final_y'
XX =[1010;1155;1010;1155;1010;1155;1010;721.7;577.4;288.7;144.3;-144.3;-288.7;-577.4;-721.7;-1010;-1155;-1010;-1155;-1010;-1155;-1010;-721.7;-577.4;-288.7;-144.3;144.3;288.7;577.4;721.7;1010]
boundary = mx_min+(mx_max-mx_min)*rand(1,100);
boundary2 = my_min+(my_max-my_min)*rand(1,100);
figure(2)
plot(XX,final_y1)
hold on
%plot(boundary,boundary2,'or')
hold on
xv = [mx_max mx_min];
yv = [my_max my_min];
[in,on] = inpolygon(boundary,boundary2,xv,yv);
hold on
plot(boundary,boundary2,'bo',xv,yv,'ro');
我需要找到该边界内的点数。
答案 0 :(得分:1)
正如您已经指出的那样,inpolygon
函数确定每个点是否在给定多边形的内部或外部。您现在要做的只是计算指标向量中true
条目的数量:
[in,on] = inpolygon(boundary, boundary2, XX, final_y);
numPointsIn = sum( in );
numPointsOn = sum( on );