Poor man Sin() question

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by WolfgangS.

Hi !

Question 1:
Why do have my angle to reach 6.3 !?!?!? Until it will close the full 'circle' ? (e.g. 0...1...0...-1...0)

Question 2:
Is it possible to use a long variable with Sinus ?
Similar to:
Sin(90) = 1 ????
Sin(270)=-1 ????

MFG
:)WolfgangS

InitKeyboard()
angle.f=0
Repeat
angle+0.03
Debug Sin(angle)
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape) Or angle>6.3
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

What you want is sinus of an angle (degree):

Code: Select all

Procedure.f GSin(Angle.f)   ; Input : Angle ( 0 - 360 )
   ProcedureReturn Sin(Angle*(2*3.14159265/360))
EndProcedure 
  
Procedure.f GCos(Angle.f) 
   ; Input : Angle ( 0 - 360 )
   ProcedureReturn Cos(Angle*(2*3.14159265/360))
EndProcedure
For examples that use it, see: viewtopic.php?t=2091 and viewtopic.php?t=2016

cya,
...Danilo

(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Stan.

Hi,

That because angles are in radian, so 360° = 2*Pi radians, (as
implied by Danilo's post) where Pi = 3.141592...,
so 2 * Pi = 6.2832... and your program use the values 6.27 then
6.3 ...

BTW Fred, having double (long float), would help there ...

Bests.

Stan.


Since I attended an MS course, my programs no longer have bugs ... just hidden "features" !! [ PB. registered user ]
Post Reply