//判断两条线段是否相交,线段1的两端坐标:point、point2 线段2的两端坐标:linePoint1、linePoint2
function isPointInLine(point,point2,linePoint1,linePoint2){
//判断两条线是否平行或者共线
var denominator = (point.y-point2.y)*(linePoint1.x-linePoint2.x)-(point2.x-point.x)*(linePoint2.y-linePoint1.y);
if(denominator==0)
return false;
//获取两条线延伸后的交点坐标
var x = ((point.x-point2.x)*(linePoint1.x-linePoint2.x)*(linePoint2.y-point2.y)+
(point.y-point2.y)*(linePoint1.x-linePoint2.x)*point2.x-(linePoint1.y-linePoint2.y)*(point.x-point2.x)*linePoint2.x)/denominator;
var y = -((point.y-point2.y)*(linePoint1.y-linePoint2.y)*(linePoint2.x-point2.x)+
(point.x-point2.x)*(linePoint1.y-linePoint2.y)*point2.y-(linePoint1.x-linePoint2.x)*(point.y-point2.y)*linePoint2.y)/denominator;
//判断交点是否在线段上
if((x-point2.x)*(x-point.x)<=0 && (y-point2.y)*(y-point.y)<=0 && (x-linePoint2.x)*(x-linePoint1.x)<=0 && (y-linePoint2.y)*(y-linePoint1.y)<=0)
return {x:x,y:y}
return false;
}
function isPointInPolygon(point,poly1){
var temppoly = poly1.split(",");
var poly = new Array();
for(var i = 0;i<temppoly.length/2;i++){
poly[i] = {x:temppoly[i*2],y:temppoly[i*2+1]};
}
//是否点在多边形里
var re=true;
if(poly.length>3){
var crossNum=0;
var point2 = {x:(poly[0].x-poly[1].x)/2,y:(poly[0].y-poly[1].y)/2}
for(var i=1;i<poly.length;i++){
if(i==poly.length-1){
if(isPointInLine(point,point2,poly[i],poly[0])){
crossNum++;
}
}else{
if(isPointInLine(point,point2,poly[i],poly[i+1])){
crossNum++;
}
}
}
if((crossNum % 2)==0){
re=false;
}
}
return re;
}
function isPointInLine(point,point2,linePoint1,linePoint2){
//判断两条线是否平行或者共线
var denominator = (point.y-point2.y)*(linePoint1.x-linePoint2.x)-(point2.x-point.x)*(linePoint2.y-linePoint1.y);
if(denominator==0)
return false;
//获取两条线延伸后的交点坐标
var x = ((point.x-point2.x)*(linePoint1.x-linePoint2.x)*(linePoint2.y-point2.y)+
(point.y-point2.y)*(linePoint1.x-linePoint2.x)*point2.x-(linePoint1.y-linePoint2.y)*(point.x-point2.x)*linePoint2.x)/denominator;
var y = -((point.y-point2.y)*(linePoint1.y-linePoint2.y)*(linePoint2.x-point2.x)+
(point.x-point2.x)*(linePoint1.y-linePoint2.y)*point2.y-(linePoint1.x-linePoint2.x)*(point.y-point2.y)*linePoint2.y)/denominator;
//判断交点是否在线段上
if((x-point2.x)*(x-point.x)<=0 && (y-point2.y)*(y-point.y)<=0 && (x-linePoint2.x)*(x-linePoint1.x)<=0 && (y-linePoint2.y)*(y-linePoint1.y)<=0)
return {x:x,y:y}
return false;
}
function isPointInPolygon(point,poly1){
var temppoly = poly1.split(",");
var poly = new Array();
for(var i = 0;i<temppoly.length/2;i++){
poly[i] = {x:temppoly[i*2],y:temppoly[i*2+1]};
}
//是否点在多边形里
var re=true;
if(poly.length>3){
var crossNum=0;
var point2 = {x:(poly[0].x-poly[1].x)/2,y:(poly[0].y-poly[1].y)/2}
for(var i=1;i<poly.length;i++){
if(i==poly.length-1){
if(isPointInLine(point,point2,poly[i],poly[0])){
crossNum++;
}
}else{
if(isPointInLine(point,point2,poly[i],poly[i+1])){
crossNum++;
}
}
}
if((crossNum % 2)==0){
re=false;
}
}
return re;
}