铅垂线内点法实现判断一个点与多边形区域之间的位置关系。
铅垂线内点法的基本思想是从待判别点向外引铅垂线,计算其与多边形交点的个数。若交点个数为奇数,则点在多边形内;若交点个数为偶数,则该点在多边形外。具体参见【王润科,张艳丽】的《判断多边形位置关系的算法综述》。
matlab代码
function result=area()
clear
clc
% the sequence points of an area. the last point is the same as the first one
areapoints=[116.293859, 39.983803
116.334411, 39.985055
116.334653, 39.98101
116.335607, 39.976502
116.337541, 39.975268
116.339567, 39.97489
116.340156, 39.966256
116.328224, 39.96611
116.315182, 39.965722
116.301885, 39.960507
116.300487, 39.968747
116.295395, 39.97214
116.293859, 39.983803];
plot(areapoints(1:end,1),areapoints(1:end,2));
n=length(areapoints)-1;
lines=[areapoints(1:end-1,:) areapoints(2:end,:)]; % all the border lines. save the two points of a line
lines
% for: the longitude of the first point must be less or equal to the second.
for i=1:n
if lines(i,1)>lines(i,3)
lines(i,: