Page 1 of 2

Sin() and Cos() to optionally support degrees...

Posted: Sun May 07, 2006 5:12 pm
by Kale
Please, is it possible for the Sin() and Cos() commands to support degrees and radians by using a built-in constant?

Code: Select all

Sin(Angle.f, #PB_Radians)
Sin(Angle.f, #PB_Degrees)

Cos(Angle.f, #PB_Radians)
Cos(Angle.f, #PB_Degrees)
I know some people prefer either one or the other, but it would be nice to support both. :)

Posted: Sun May 07, 2006 5:36 pm
by josku_x
I agree.

Posted: Sun May 07, 2006 5:54 pm
by Dare2
Also agree. (And props to me from me for restraint on the pun)

Posted: Sun May 07, 2006 8:09 pm
by blueznl
sinq cosq ?

(don't kill me, gfa malformed me!)

Posted: Sun May 07, 2006 8:31 pm
by Polo
Then i'ld prefer two different functions, for speed/size reasons.

Posted: Sun May 07, 2006 8:35 pm
by Trond
Radians is the standard in programming languages I think, but it would be convenient with a set of functions for either, or at least predefined conversion functions/(macros).

Posted: Sun May 07, 2006 9:31 pm
by josku_x
Degrees are mostly used in calculators and when I look virtual calculator software on the internet, it always has an option to switch between degrees and radian.

Posted: Sun May 07, 2006 9:39 pm
by djes
I vote for differents functions. I prefer radians by default.

Posted: Sun May 07, 2006 9:56 pm
by Killswitch
Would it not be better to keep Sin/Cos etc in degrees mode then have a Deg2Rad() command and vice verca?

Posted: Sun May 07, 2006 10:03 pm
by djes
As we have discuted before, sin and cos are often used for a lot of calculations. Any slow down of these functions will have a big speed impact on our programs!

I prefer differents dedicated functions for this reason :

"Sin" and "cos" in radians
"Sinq" and "cosq" or anything else, like "sind" and "cosd" for degrees.

Posted: Sun May 07, 2006 10:18 pm
by Kale
djes wrote:I prefer differents dedicated functions for this reason :

"Sin" and "cos" in radians
"Sinq" and "cosq" or anything else, like "sind" and "cosd" for degrees.
You misunderstand, my request was for an optional unit parameter to allow sin and cos to work with degrees. There is no need for seperate commands because when compiled the two different versions can be use behind the scenes. Just like the Plot(x, y) and plot(x, y, colour) commands where the first is not accelerated but the second is.

Posted: Mon May 08, 2006 7:14 am
by Michael Vogel
Kale wrote:
djes wrote:I prefer differents dedicated functions for this reason :

"Sin" and "cos" in radians
"Sinq" and "cosq" or anything else, like "sind" and "cosd" for degrees.
You misunderstand, my request was for an optional unit parameter to allow sin and cos to work with degrees. There is no need for seperate commands because when compiled the two different versions can be use behind the scenes. Just like the Plot(x, y) and plot(x, y, colour) commands where the first is not accelerated but the second is.
I've used...
Procedure.f Radiant(x.f)
ProcedureReturn x*#PI/180
EndProcedure
...but maybe there could be a alternative (for speeder and not so precise calculation) which uses degrees...

Posted: Mon May 08, 2006 9:19 am
by blueznl
in gfa sinq and cosq were doing lookups in a table instead of a real calculation to speed things up, and intermediate positions were just interpolated, not using the fpu

as degrees are mostly done in game purposes, this did make some sense

the question is just: would it make sense to do it this way on modern hardware, with modern fpu's ?

Posted: Mon May 08, 2006 10:09 am
by Kale
blueznl wrote:in gfa sinq and cosq were doing lookups in a table instead of a real calculation to speed things up, and intermediate positions were just interpolated, not using the fpu?
Thats a good idea! :) As the only reason for asking this would be for games and the like, to quickly throw things around the screen.

Posted: Mon May 08, 2006 11:52 am
by josku_x
Killswitch wrote:Would it not be better to keep Sin/Cos etc in degrees mode then have a Deg2Rad() command and vice verca?
Seems to be that PHP is really powerful:
http://php.net/rad2deg