Angle.f parameters always in radians

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Angle.f parameters always in radians

Post by Psychophanta »

Please, for consistence and elegance consider Angle.f parameter value given as radians, not as degrees, for all the functions :)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Blade
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Aug 06, 2003 2:49 pm
Location: Venice - Italy, Japan when possible.
Contact:

Post by Blade »

Why not all degrees? Despite I know what radiants are, degrees are much more easy to handle...
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

What about adding a flag to support each?

Code: Select all

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

Image
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

Well, it's so much easier to use degrees for that kind of stuff 8)
MikeB
Enthusiast
Enthusiast
Posts: 183
Joined: Sun Apr 27, 2003 8:39 pm
Location: Cornwall UK

Post 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
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post 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 :)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Blade
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Aug 06, 2003 2:49 pm
Location: Venice - Italy, Japan when possible.
Contact:

Post 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:
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post 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.
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post 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:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Blade
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Aug 06, 2003 2:49 pm
Location: Venice - Italy, Japan when possible.
Contact:

Post 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... :)
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post 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.
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post 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.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post 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
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post 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 :)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post 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
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
Post Reply