Codea uses radians in some situations (most notably the lua standard libraries), and degrees in others. This isn’t too big an issue, but API consistency makes for easier writing and debugging IMHO, and I’d love to see an angleUnits(MIXED | RADIANS | DEGREES) function to switch the units used by angle-related functions and objects. MIXED would be what is currently used, and the default to maintain backward-compatibility, but you could easily change the units to radians or degrees depending on your personal preference. In addition, to facilitate libraries that could work in both radian and degree mode, there could be two convenience functions, fromDegrees(deg) and fromRadians(rad), which would convert angles to whatever the currently used units are.
Have you tried math.deg() and math.rad() to do your conversions?
.@West yes I have, and even though that is a working solution to dealing with inconsistent units, in my experience it’s one of those situations where you can write an algorithm that makes perfect sense and is entirely correct, except that it doesn’t do a unit conversion, causing you to spend three hours debugging the program trying to find a flaw in the logic, when it turns out that you just needed to add a math.rad(). It’s rather similar to python’s 1.0/2.0 = 0.5, but 1/2 = 0 quirk, which, even though it makes sense, can sneak into otherwise airtight calculations and sabotage them in subtle ways.
Very good suggestion, @SelectricSimian. Though I’m hesitant to overload Lua’s math library (which would be required in the case of angleUnits(DEGREES)).
The only inconsistent API function off the top of my head is rotate(degrees) while everything else is in radians.
I’d like to change
rotate to radians by default, however I can’t think of a great way to do this without breaking existing code. Perhaps a future update to Codea could automatically insert angleUnits(DEGREES) at the top of all old projects, with new projects defaulting to radians.
Could you add this feature request to the issue tracker?
No, @Simeon, that’s the wrong solution!
As a pure mathematician, I am of course dedicated to radians. They are the right way to specify angles. As a hobby programmer, I realise that that is a load of codswallop. No one ever wants to rotate something by a specific number of radians. They always want to rotate by “half a circle” or “3/4 of a circle” and degrees are fabulous for specifying such because 360 is just so divisible. So actually, everything should be degrees by default and
math.rad() for anyone who actually wants to do anything mathematical (me, and … me).
.@Andrew that’s the reason I chose degrees in the first place, as they are more intuitive. I guess we could go the other direction and modify Lua to work with the switch.
.@Simeon think some of the physics is in degrees as well…