# Screen Coordinate Systems Aren't Cartesian: Y Points Down, Not Up

> Every rotation, angle, and drag direction you learned on a math-class Cartesian plane comes out mirrored on screen, because the screen coordinate system flips Y.

**Date:** 2026-10-08T00:00:00.000Z
**Tags:** Canvas, Graphics

## The intuition

A math-class Cartesian plane has `y` increasing *upward* and angles
sweeping *counterclockwise* from positive `x`. Every View, Canvas, and
`DrawScope` on Android looks like that same plane, same `x = cx +
r·cos(angle)` formulas, but it isn't:

* The origin is the **top-left** corner, not the center.
* `y` increases **downward**, not upward.
* A positive angle in `cos`/`sin` sweeps **clockwise** on screen, not
  counterclockwise, because flipping `y` flips the direction rotation
  reads as.

Nothing about the math changes. `sin` and `cos` don't know or care which
way `y` points. What changes is which direction on *your screen* a given
angle or formula lands you in, and that's the part muscle memory from
math class gets backward.

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

* [Polar to Cartesian: What cos and sin Are Actually Computing](/polar-to-cartesian-point) — The x = cx + r·cos(angle) formula this post's rotation and sweep examples build on, and why the same formula sweeps clockwise instead of counterclockwise once y points down.

* [atan, atan2, and atanh](/atan-atan2-atanh) — The reverse direction of the drag case below: turning a (dx, dy) position back into an angle, and why atan alone can't do it.

## Concrete example: rotating a point by hand

```kotlin
// Math-class Cartesian: rotating (10, 0) by +90° lands at (0, 10),
// "up and to the left" on paper, where y grows upward.
val angle = Math.toRadians(90.0)
val rotatedX = 10 * cos(angle)
val rotatedY = 10 * sin(angle)
// On screen (y grows downward instead), that same (0, 10) result
// is 10px *down* from center, not up. The formula didn't change —
// which way "up" points did.
```

Feed the exact same rotation formula the exact same numbers on a View's
`Canvas`, and the result lands in the mirror image of where it would on
graph paper. The formula is identical; only the meaning of a positive `y`
flipped underneath it.

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

## Angle direction

`Modifier.graphicsLayer { rotationZ = 90f }` spins a composable
**clockwise** for a positive angle, the same `y`-down logic as every other
case here: the layer's rotation pivot sits in a y-down space, so a
positive angle reads clockwise there too. It's not a special rule for
`graphicsLayer`, it's the same one rule showing up again.

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

## Sweep

`drawArc(startAngle = 0f, sweepAngle = 90f)` sweeps **clockwise** from 3
o'clock to 6 o'clock. The same `0°` to `90°` sweep on a Cartesian plane
goes from 3 o'clock to 12 o'clock, **counterclockwise**, the opposite
visual direction for the identical numbers.

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

## Dragging

A drag only gives you a position, specifically a
`(dx, dy)` (dx is how far a point moved along x, dy is how far it moved along y, both measured relative to some reference point (a drag's start position, a shape's center). Neither one is a coordinate by itself, just a difference between two.)
offset, not an angle. Turning that into an angle needs `atan2(dy, dx)`.

You might reach for `arctan(dy/dx)` instead, "rise over run." It breaks
twice: `dx = 0` divides by zero, and the ratio alone can't tell `(1, 1)`
from `(-1, -1)` apart, since `-1/-1` is also `1`, even though those are
opposite directions. `atan2` takes `dx` and `dy` separately instead of
pre-dividing them, so it can see each sign and resolve all four
directions correctly.

That's also the cleanest trigger for *when* to reach for it: `cos`/`sin`
go **angle in, position out** (the polar formula from the intro,
`x = cx + r·cos(angle)`), and `atan2` goes the other way, **position in,
angle out**. A drag hands you a position, not an angle, so there's
nothing to compute with except `atan2`.

It's the right tool for a drag-to-rotate knob for the same reason: the
finger doesn't need to land exactly on the ring, since `atan2` only reads
the *direction* from center to finger, not the distance. The same trick
drives any facing-direction logic too, rotating a sprite to match its
per-frame `(dx, dy)` velocity instead of a finger position.

On paper, dragging *up* gives a positive angle (counterclockwise from
positive `x`). On screen, dragging up **decreases** `y`, which flips the
sign `atan2` returns for the same physical gesture.

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

## Scroll

A scrollable view makes this concrete without any trig at all: a child at
content position `y` renders on screen at `y - scrollState.value`, where
`scrollState` is the `ScrollState` behind `Modifier.verticalScroll`.
Scroll down, `scrollState.value` increases, and content moves *up* on
screen, toward smaller `y`, the same y-down space the whole post has been
using. There's no new convention here, just the familiar one plus a
subtraction.

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

## Lazy lists

`LazyColumn` applies the exact same subtraction, but `scrollState.value`
doesn't exist there, because a lazy list never measures the items it
hasn't drawn yet. There's no single upfront content height to subtract
against.

```kotlin
// ScrollState: every child is measured up front, so one cumulative
// pixel value is enough to place all of them.
val offsetPx = scrollState.value

// LazyListState: items off-screen are never measured, so there's no
// total content height to track. The offset is split into which item
// is first on screen, plus how far into that item you've scrolled.
val firstIndex = lazyListState.firstVisibleItemIndex
val firstItemOffsetPx = lazyListState.firstVisibleItemScrollOffset
```

The `y - offset` logic still runs during layout, it's just computed per
visible item relative to `firstVisibleItemIndex` instead of against one
global value: item 0 sits at `-firstItemOffsetPx`, item 1 at \`item0Height

* `firstItemOffsetPx`, and so on. Same y-down space, same subtraction,
  just anchored to the nearest visible item instead of to a precomputed
  total.

> **The fundamental**
>
> This is a **left-handed 2D coordinate system** (equivalently, a y-down or
> raster/screen coordinate system), as opposed to math's right-handed,
> y-up convention. Flipping the sign of one axis flips the handedness of
> the whole system, which is exactly why a positive angle that reads
> counterclockwise in one convention reads clockwise in the other. The
> trig identities never changed; the axis they're measured against did.

## Elsewhere: same fundamental, different framework

* **HTML5 Canvas**: origin top-left, `y` down, `rotate()` positive is
  clockwise, identical convention to Android's `View`/`Canvas`, for the
  identical reason (both inherited it from raster image coordinates,
  where row 0 is the top row).
* **SwiftUI / Core Animation**: `CGContext`'s drawing space is top-left,
  `y` down, same as Compose's
  [`DrawScope`](/phase-aware-compose-tips), but `UIKit`'s own
  `CGPoint`/`CGRect` APIs *also* assume y-down, making SwiftUI and
  Compose closer to each other here than either is to math.
* **Core Graphics / PDF, by contrast**: `y` increases *upward*, true to
  math convention, because PDF's coordinate system descends from print
  layout, not raster scanning. The same `CGContext` family of APIs
  straddles both conventions depending on which one you're drawing into,
  which is the single most common source of "my PDF export is upside
  down" bugs.
* **OpenGL / Metal normalized device coordinates**: `y` increases
  *upward*, right-handed, math convention again, which is exactly why
  every texture you load from a y-down image file needs its `v`
  coordinate flipped before it samples right-side up on screen.
* **Flutter**: `Offset`/`Canvas` are y-down, same as Android's `View`
  system, for the same raster-coordinate lineage, so a rotation or
  `atan2` ported from a Flutter `CustomPainter` to a Compose `DrawScope`
  needs no sign changes at all, unlike porting one from math-derived
  OpenGL code.

`atan2` shows up far beyond this one drag case: knobs, pie menus, sprite
facing, joystick input, bearing calculations, DSP phase, and more. The
[atan2/atan/atanh deep-dive](/atan-atan2-atanh#where-else-atan2-shows-up)
covers the full list.

## Mental model to actually use

**Before trusting a rotation, angle, or drag-direction formula on
screen, ask whether it was derived for a y-up plane or a y-down one; the
formula is identical either way, only its visual direction flips.**


---

Canonical page: https://recomposed.blog/screen-coordinate-system