Re: atan2

new topic     » goto parent     » topic index » view thread      » older message » newer message

Liquid-Nitrogen Software wrote:
>
> i think atan2(x, y)
> is sposed to return a, where sin(a) = x and cos(a) = y
> anyone know how to do this?
>
> thanx.

------------------------------------------------------------------------------
include misc.e          -- PI
--
         c2PI   = 2*PI,
         cPIH   = 0.5*PI
------------------------------------------------------------------------------
function arctan2 ( object y, object x)  -- returns 4 quadrant angle
[-ã,ã)
    sequence s                          -- x and y have to have equal
structure!
    if atom(x) then
        if x > 0 then
            return arctan(y/x)
        elsif x < 0 then
            if y > 0 then
               return arctan(y/x) + PI
            elsif y < 0 then
               return arctan(y/x) - PI
            else    -- y = 0
               return -PI
            end if
        else    -- x = 0
            if y > 0 then
                return cPIH
            elsif y < 0 then
                return -cPIH
            else    -- y = 0
                return 0
            end if
        end if
    end if
--  sequence s
    s = repeat(0,length(y))
    for i = 1 to length(y) do
        s[i] = arctan2(y[i],x[i])
    end for
    return s
end function
------------------------------------------------------------------------------

Hope this helps.
Nave a nice day, Rolf

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu