Equation for testing if a point is inside a circle
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
In mathematics and computer graphics, determining whether a point lies inside, outside, or on the boundary of a circle is a fundamental problem. This task finds applications in various fields such as geometry, game development, simulations, and geographic information systems. This article explores the equation used to test the position of a point relative to a circle, delves into the mathematical foundation behind it, and provides practical examples and considerations.
Mathematical Foundation
To determine if a point (x, y) is inside a circle, one can use the equation derived from the circle's definition. A circle in a Cartesian coordinate system with center (h, k) and radius r is represented by the equation:
This equation describes all the points (x, y) that lie on the boundary of the circle. For points either inside or outside, we have inequalities based on the squared distance from the point to the circle's center compared to the square of the radius.
Criterion for Point Location
Given a point (x, y), one needs to evaluate:
- Inside the Circle: The point is inside the circle if:
- On the Circle: The point is on the boundary if:
- Outside the Circle: The point is outside the circle if:
Examples
Example 1: Inside the Circle
Consider a circle centered at (0, 0) with a radius of 5. Test if the point (3, 4) is inside the circle.
Calculate:
Since 25 equals r^2, the point (3, 4) is precisely on the circle, not inside.
Example 2: Outside the Circle
Using the same circle as previously, test if the point (6, 0) is outside the circle.
Calculate:
Since 36 is greater than 25, the point (6, 0) is outside the circle.
Example 3: On the Circle
Suppose the circle is centered at (2, 3) with radius 4. Test if the point (5, 3) is on the circle.
Calculate:
The comparison yields 9 which is less than 16 (where r^2 = 16), indicating that the point (5, 3) lies inside the circle.
Applications
- Collision Detection: In computer graphics and game development, detecting whether a point (e.g., mouse click or character position) lies within interactive zones.
- Geofencing: Utilized in location-based services to determine if a user is within a specific geographic boundary.
- Spatial Analysis: Used in geographical analysis to evaluate spatial relationships between points and defined areas.
Table Summary
| Concept | Mathematical Expression | Interpretation |
| Point on Circle | Point lies on circle boundary | |
| Point inside Circle | Point lies within circle | |
| Point outside Circle | Point lies outside circle |
Considerations
- Precision: When working with floating-point arithmetic, be mindful of precision errors. Comparisons involving
=may require an epsilon tolerance. - Optimization: Avoid calculating the square root by comparing squared values, which is computationally efficient.
Determining a point's relationship to a circle is fundamental, providing the basis for more complex spatial analyses and geometric algorithms. By understanding and applying these basic principles, one can effectively solve a wide array of practical problems.
Related reading
- Estimating the digits occurrence probability inside a GUID
- Euler project 18 approach
- Evenly distributing n points on a sphere
- Evenly distributing n points on a sphere
- Expand a random range from 1–5 to 1–7
- Expectation Maximization coin toss examples
- Expectation Maximization coin toss examples
- Explain markov-chain algorithm in layman's terms

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.