
Angle.f parameters always in radians
- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
Angle.f parameters always in radians
Please, for consistence and elegance consider Angle.f parameter value given as radians, not as degrees, for all the functions 

What about adding a flag to support each?

Code: Select all
SomeProcedure(Angle.f, #PB_Radians)
SomeProcedure(Angle.f, #PB_Degrees)

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
MikeB
- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
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
So, i request to use radians for all, for RotateSprite3D(), etc...
matter of consistence

-
- Enthusiast
- Posts: 362
- Joined: Wed Aug 06, 2003 2:49 pm
- Location: Venice - Italy, Japan when possible.
- Contact:
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

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

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.
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.
- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
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.
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.
- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
hah! You see?, just for explaining, and you had one mistake: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.
And yes, this takes too much CPU time when operation time is critical.Degree_Angle.l (or .f) = Radian_Angle * Pi / 180![]()
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
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.
- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
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.