检查矩形内部或外部的x和y坐标 我有四个坐标NE,SW,NW,SE如果x和Y坐标在这个four_coordinates函数中相交为true,否则它应该是false 如果x和Y值不在这四个坐标内,它应该返回false但是我得到了真; 这个小提琴显示该函数当前返回true。
jsFiddle here https://jsfiddle.net/uwv249vc/
function is_inside(point, loc) {
var x_min = 12.306879896962968,
x_max = 76.66268348693848,
y_min = 12.297236015659891,
y_max = 76.67736053466797
var x =12.283985584345864,
y = 76.67015075683594;
var top_left = [x_min, y_min],
top_right = [x_max, y_max],
bottom_left = [x_max, y_min],
bottom_right = [x_min, y_max];
console.log("top_left : " + top_left);
console.log("top_right : " + top_right);
console.log("bottom_left : " + bottom_left);
console.log("bottom_right : " + bottom_right);
var rectangle_value = [top_left, bottom_left, bottom_right, top_right];
console.log("rectangle_value" + rectangle_value);
for (var i = 0, j = rectangle_value.length - 1; i < rectangle_value.length; j = i++) {
var xi = rectangle_value[i][0],
yi = rectangle_value[i][1];
var xj = rectangle_value[j][0],
yj = rectangle_value[j][1];
console.log("xi :" + xi + "yi :" + yi);
console.log("xj :" + xj + "yj :" + yj);
var intersect = ((yi > y) != (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
return intersect;
}
}
console.log(is_inside()) //this must be false