Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Sin and cos functions wrong? (https://forums.graalonline.com/forums/showthread.php?t=134265076)

iBeatz 11-21-2011 09:06 PM

Sin and cos functions wrong?
 
I've been doing an angle-based movement project, and haven't really done anything major with angles in GScript until now.
When I use a variable which is equal to 180 and take the sine of it using sin(), instead of echoing 0 for the sine value of 180 (which I know it should), it echoes a value of -0.801.
The same goes for the cosine value of 180. It echoes a value of -0.598 instead of -1.

Any reason for this, or is there something wrong with the functions?

Crow 11-21-2011 09:18 PM

Use radian values, not degrees. pi is a built-in variable that'll help a lot.

fowlplay4 11-21-2011 10:48 PM

There's also:

degtorad(angle);
radtodeg(angle);

To convert back and forth. You really shouldn't need to do that though.

iBeatz 11-22-2011 12:13 AM

Quote:

Originally Posted by fowlplay4 (Post 1674958)
There's also:

degtorad(angle);
radtodeg(angle);

To convert back and forth. You really shouldn't need to do that though.

I'm using degtorad().
I just feel more comfortable using degrees than radian values.

fowlplay4 11-22-2011 12:29 AM

Quote:

Originally Posted by iBeatz (Post 1674973)
I'm using degtorad().
I just feel more comfortable using degrees than radian values.

Well yeah of course degtorad(45) is a lot easier to read/understand than say (pi / 4) for 45 degrees.

Keep in mind that pi is equal to a 180 degrees and it's easy enough to calculate degrees using it. I.e: 360 (pi * 2) or 90 (pi / 2) or 45 (pi / 4) and so on.

Sinkler 11-22-2011 05:36 PM

Quote:

Originally Posted by Crow (Post 1674943)
Use radian values, not degrees. pi is a built-in variable that'll help a lot.

I know nothing about scripting, but does it have something to do with units? In calculus, we're not permitted to use degrees due to the units associated with degrees. Is this a fair assumption?

--This is coming from an unknowledgeable person in regards to scripting--

cbk1994 11-22-2011 05:59 PM

Quote:

Originally Posted by Sinkler (Post 1675049)
I know nothing about scripting, but does it have something to do with units? In calculus, we're not permitted to use degrees due to the units associated with degrees. Is this a fair assumption?

You know how your calculator has a mode for radians and a mode for degrees? In programming, radians are almost always used.

I don't really know what you mean by "units associated with degrees" but that sounds like a silly reason to use radians.

Sinkler 11-22-2011 11:08 PM

Quote:

Originally Posted by cbk1994 (Post 1675051)
You know how your calculator has a mode for radians and a mode for degrees? In programming, radians are almost always used.

I don't really know what you mean by "units associated with degrees" but that sounds like a silly reason to use radians.

When using related rates, some problems (if you use degrees) can end up with:

"___ degrees/hour"

Which doesn't make sense (if we're talking angular calculus). That's why Radians is the preferable mode in calculus. There are no units.

cbk1994 11-23-2011 12:58 AM

Quote:

Originally Posted by Sinkler (Post 1675073)
Which doesn't make sense (if we're talking angular calculus). That's why Radians is the preferable mode in calculus. There are no units.

Radians are units :oo:. You just generally don't write it because it's assumed. There's also radians per second and similar.

Sinkler 11-23-2011 01:17 AM

Quote:

Originally Posted by cbk1994 (Post 1675095)
Radians are units :oo:. You just generally don't write it because it's assumed. There's also radians per second and similar.

Radians have a mathematical "naturalness" that leads to a more elegant formulation of a number of important results.


All times are GMT +2. The time now is 09:18 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.