All about Degrees <> Radians

Status
Not open for further replies.
Level 16
Joined
Oct 12, 2008
Messages
1,569
Heey guys,,

At school i have worked with Cos and Sin with degrees, now i heard here that it is better to use Radians, but how do i use them?
Lets say i got an angle in radians, but i dont know how to increase it the right way,,
So i convert it to degrees, set it + 90 and convert to radians again,,
This is probably way around how it should, so my question is, how to use it well?
What are the basics with Radians?

Thanks! -Yixx,,-
 
Use the constant bj_DEGTORAD. It's Pi/180. EG. To convert 90 degrees to radians, it would look something like this:

set r = 90*bj_DEGTORAD

The only real use for bj_DEGTORAD is when dealing with GetUnitFacing, and SetUnitFacing.

Degrees range from 0 to 360, radians range from 0 to around 6.28 (2π).
 
Ya that would work, but it would become this every time:
set dat.cos = Cos( ( (bj_RADTODEG * dat.a) + 90) * bj_DEGTORAD)

And I dont like that,, so is there an easy way to do it with radians immediately?
something like:
set dat.angle = dat.angle + (Degrees * bj_DEGTORAD)

Would that add the right degrees to it? Would it?
 
In a circle, there are 360 degrees and 2*(Pi) radians, meaning that if you want to go from radians to degrees, use a conversion:

X radians = (Your Number of Degrees) * ((2*(PI) radians) / (360 degrees))
X radians = (Your Number of Degrees) * (((PI) radians) / (180 degrees))

Y degrees = (Your Number of Radians) * ((360 degrees) / (2*(PI) radians))
Y degrees = (Your Number of Radians) * ((180 degrees) / ((PI) radians))

I would suggest just doing the calculations by hand before putting them into your scripts, and you'll be able to get the hang of it without too much work.

EDIT: Got my conversions mixed up, should be fixed now.
 
So,
radians = degrees * PI/180
so if i do:
set NewRadians = OldRadians + (ExtraDegrees * PI/180)

This is the right formula?

Oh, and one more question:
Is there any difference between:
set angle = Cos(a * PI/180)

and

set angle = Cos(a) * PI/180

Any difference?
 
So,
radians = degrees * PI/180
so if i do:
set NewRadians = OldRadians + (ExtraDegrees * PI/180)

This is the right formula?

Yes, that should be the right formula.

Oh, and one more question:
Is there any difference between:
set angle = Cos(a * PI/180)

and

set angle = Cos(a) * PI/180

Any difference?

Yeah, there will be a difference between these two pieces of code. You should convert to radians inside of the cosine function, eg.
set angle = Cos(a * PI/180)

Otherwise you will get skewed results.

Hope this helps!
 
It does! =),, thanks! + rep to youu,,
No problem! Just be careful with Degrees and Radians when working with Jass/Triggers (or even worse, a combination of the two), as, if I remember correctly, most triggers use degrees and most native Jass functions use radians (although it is not always the case).
 
Radians can also be harder to handle than degrees for some people and that's why I think Blizzard made some of the functions use degrees or added BJ versions of those natives that used radians to help people that have problems with it.
 
Status
Not open for further replies.
Back
Top