Algorithm
Geometry
Computational Geometry
Circle
Point Distribution

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.

Practice algorithms

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:

python
1import math
2from typing import List, Tuple
3
4
5def points_on_circle(cx: float, cy: float, radius: float, count: int) -> List[Tuple[float, float]]:
6    points = []
7    for i in range(count):
8        theta = 2.0 * math.pi * i / count
9        x = cx + radius * math.cos(theta)
10        y = cy + radius * math.sin(theta)
11        points.append((x, y))
12    return points
13
14
15for point in points_on_circle(0.0, 0.0, 5.0, 8):
16    print(point)

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.

python
1from typing import List, Tuple
2
3
4def grid_points_in_circle(cx: int, cy: int, radius: int) -> List[Tuple[int, int]]:
5    points = []
6    r2 = radius * radius
7
8    for x in range(cx - radius, cx + radius + 1):
9        for y in range(cy - radius, cy + radius + 1):
10            dx = x - cx
11            dy = y - cy
12            if dx * dx + dy * dy <= r2:
13                points.append((x, y))
14
15    return points
16
17
18print(grid_points_in_circle(0, 0, 2))

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.

python
1import math
2from typing import List, Tuple
3
4
5def grid_points_in_circle_faster(cx: int, cy: int, radius: int) -> List[Tuple[int, int]]:
6    points = []
7    r2 = radius * radius
8
9    for x in range(cx - radius, cx + radius + 1):
10        dx = x - cx
11        max_dy = int(math.sqrt(r2 - dx * dx))
12        for y in range(cy - max_dy, cy + max_dy + 1):
13            points.append((x, y))
14
15    return points

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).

python
1import math
2import random
3from typing import Tuple
4
5
6def random_point_in_circle(cx: float, cy: float, radius: float) -> Tuple[float, float]:
7    theta = random.random() * 2.0 * math.pi
8    distance = math.sqrt(random.random()) * radius
9    return (
10        cx + distance * math.cos(theta),
11        cy + distance * math.sin(theta),
12    )
13
14
15print(random_point_in_circle(0.0, 0.0, 10.0))

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 cos and sin in O(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
Course
Intermediate
27 lessons
15 hours
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 course
Track 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.

Practice algorithms

All Rights Reserved.