Page 1 of 2

Angle.f parameters always in radians

Posted: Fri Jun 24, 2005 4:44 pm
by Psychophanta
Please, for consistence and elegance consider Angle.f parameter value given as radians, not as degrees, for all the functions :)

Posted: Fri Jun 24, 2005 5:47 pm
by Blade
Why not all degrees? Despite I know what radiants are, degrees are much more easy to handle...

Posted: Fri Jun 24, 2005 5:53 pm
by Kale
What about adding a flag to support each?

Code: Select all

SomeProcedure(Angle.f, #PB_Radians)
SomeProcedure(Angle.f, #PB_Degrees)
:?:

Posted: Fri Jun 24, 2005 7:29 pm
by Polo
Well, it's so much easier to use degrees for that kind of stuff 8)

Posted: Fri Jun 24, 2005 7:39 pm
by MikeB
I feel that being able to use either is the obviously preferrable way, some mathmatics require the use of radians if you want to make things simpler, but I would say that while nearly everybody can visualise an angle expressed in degrees, they would have no idea what the same angle in radians meant. Likewise describing a circle and plotting the points is much simpler working with 360° than with 2*PI. If I could only have one way I would go for degrees.

MikeB

Posted: Fri Jun 24, 2005 7:54 pm
by Psychophanta
Angles in degrees couldn't be done. One of the reasons is that Intel FPUs work with radians (and of course all well done FPUs), and to do a programming language that use degrees would be slower for calculations.
So, i request to use radians for all, for RotateSprite3D(), etc...
matter of consistence :)

Posted: Fri Jun 24, 2005 9:37 pm
by Blade
So there IS a reason to use radiants... at last :)
Still don't know why a "well done FPU" has to use them...

I remember when 8bit computer games used "8bit Degrees", ranging from 0 to 255 ... for optimization purposes... Programmes have always to use annoying things instead of easy ones, for optimization purposes :twisted:

Posted: Fri Jun 24, 2005 9:43 pm
by fweil
The reason why radians is the base is easy to understand :

all trigonoetrics are radians based, and all degrees parametering is Pi / 180 based (which is more costy).

Definitely, you have to agree that radians should be the fastest way to compute any trigonometrical value.

But maybe some commands would take some benefit in providing a Radian / Degree flag, except that it would cost a test sequence.

Well, I guess that this post has its roots in that PureBasic provides some (or maybe less than some) instructions with a Degree definition. It should be a Radian float.

But with some use of the language, I did not notice even that, just reading the documentation gives information.

Posted: Fri Jun 24, 2005 9:46 pm
by Psychophanta
Blade wrote:Still don't know why a "well done FPU" has to use them...
Yeah! that's because you are not in use with geometry, trigonometry or general calculations
In the past i said just same as you about degrees, but it is no good for heavy and/or light calculations, trust me :wink:

Posted: Fri Jun 24, 2005 10:00 pm
by Blade
Have to admit I've never used trigonometry a lot. I had many times, but just for small calculations, never coded something mainly based on trigonometry and such...
Ok, I thrust you... :)

Posted: Fri Jun 24, 2005 10:09 pm
by fweil
Just a point messing with Degree instructions in PureBasic : remember that when you think in degrees, you maybe want to STEP by one... which means integers.

But if you want to step by a float value, it is no more of interest to work in degrees because behind the FPU will translate it in radians.

Just with this, try to think all angles in radians and last do a Degree_Angle.l (or .f) = Radian_Angle * Pi / 180

It is generally not slower and makes all trigonometrics more clear.

Posted: Sat Jun 25, 2005 9:28 am
by Psychophanta
fweil wrote:Just with this, try to think all angles in radians and last do a Degree_Angle.l (or .f) = Radian_Angle * Pi / 180
It is generally not slower and makes all trigonometrics more clear.
hah! You see?, just for explaining, and you had one mistake:
Degree_Angle.l (or .f) = Radian_Angle * Pi / 180 :?:
And yes, this takes too much CPU time when operation time is critical.

Posted: Sat Jun 25, 2005 2:37 pm
by fweil
When it is time critical and just want to use degrees, I usually create arrays for Sin, Cos and Tan, ie, that allow to write MySinus(Degree)

It saves much CPU time

Posted: Sat Jun 25, 2005 2:40 pm
by Psychophanta
fweil wrote:When it is time critical and just want to use degrees, I usually create arrays for Sin, Cos and Tan, ie, that allow to write MySinus(Degree)

It saves much CPU time
Strange and inefficent way to save CPU time :)

Posted: Sat Jun 25, 2005 8:19 pm
by fweil
Did you really have a look ?

Code: Select all

Dim Sinus.f(359)
Dim Cosinus.f(359)
Dim Tangente.f(359)

  Pi.f = 3.14159265
  For i = 0 To 359
    Sinus(i) = Sin(i * Pi / 180)
    Cosinus(i) = Cos(i * Pi / 180)
    Tangente(i) = Tan(i * Pi / 180)
  Next
  
  NTimes = 10000000
  OpenConsole()
    
    tz = ElapsedMilliseconds()
    For i = 1 To NTimes
      Angle.l = Random(359)
      s.f = Sin(Angle * Pi / 180)
      c.f = Cos(Angle * Pi / 180)
      t.f = Tan(Angle * Pi / 180)
    Next
    PrintN(Str(ElapsedMilliseconds() - tz) + " " + StrF(Sin(45 * Pi / 180)))
    
    tz = ElapsedMilliseconds()
    For i = 1 To NTimes
      Angle.l = Random(359)
      s.f = Sinus(Angle)
      c.f = Cosinus(Angle)
      t.f = Tangente(Angle)
    Next
    PrintN(Str(ElapsedMilliseconds() - tz) + " " + StrF(Sinus(45)))
    
    While Inkey() = ""
    Wend
    
  CloseConsole()
  
End