Re: FIND THE TRUE TAN WITHIN A CIRCLE
- Posted by "Carl R. White" <C.R.White at SCM.BRAD.AC.UK> Mar 23, 1999
- 564 views
On Mon, 22 Mar 1999 RodDamon at AOL.COM wrote: ] constant Pi=3.14159265359 --- Now in version 2.1 ] ] global function Sgn(atom x) ] if x>0 then ] return 1 ] elsif x<0 then ] return -1 ] else ] return 0 ] end if ] end function ] ] global function arctan2(atom Y, atom X) ] return ] abs(-arctan(X/(Y+(Y=0)))*-(Y!=0)-(Pi*.5)*Sgn(X)*-(Y=0)+Pi*-(Y<0)*(-(X>=0)+(X<0 ] ))+(-Pi*2)*-(X<0)) ] ] WHERE X & Y ARE: ] ] +Y ] I ] I ] -X -------------- +X ] I ] I ] -Y I attempted to simplify your code, but something doesn't seem right... global function arctan2(atom y, atom x) integer yeo, ylo, xlo -- conditions yeo = (y = 0) -- I hope the names are obvious enough :) ylo = (y < 0) xlo = (x < 0) return abs( -- you haven't defined abs() but I think we all know what -- it means :)... Are you sure all answers should be +ve? -- Calculation block: -- Result Section * Condition Section + arctan( x/(y+yeo) ) * (1-yeo) -- note the unary '+' + Sgn(X)*(Pi/2) * yeo + Pi * ylo * (1-2*xlo) + 2*Pi * xlo ) end function I can cope with obfuscated shortest-Euphoria code, in fact I'm a great lover of it (I did similar things in Commodore BASIC many moons ago) but not at the level you showed in your example! Ooh, my head hurts :) Carl PS Nice work by the way... -- Carl R White -- cyrek- at -bigfoot.com -- http://www.bigfoot.com/~cyrek aka Cyrek -- No hyphens :) -- Bigfoot URL Alias