%% 想要在给定区域内随机均匀分布一定数量的点
% 网上有这样的方式
load('usborder.mat','x','y','xx','yy');
figure
plot(x,y,'Color','red...plot(xx,yy,'b--')
cities = 40;
locations = zeros(cities,2);
n = 1;
while (n <= cities)
% 随机产生包络矩形区域内的点...xp = rand*1.5;
yp = rand;
if inpolygon(xp,yp,xx,yy)
% 如果在给定区域内就保留
locations...% 但是这样并不均匀
%% 有个科学的方式可以在凸多边形中均匀分布点
% 先在三角形内实现均匀
a = [1.0,0.5];
b = [0.7,0.2];
c = [0.3,0.8];
triangle...%% 将凸多边形分割为多个三角形
polygone = [0,0;1,0;10,1;30,8;20,8;0,5] ;
% 调用函数分布100个点
points = randPolygone(polygone