以下有三種方法:
1、如果是經度緯度數據的話,可以根據百度API來實現,具體請看:http://blog.csdn.net/c1481118216/article/details/52661934
2、如果是點數據的話,可以根據PNPoly算法來實現,具體請看: http://www.cnblogs.com/luxiaoxun/p/3722358.html、
3、這種想法是我自己想的,有待各位驗證。如果是邊數比較少量並且是凸邊形的話,可以求出每個邊的函數,利用多個函數的不等式組進行判斷
下面求x∈[-2,2],y∈[2-,2]區域中,所取的點是否落在三角形區域內,利用了四個不等式組如:x>0,y<x,y>1/2x,x<1.5,將落在三角形內的點標記爲紅色,其他爲藍色
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 22 09:25:34 2016
@author: Jemila
import matplotlib.pyplot as plt
import random
n = int(raw_input("Please input your number:"))
x=[random.uniform(-2,2) for i in range(n)]
y=[random.uniform(-2,2) for i in range(n)]
x1=[]
y1=[]
for i in range(n):
if y[i]<x[i] and x[i]>0 and 2*y[i]>x[i] and x[i]<1.5:
x1.append(x[i])
y1.append(y[i])
plt.plot(x,y,'bo')
plt.plot(x1,y1,'ro')
plt.show()