r/iosdev • u/DrawPiko • 2d ago
Tutorial Apple Pencil altitude and brush tilt use different reference angles
I help build DrawPiko. One detail in our UIKit drawing code is easy to miss when wiring Apple Pencil into a brush engine: UITouch.altitudeAngle is in radians measured from the screen plane. Our engine takes degrees measured away from the screen normal.
The conversion at the input boundary is tiltDegrees = 90 − altitudeAngle × 180 / π. A Pencil held perpendicular to the glass has an altitude of π/2 and should reach the engine as 0° tilt. At π/4, the engine should receive 45°.
We do the conversion on each stylus sample, including the coalesced samples UIKit provides. Tilt travels separately from pressure and barrel roll. Those two angle values make handy sanity checks when a brush seems to respond in the opposite direction from what you expect.