Write a function that takes 4 coordinates of the Rectangle and a point P as a parameter. Your function should be able to tell whether P lies inside the Rectangle, On the Rectangle, or Outside rectangle. Sample Input:
P1 0 0
P2 2 0
P3 2 2
P4 0 2
P 1 1
Output: P lies inside Square
// CPP program to Check if a
// point lies on or inside a rectangle | Set-2
#include <bits/stdc++.h>
using namespace std;
// function to find if given point
// lies inside a given rectangle or not.
bool FindPoint(int x1, int y1, int x2,
			int y2, int x, int y)
{
	if (x > x1 and x < x2 and y > y1 and y < y2)
		return true;
	return false;
}
// Driver code
int main()
{
	// bottom-left and top-right
	// corners of rectangle
	int x1 = 0, y1 = 0, x2 = 10, y2 = 8;
	// given point
	int x = 1, y = 5;
	// function call
	if (FindPoint(x1, y1, x2, y2, x, y))
		cout << "P lies inside Rectangle";
	else
		cout << "P lies outside Rectangle";
	return 0;
}
Comments