[cairo] Shouldn't Cairo use/offer degrees rather than radians?

Lawrence D'Oliveiro ldo at geek-central.gen.nz
Tue Jun 27 23:54:35 UTC 2017


On Tue, 27 Jun 2017 17:46:50 +0200, David Kastrup wrote:

> It wasn't good enough for PostScript, and it wasn't good enough for
> METAFONT, and its author Donald Knuth basically _founded_ computer
> science as a discipline.

Having used graphics APIs with both radians and degrees, I end up
preferring radians as the underlying common unit. Maybe it’s because I
don’t just draw things, I also frequently need to calculate various
geometrical properties as well. Radians ends up being easier for this.

Though I accept that humans usually find angles easier to understand
when expressed in degrees, or even in fractions of a whole circle.
Thus, it is handy to be able to accept input and display output in
these units, while doing all calculations internally in radians.

By the way, languages like Python and Java commonly offer conversion
functions between radians and degrees. I find this a less-than-optimal
way of doing things, because you need two conversion functions (one in
each direction) for each unit. Better to offer a single conversion
factor: multiply by that factor to convert the unit to radians, divide
by it to convert radians to that unit. This is what I did in Qahirah: I
offer both “deg” and “circle” factors, so for example a right angle
can be expressed as any of

    math.pi / 2
    90 * qahirah.deg
    qahirah.circle / 4

and conversely it is easy to convert radians to the desired units:

    math.atan2(1, 1) / qahirah.deg # 45°
    math.atan2(1, 1) / qahirah.circle # one eighth of a circle


More information about the cairo mailing list