• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

All about Degrees <> Radians

Status
Not open for further replies.
Level 16
Joined
Oct 12, 2008
Messages
1,570
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,,-
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
Ya ok,, but i dont want it just for 90 degrees, i want to know a general rule for degrees to radians,, not just for 90 degrees,,
Cause i also want to add 45 degrees later, and maybe 2 degrees later on,, you know?
 
Level 17
Joined
Jun 17, 2007
Messages
1,433
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π).
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
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?
 
Level 4
Joined
Jun 8, 2007
Messages
89
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.
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
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?
 
Level 4
Joined
Jun 8, 2007
Messages
89
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!
 
Level 4
Joined
Jun 8, 2007
Messages
89
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).
 
Level 4
Joined
Jun 8, 2007
Messages
89
I don't think there is any programming language that takes or returns degrees in any trigo function.

I didn't mean the base trig functions like cosine, sine, or tangent, but there are some other functions that utilize angles that can get confusing.
 
Level 22
Joined
Dec 31, 2006
Messages
2,216
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.
Top