Given coordinates of bottom-left and top-right corners of a rectangle. Check if a point (x, y) lies inside this rectangle or not.
Input: bottom-left: (0, 0), top-right: (10, 8), point: (1, 5)
Input: bottom-left: (-1, 4), top-right:(2, 3), point:(0, 4)
This problem is already discussed in a previous post. In this post we have discussed a new approach.
Approach: The above problem can be solved by observation. A point lies inside or not the rectangle if and only if it’s x-coordinate lies between the x-coordinate of the given bottom-right and top-left coordinates of the rectangle and y-coordinate lies between the y-coordinate of the given bottom-right and top-left coordinates.
Below is the implementation of the above approach:
- Check whether a given point lies on or inside the rectangle | Set 3
- Check whether a given point lies inside a rectangle or not
- How to check if a given point lies inside or outside a polygon?
- Check whether a point lies inside a sphere or not
- Check whether a given point lies inside a triangle or not
- Find a point that lies inside exactly K given squares
- Check if a given circle lies completely inside the ring formed by two concentric circles
- Check whether the point (x, y) lies on a given line
- Check if a point is inside, outside or on the parabola
- Check if a point is inside, outside or on the ellipse
- Check if a circle lies inside another circle or not
- Sum of Area of all possible square inside a rectangle
- Coordinates of rectangle with given points lie inside
- Count the number of rhombi possible inside a rectangle of given size
- Triangle with no point inside
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.