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:
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Check whether a given point lies on or inside the rectangle | Set 3
- Check whether a given point lies inside a rectangle or not
- Check whether a given point lies inside a triangle 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
- Find a point that lies inside exactly K given squares
- Find if a point lies inside, outside or on the circumcircle of three points A, B, C
- Check whether the point (x, y) lies on a given line
- Check if a given circle lies completely inside the ring formed by two concentric circles
- Check if a point is inside, outside or on the ellipse
- Check if a point is inside, outside or on the parabola
- Check if any point overlaps the given Circle and Rectangle
- Check if a circle lies inside another circle or not
- Count of integral coordinates that lies inside a Square
- Sum of Area of all possible square inside a rectangle
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.