Live data from Hacker News

Turns are better than radians

computerenhance.com

11–20 of 494 posts

Re: Turns are better than radians

#11

My favourite way of handling angles was always with either unsigned char or 16bit unsigned int that was treated as 1/nth of turn. Usually in these cases cos/sin tables were pre-calculated for speed, although that need went away to an extent. As long as as the calculations wrap around on the underlying system, it makes angles much easier to manage, because angle1 + angle2 = angle3 is always within 0 to 255 or 0 to 655…

For overflowing integers in JS, you can use single-value long typed arrays. I just checked with an Uint16Array and it wraps back to 0 after 65536.

Re: Turns are better than radians

#12

My favourite way of handling angles was always with either unsigned char or 16bit unsigned int that was treated as 1/nth of turn. Usually in these cases cos/sin tables were pre-calculated for speed, although that need went away to an extent. As long as as the calculations wrap around on the underlying system, it makes angles much easier to manage, because angle1 + angle2 = angle3 is always within 0 to 255 or 0 to 655…

> If anybody knows how similar calculations can be easily achieved in JS for example

Simply "a = (a + 0x1234) & 0xffffffff;". Or whatever width you require, 0xff or 0xffff. JIT is going to optimize that and-operation away (at least for 32-bit mask 0xffffffff) and keep the integer value internally.

You can also "cast" a var to int by "ORring" 0 with it, like "a |= 0;"

Re: Turns are better than radians

#13
I agree that this makes sense for the kind of situations that the article talks about. If you only need to express common angles like 90 degrees, 45 and so on, radians are just messy (though in physics, you get used to it).

But in other cases, radians are useful. For example consider the case of small deviations from a direction. If you give it in radians, let's say three mrad (milliradians), it's very easy to estimate how large the error will be over the course of a meter; three mm.

This is just to say: choose the right unit for the job.

Re: Turns are better than radians

#14
I’m surprised game engines do conversion from degrees to radian to call trigonometric functions. I would have called that bad code in an industrial context. We did everything in radians and converted to degrees only for displaying and input.

It was a lot more natural from us because we are a lot more familiar with radians anyway. I don’t think I have used degrees often since starting high school twenty years ago.

Re: Turns are better than radians

#15

My favourite way of handling angles was always with either unsigned char or 16bit unsigned int that was treated as 1/nth of turn. Usually in these cases cos/sin tables were pre-calculated for speed, although that need went away to an extent. As long as as the calculations wrap around on the underlying system, it makes angles much easier to manage, because angle1 + angle2 = angle3 is always within 0 to 255 or 0 to 655…

In JavaScript, I’d stay with floating-point (don’t fight the language if you don’t have to) and use something like x => x - Math.floor(x) to normalize.

Re: Turns are better than radians

#16

That was quite convincing actually. I guess we all have this realization at some point in early math education. Why is it 360 degrees? Mainly because that's a nicely divisible number, no other good reason. Sometimes you find a 400 degree system on calculators but it doesn't seem to be taught anywhere (is it a French thing?) Then at some point you get shown radians, which relates the arc length to the radius. That som…

The 400 system is the grads or gradians, indeed originating from the French revolution.

Nowadays I don't think they're used as the principal unit in any country. Wikipedia does mention it gets some use in specialized fields such as surveying, mining and geology.

Re: Turns are better than radians

#17
post #9

Turns sound fine. But they are turns of a circle of a given radius. So as long as everything conforms to that coordinate system, we're groovy? Radians (circle fractions) are generally preferred because we can compare, e.g. two planetary orbits, conveniently, no? Or did I miss something?

Radians are not circle fractions. Radians _divided by 2pi_ are circle fractions. OP is proposing to use circle fractions instead of radians.

Re: Turns are better than radians

#18
> Some time ago, much effort was expended to convince people to replace approximations of “pi” (3.14159…) with approximations of “tau” (6. 28318…).

IMO the effort was simply to replace the use of pi with the use of tau. What does approximation have to do with it?

Re: Turns are better than radians

#19

I’m surprised game engines do conversion from degrees to radian to call trigonometric functions. I would have called that bad code in an industrial context. We did everything in radians and converted to degrees only for displaying and input. It was a lot more natural from us because we are a lot more familiar with radians anyway. I don’t think I have used degrees often since starting high school twenty years ago.

I consider APIs that use degrees essentially broken. (And similarly, APIs that express ratios as numbers in [0, 100].)

But you have to consider that a lot of game engines and related tools are intended for an audience without a strong programming background. You wouldn’t expect a 3D modeling tool to display radians. And if the UI shows degrees, the file format would better use degrees as well to avoid rounding errors. And then maybe you want the scripting layer to use the same values that the UI does. And so on.

Re: Turns are better than radians

#20

That was quite convincing actually. I guess we all have this realization at some point in early math education. Why is it 360 degrees? Mainly because that's a nicely divisible number, no other good reason. Sometimes you find a 400 degree system on calculators but it doesn't seem to be taught anywhere (is it a French thing?) Then at some point you get shown radians, which relates the arc length to the radius. That som…

It's 360 degrees because of stars. One degree is how much stars move by one day.
Post reply on HN