I want to know if a point is inside or outside a square
A point has 2 attributes, positions at 'X' and 'Y'.
A square has 4 attributes: position X, Y, base, height.
How can you know if the point is inside or outside?
I want to know if a point is inside or outside a square
A point has 2 attributes, positions at 'X' and 'Y'.
A square has 4 attributes: position X, Y, base, height.
How can you know if the point is inside or outside?
To know if a Point is inside a square, the following must be checked:
In the following example I check with 2 points for the two cases (point inside the square and the opposite case).
Do you consider that if it is touching the border, is it inside or outside? This is important at the moment of knowing if it is < or <= what you want to catch as inside or outside.
To begin with, in a square it holds:
So I'm assuming you're talking about any quadrilateral, a rectangle.
AX you add the base and you get X+b. AY you add the height and you get Y+a.
You have to explain well and know 1. Your coordinate system, where does the value of X and Y increase? to the right and up? right and down? Because the sign of the operations has to do with this.
Generally, the point (x1, y1) will be inside the square if: (considering that the point on the border is included in the square)
And considering that the point on the border is NOT included in the square:
But you have to take into account your coordinate system.
All the best