Calculating the position of points in a circle
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
To calculate points on a circle, you need the circle's center, its radius, and an angle. From there, basic trigonometry gives you coordinates for one point, evenly spaced points around the circumference, or even random points inside the disk.
The Core Formula
For a circle centered at (cx, cy) with radius r, a point at angle theta is:
- '
x = cx + r * cos(theta)' - '
y = cy + r * sin(theta)'
The cosine gives the horizontal offset from the center, and the sine gives the vertical offset.
Example in Python:
This is the foundation for nearly every circle-positioning problem in programming, graphics, and geometry.
Degrees Versus Radians
One of the most common mistakes is using degrees directly with sin and cos in code. Most programming language math libraries expect radians.
If the angle is given in degrees, convert it first:
After conversion, plug theta into the same circle formula.
If you skip this step, the code still runs, but the coordinates are wrong because the trigonometric functions are interpreting the input in the wrong unit.
Evenly Spaced Points Around the Circle
If you want n equally spaced points, divide the full turn into n equal angular steps. A full revolution is 2 * pi, so the step size is 2 * pi / n.
This pattern is useful for:
- placing icons around a hub
- creating polygon vertices
- laying out tick marks on a dial
- generating circular motion paths
Starting from the Top or Rotating the Layout
By mathematical convention, angle zero lies on the positive x-axis. In visual layouts, people often expect the first point to appear at the top instead.
You can shift the starting point with an angle offset:
That same offset idea lets you rotate the entire point set by any angle.
Screen Coordinates Versus Mathematical Coordinates
In mathematics, the y-axis increases upward. In many graphics systems, the y-axis increases downward. That can make an apparently correct formula look upside down on screen.
In a screen coordinate system, a common adaptation is:
- '
x = cx + r * cos(theta)' - '
y = cy - r * sin(theta)'
The negative sign flips the vertical direction to match the display system.
If your points appear mirrored or rotate the wrong way in a UI, coordinate-system direction is one of the first things to check.
Points Inside the Circle
Sometimes you want to test or generate points inside the disk rather than only on the border.
To check whether a point lies inside or on the circle:
(x - cx)^2 + (y - cy)^2 <= r^2
Example:
If you want a random point inside the disk, sample a random angle and a properly scaled random radius:
The square root matters. Without it, the sample density is biased toward the center.
Common Pitfalls
The biggest mistake is mixing degrees and radians. The formulas stay the same, but the angle unit must match the math library.
Another issue is forgetting to add the center offsets after computing the sine and cosine components. r * cos(theta) and r * sin(theta) give offsets from the origin, not final coordinates for an arbitrary center.
Developers also get tripped up by screen coordinates, where the vertical axis often points downward instead of upward.
Finally, when generating evenly spaced points, use 2 * pi / n for a full closed circle. Using n - 1 instead changes the problem into placing points along an arc with duplicated endpoints.
Summary
- A point on a circle comes from cosine for x and sine for y, scaled by the radius and shifted by the center.
- Convert degrees to radians before calling trigonometric functions in most programming languages.
- Evenly spaced points use an angle step of
2 * pi / n. - Screen coordinate systems may require flipping the sign of the y term.
- For inside-circle work, compare squared distances or sample radius carefully for uniform random points.

