- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check if a point lies on or inside a rectangle in Python
Suppose we have a rectangle represented by two points bottom-left and top-right corner points. We have to check whether a given point (x, y) is present inside this rectangle or not.
So, if the input is like bottom_left = (1, 1), top_right = (8, 5), point = (5, 4), then the output will be True
To solve this, we will follow these steps −
- Define a function solve() . This will take bl, tr, p
- if x of p > x of bl and x of p < x of tr and y of p > y of bl and y of p < y of tr, then
- return True
- otherwise,
- return False
Let us see the following implementation to get better understanding −
Example
def solve(bl, tr, p) : if (p[0] > bl[0] and p[0] < tr[0] and p[1] > bl[1] and p[1] < tr[1]) : return True else : return False bottom_left = (1, 1) top_right = (8, 5) point = (5, 4) print(solve(bottom_left, top_right, point))
Input
(1, 1), (8, 5), (5, 4)
Output
True
- Related Articles
- How To Check if a Given Point Lies Inside a Rectangle in Java?
- Check if a given point lies inside a Polygon
- Check whether a given point lies inside a Triangle
- Check if a circle lies inside another circle or not in C++
- Find if a point lies inside a Circle in C++
- Check if a point is inside, outside or on the ellipse in C++
- Check if a point is inside, outside or on the parabola in C++
- C++ Program to Check if a Point d lies inside or outside a circle defined by Points a, b, c in a Plane
- Check whether the point (x, y) lies on a given line in Python
- Check if given four integers (or sides) make rectangle in Python
- Program to check given point in inside or boundary of given polygon or not in python
- Check if a given circle lies completely inside the ring formed by two concentric circles in C++
- Plot a circle inside a rectangle in Matplotlib
- What's the fastest way of checking if a point is inside a polygon in Python?
- Check if a word exists in a grid or not in Python

Advertisements