Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why did Apple flip their unit circle for UIBezierPath?

enter image description here

The image on the left is what a typical unit circle looks like. The one on the right is from the documentation. I haven't seen a more in depth explanation for why it was flipped anywhere online. Why is this so?

like image 667
Biclops Avatar asked Jan 13 '17 22:01

Biclops


1 Answers

A drawing of a circle is often represented by x = center.x + r * cos(φ) and y = center.y + r * sin(φ) as φ progresses from 0 to 2π. With a standard Cartesian coordinate system, with the origin in the lower-left corner, this results in a circle drawn, starting at 3 o'clock and proceeding counterclockwise. See diagram to the left, below.

But the iOS coordinate system has the the y-axis flipped from the standard Cartesian coordinate system, with the origin in the upper-left corner and y increasing as you move down the screen. See right diagram below:

enter image description here

(This is adapted from Coordinate Systems in the Quartz 2D Programming Guide. The original diagram in the Apple documentation is merely illustrating how the coordinate systems are flipped, but I've changed the arrow to more accurately represent how this affects the drawing of an arc from 0 to π/2.)

The result is that, when using the iOS coordinate system, it will start at 3 o'clock but then proceed clockwise.

like image 157
Rob Avatar answered Sep 20 '22 08:09

Rob