Page 1 of 1

ATAN2

Posted: Thu Sep 11, 2003 9:57 pm
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

Posted: Fri Sep 12, 2003 1:13 am
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

ATAN2

Posted: Fri Sep 12, 2003 1:06 pm
by tex
work fine, thank for this lightning response.

Tex