I have this matrix
/// as if the create a rectangle
int [][] loc = {
{5, 15},//(x1, y1)
{5, 30}, // (x1, y2)
{20, 15},// (x2, y1)
{20, 30}, // (x2,
The code in the question is Java or C or some other language that defines array literals with {}, but since the tag is Javascript and this shows up on Google for Javascript, here is a reasonable way to do point-rectangle intersection in JS.
function pointRectangleIntersection(p, r) {
return p.x > r.x1 && p.x < r.x2 && p.y > r.y1 && p.y < r.y2;
}
var point = {x: 1, y: 2};
var rectangle = {x1: 0, x2: 10, y1: 1, y2: 7};
pointRectangleIntersection(point, rectangle);
As mentioned in the comments, change >
to >=
and/or <
to <=
to do an intersection which includes the rectangle boundaries.