Efficient Algorithm to obtain Points in a Circle around a Center
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
When people ask for points “in a circle around a center,” they often mean one of two different problems. They may want points evenly spaced on the circumference, or they may want all integer grid points inside the disk.
Those are different tasks and they lead to different algorithms. The efficient solution depends on whether you care about geometric placement, integer coordinates, or covering every point in the area.
Evenly Spaced Points on the Circumference
If the goal is to place n points evenly around a circle of radius r centered at (cx, cy), the standard parametric form is the right tool.
For point i, use angle:
theta = 2 * pi * i / n
Then compute:
- '
x = cx + r * cos(theta)' - '
y = cy + r * sin(theta)'
Here is a Python implementation:
This runs in O(n) time because it computes each point once.
Why This Is Efficient
For equally spaced circular points, there is no need for search or rejection sampling. The angular step is known in advance, so the algorithm directly generates the exact coordinates you need.
That is about as efficient as the problem allows: one constant amount of arithmetic per output point.
If trigonometric calls are a bottleneck in very large runs, you can also use a rotation recurrence to avoid repeated sin and cos evaluation, but for ordinary use the direct formula is clear and fast enough.
Integer Grid Points Inside the Circle
If the goal is different, such as “give me all integer lattice points inside a circle,” then the parametric formula is not the correct solution. In that case, iterate over the bounding square and keep only points that satisfy the circle equation.
This checks all grid points in the bounding box. Its time complexity is O(r^2) because the box has side length proportional to r.
Avoiding Unnecessary Work in the Grid Version
The bounding-box scan is easy to understand, but you can reduce work slightly by computing the allowed y range for each x.
This avoids checking points that are obviously outside the circle. The asymptotic cost is still proportional to the number of visited grid points, but the constant factor is better.
Random Points Inside a Circle
A third interpretation is random sampling inside a circle. If that is what you need, use polar coordinates carefully. To get a uniform area distribution, the radius should not be sampled linearly. Instead, sample sqrt(u) * r, where u is uniform in [0, 1).
Without the square root, the sample points cluster too heavily near the center.
Choosing the Right Algorithm
Use the circumference formula when you want deterministic, evenly spaced points around the center. Use the grid scan when you need integer coordinates inside the disk. Use polar sampling when you want random points.
The word “efficient” is tied to the exact output you want. There is no single best algorithm for all three interpretations.
Common Pitfalls
One common mistake is using the circumference formula when the actual requirement is to cover the interior of the circle. That only gives edge points, not area points.
Another issue is assuming random radius values produce a uniform distribution inside the disk. They do not; uniform radius sampling biases toward the center.
It is also easy to waste time generating candidate points and rejecting most of them. For many circle tasks, direct formulas are cleaner and faster than rejection-based approaches.
Finally, be clear about coordinate type. Floating-point geometry and integer grid enumeration are different problems and should not be mixed casually.
Summary
- Evenly spaced points on a circle are generated directly with
cosandsininO(n)time. - Integer points inside a circle are usually found by scanning the bounding box or a pruned version of it.
- Random points inside a circle need radius sampling based on
sqrt(u)for uniform area coverage. - The most efficient algorithm depends on whether you want edge points, interior grid points, or random samples.
- Choosing the wrong interpretation is the most common source of both incorrect output and wasted work.
Related reading
- Efficient algorithm to randomly select items with frequency
- Efficient Algorithms for Computing a matrix times its transpose
- Efficient Array Storage for Binary Tree
- Efficient calculation of Fibonacci series
- Efficient checking of whether a point is inside a large number of triangles in 2D
- Efficient combinations of N colored elements with restriction in the number of colors
- Efficient Cartesian Product algorithm
- Efficient data structure for sparse data lookup

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.