# Polar to Cartesian: What cos and sin Are Actually Computing

> x = center.x + r·cos(angle) looks like it's moving the coordinate system. It isn't: cos and sin are converting an (angle, radius) pair into an (x, y) position, and the center is a separate step bolted on afterward.

**Date:** 2026-10-11T00:00:00.000Z
**Tags:** Canvas, Coordinates, Math

## The intuition

A formula like `x = center.x + radius * cos(angle)` reads like it's doing
something to the coordinate system itself, shifting the origin, rotating
the axes, something structural. It isn't. Three independent, much more
boring things are happening, stacked in the same expression:

* `cos(angle)` and `sin(angle)` answer one question: on a circle of
  radius 1 centered at the origin, where does `angle` land, as an `x` and
  a `y`. That's all either function ever computes, a pair of coordinates
  for one point on the unit circle.
* `radius * cos(angle)` scales that unit-circle point outward, same
  angle, bigger circle.
* `center.x + ...` is a plain translation, moving the whole scaled point
  so the circle is centered wherever you want, instead of at `(0, 0)`.

`cos`/`sin` only ever do the first part. They don't know about `radius`,
they don't know about `center`, and they never touch the coordinate
system itself, the axes, the origin, "up" and "down" are exactly where
they were before you called them. The formula just runs rotate, then
scale, then translate, one after another, and it's easy to misread the
combined result as one operation instead of three.

* [Screen Coordinate Systems Aren't Cartesian](/screen-coordinate-system) — Why the same cos/sin formula sweeps clockwise on a y-down screen instead of counterclockwise, plus atan2 for turning a drag into an angle.

* [atan, atan2, and atanh](/atan-atan2-atanh) — The reverse direction: going from an (x, y) position back to an angle, and why atan alone can't do it.

## Concrete example

Here's the pattern trimmed down to just that formula, adapted from a
real Compose `DrawScope` helper that places points along a circular arc:

```kotlin
import androidx.compose.ui.geometry.Offset
import kotlin.math.cos
import kotlin.math.sin

// Where does `angleRadians` land on a circle of `radius`, centered at
// `center`? That's the whole question this function answers.
fun pointOnCircle(center: Offset, radius: Float, angleRadians: Float): Offset {
    return Offset(
        x = center.x + radius * cos(angleRadians),
        y = center.y + radius * sin(angleRadians),
    )
}
```

```kotlin
pointOnCircle(center, radius, angleRadians = 0f)
// cos(0) = 1, sin(0) = 0 → (center.x + radius, center.y)
// directly to the right of center

pointOnCircle(center, radius, angleRadians = (PI / 2).toFloat()) // 90°
// cos(90°) = 0, sin(90°) = 1 → (center.x, center.y + radius)
// straight down, on a y-down DrawScope (more on that flip below)
```

Nothing about `center` changed either answer. It only gets added once the
rotate-and-scale step has already finished.

Drag the sliders below and watch the readout: the `r·cos`/`r·sin` values
are exactly the two dashed legs of the triangle, and `x`/`y` are just
`center` plus those two legs.

*\[Interactive demo: PolarPointDemo — view this post in a browser for the live version.]*

## More cases: placing several points at once

The same formula answers "where's the Nth point" just as easily as "where's
this one point," by sweeping `angle` in even steps instead of calling it
once:

```kotlin
// Evenly spaced points around a full circle, e.g. tick marks on a dial
// or dots arranged in a ring.
fun pointsAroundCircle(center: Offset, radius: Float, count: Int): List<Offset> {
    return List(count) { i ->
        val angle = (2 * Math.PI * i / count).toFloat()
        pointOnCircle(center, radius, angle)
    }
}
```

Nothing new is happening mathematically, it's the exact same
`pointOnCircle` call from above, just invoked `count` times with a
different `angle` each time. This is the general shape behind clock
hands, radial menus, particles on a ring, and sampling points along a
circular arc to connect with curves instead of drawing the arc directly.

> **The fundamental**
>
> This is **polar-to-Cartesian conversion**: a point described as `(radius,
> angle)`, distance and direction from a center, converted into the `(x,
> y)` pair a screen actually needs. `cos`/`sin` are the conversion's rotate
> step; the radius multiply and the center add are separate steps riding
> along in the same line of code. Going the other direction, `(x, y)` back
> to `(radius, angle)`, is a different problem with a different tool
> (`atan2` for the angle, the distance formula for the radius), not the
> inverse of calling `cos`/`sin` differently.

## Elsewhere: same fundamental, different framework

* **SVG**: an `<circle>` or an arc's `A` path command is rendered by the
  browser's path engine walking this exact `center + radius * (cos,
  sin)` formula internally to produce the curve; `d3.arc().centroid()`
  calls the same conversion directly, used constantly to position pie
  and donut chart labels at a slice's midpoint.
* **HTML5 Canvas**: `CanvasRenderingContext2D.arc(x, y, radius,
  startAngle, endAngle)` takes the center/radius/angle triple as
  separate arguments and runs the identical conversion per frame to
  trace the curve.
* **SwiftUI / Core Graphics**: `Path.addArc(center:radius:startAngle:
  endAngle:clockwise:)` takes the exact same center/radius/angle triple
  as Canvas's `arc()`; hand-placing a point with `CGPoint(x: center.x +
  radius * cos(angle), y: center.y + radius * sin(angle))` is the
  standard way to draw anything a `Path` has no built-in primitive for,
  a gauge's tick marks, a clock face, a radial layout.
* **Game engines (Unity, Godot, Unreal)**: `new Vector2(Mathf.Cos(angle),
  Mathf.Sin(angle)) * radius + center` is the standard way to orbit an
  object around a point, same three steps, same order, just written with
  a vector type instead of separate `x`/`y` fields.
* **CSS**: `conic-gradient()` and `clip-path: circle()` are declarative
  wrappers around the same math; animating an element around a circular
  path with `offset-path: circle()` is this formula running every frame,
  just computed by the browser instead of your own code.

## Edge cases

**Forgetting the radius multiply.** `cos`/`sin` return values in `[-1,
1]`, not pixels. `x = center.x + cos(angle)` compiles fine and looks
plausible, since it has the right shape, `center` plus something
angle-dependent, but it traces a circle of radius 1: visually, every
point collapses onto roughly the same spot as `center`. There's no crash
to point at the missing `radius *`, just a shape that silently refuses
to be bigger than a pixel.

**Swapping which axis gets `cos` and which gets `sin`.** `x = center.x +
radius * sin(angle)` paired with `y = center.y + radius * cos(angle)`
still traces a perfectly good circle, the shape never breaks. What
breaks is the meaning of `angle = 0`: instead of landing to the right of
center (this post's convention), it lands below it, a silent 90° offset
from whatever the rest of the code assumes "angle zero" points toward.

**Degrees fed to a radians-only function.** `kotlin.math.cos`/`sin` (and
their equivalents in virtually every language) expect radians (The unit cos/sin actually take. PI radians is half a circle (180°), 2 \* PI radians is a full circle (360°), so dividing 2 \* PI by N gives the angular step for N equal slices of a circle.), not
degrees. Passing `90` straight in, meaning "90 degrees," actually asks
for `cos`/`sin` of 90 *radians*, about 14 full turns past where you
meant, and the result lands nowhere near the circle you expected with no
exception to catch the mistake. Convert first: `Math.toRadians(90.0)`,
or the `degrees * PI / 180` arithmetic it wraps.

**Which way "up" points flips, the formula doesn't.** On a y-down
`DrawScope`/`Canvas` (the Android/Compose default), increasing `angle`
sweeps clockwise instead of the counterclockwise sweep the same formula
produces on a math-class, y-up plane. `cos`/`sin` themselves never
change, only which visual direction a positive angle lands in. The
[screen coordinate systems post](/screen-coordinate-system) covers that
flip in depth; this post's formula is the `x = cx + r·cos(angle)` case
that post's intro already assumes.

## When to reach for it

Anything where the real quantity you're thinking in is "how far, in what
direction, from a center," not an `x`/`y` pair directly:

* **Clock and dial faces.** Hour/minute hands, tick marks, gauge needles:
  each one is `angle` in, position out, exactly `pointOnCircle`.
* **Radial and pie menus.** Laying out N menu items evenly around a
  center is `pointsAroundCircle` from above, one call per item.
* **Orbiting or circling objects.** A loading spinner's dots, a satellite
  icon circling a planet, a particle on a ring: update `angle` each
  frame and recompute the position, instead of tracking `x`/`y` velocity
  directly.
* **Chart label and slice placement.** A pie/donut chart's label needs to
  sit at a slice's midpoint angle, pushed out to some radius from center,
  the same formula this post has been using the whole time.
* **Sampling a circular arc to draw it with something else.** Walking
  `angle` in small steps and connecting the resulting points with
  `quadraticTo`/`lineTo` instead of a native arc primitive, useful when
  the arc needs to wobble, taper, or otherwise not be a perfect circle.

The signal that you're in the wrong post: if what you actually have is
an `(x, y)` position (a touch point, a drag) and you want an angle or
distance back out of it, that's the reverse conversion, `atan2` and the
distance formula, not a different way of calling `cos`/`sin`.

**`cos`/`sin` only ever answer "where's this angle on a unit circle";
scaling by a radius and adding a center are separate steps that happen to
live on the same line, not something sin and cos compute themselves.**


---

Canonical page: https://recomposed.blog/polar-to-cartesian-point