Jump to content

Radians


.:HyPeX:.

Recommended Posts

Hello guys, could someone be kind and explain me radians a little better? I finished school year and dont have my maths teacher to ask to..

So this is my question pretty much:

  
-- i = 0-360 
    local width = math.cos(i) 
    local height = math.sin(i) 
  

This makes an oval, it wont make a perfect circle, even thought it should.

But:

  
--i = 0-360 
    local width = math.cos( math.rad(i) ) 
    local height = math.sin( math.rad(i) ) 
  

This makes a perfect cricle, and an explanation why it does would totally appreciated.

Greetz

PD: I've readed all over the internet, but couldnt find a place that related cos & sin to radians, and cant get to understand radians itself...

I do understand how sin & cos work, so that part can be skipped...

Link to comment

cos and sin in LUA take radians as arguments, when you convert the i to radians first the math functions give the proper results because... Well, because that's the proper way to use it, so you get proper results. 1 radian is 57.296 degrees. Consider that the sin/cos functions are expecting basically 1/57th of the value you're inputting. This means the result is hard to pin down because of the fact that after reaching 360, sin/cos essentially reset and treat that as new 0. At the 7th degree, you're already over a full revolution in radians. The oval is because of the ratio between radians and degrees, if you were to * the i by 6.28318531 which is the conversion rate for 1 circle in degrees to 1 circle in radians, you would essentially be reaching the new 0 every time it went around, with a small addition proportional to the difference, but there's no other reason to do this than to change the number you * i by to watch the ratios of the oval change. If you want a proper circle, just convert to radians the normal way like you have.

I don't really know any other way to explain why the oval is an oval other than that, and that isn't particularly in depth, so I don't know if that's of any help (interest) to you.

Link to comment

Your original question as to why the code with math.rad created the circle was answered. The question of why radians is used is a lot simpler; the creator of LUA decided the mathematical functions should and would use radians rather than degrees, degrees are easier for a person to understand/remember, 0 is north, 90 is east, 180 is south, 270 is west, easy, but people don't want to remember 1.57079633 is east, 3.14159265 is south, 4.71238898 is west, because that's a lot of long complex numbers, however for a computer which can do the calculation relating to pi that gives a radian value, since 2pi = 1 circle, radians are probably more logical. With modern systems, whatever the programming justification the actual saved time is probably so miniscule you could run the differences a million times and barely see a few ms difference overall.

It may also have to do with the fact that if using degrees, for precise measurements someone may round to keep the number an int, whereas with radians, it's going to be a float at least unless you want to round so much that you may as well give it a random number anyway.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...