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:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Check whether a given point lies inside a rectangle or not
- Check whether a given point lies on or inside the rectangle | Set 3
- 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
- Check if the given point lies inside given N points of a Convex Polygon
- 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 if a given circle lies completely inside the ring formed by two concentric circles
- Check if a circle lies inside another circle or not
- Check whether the point (x, y) lies on a given line
- Count of integral coordinates that lies inside a Square
- Check if any point overlaps the given Circle and Rectangle
- Check if a point is inside, outside or on the ellipse
- Check if a point is inside, outside or on the parabola
- Largest subset of rectangles such that no rectangle fit in any other rectangle
- Maximum area of a Rectangle that can be circumscribed about a given Rectangle of size LxW
- Coordinates of rectangle with given points lie inside
- Sum of Area of all possible square inside a rectangle
- Find the number of rectangles of size 2*1 which can be placed inside a rectangle of size n*m
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.