I have a rectangle Rect (x,y,w,h) and a point P (px, py).
x and y are the top left coordinate of the rectangle.
w is it’s width.
h is it’s height.
px and py are the coordinate of the point P.
Does anyone knows the algorithm to check if P lies inside Rect.
Surprisingly, I couldn’t find any correct answer for my question on the internet.
Much appreciate!
>Solution :
use this piece of code:
#include <iostream>
int main()
{
int x, y, w, h;
std::cin >> x >> y >> w >> h;
int px, py;
std::cin >> px >> py;
if(px >= x && px <= (x + w) && py <= y && py >= (y - h))
std::cout << "point is in the rectangle";
else
std::cout << "point is out of the rectangle";
}