ATAN2

Just starting out? Need help? Post your questions and find answers here.
tex
New User
New User
Posts: 2
Joined: Sat Sep 06, 2003 9:15 pm

ATAN2

Post by tex »

how to translate this blitz function in pureB.

----
ATan2 (xvalue,yvalue)
Definition:Returns the angle from the X axis to a point (y,x).
----

Thanks

Tex
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Post by jack »

don't have blitz basic, but try the following function i adapted
from Paul Dixon's atan2.
please visit http://www.powerbasic.com/support/forum ... 09180.html
for more details.

Code: Select all

Procedure.f atan2(y.f,x.f)
;atan2 procedure by Paul Dixon
;http://www.powerbasic.com/support/forums/Forum4/HTML/009180.html
;adapted to PureBasic by Jack
! fld dword [esp]     ;load y
! fld dword [esp+4]   ;load x
! fpatan              ;get atan(y/x), put result in ST1. then pop stack to leave result in ST0
! ftst                ;test ST0 (that's the top of stack) against zero
! fstsw ax            ;put result of test into AX
! sahf                ;get the FPU flags into the CPU flags
! jae @@skip          ; if above or equal then skip the add 2*pi code
! fldpi               ;get pi
! fadd st1,st0        ;add pi to result
! faddp st1,st0       ;and again, for 2pi, then pop the now unneeded pi from st0
! @@skip:
EndProcedure
example usage:
x.f=-0.1
y.f=-0.1
z.f=57.29578*atan2(y,x) ;multiply by 57.29578 to get degrees
tex
New User
New User
Posts: 2
Joined: Sat Sep 06, 2003 9:15 pm

ATAN2

Post by tex »

work fine, thank for this lightning response.

Tex
Post Reply