1. atan2

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.

new topic     » topic index » view message » categorize

2. Re: atan2

Mark Honnor writes:
> i think atan2(x, y)
> is sposed to return a, where sin(a) = x and cos(a) = y
> anyone know how to do this?

Probably it's the other way around:
sin(a) = y and cos(a) = x
and therefore tan(a) = sin(a)/cos(a) = y/x
So a = arctan(y/x) *except* that Euphoria's arctan() function
always returns an angle between -PI/2 and +PI/2, so
to find out the true angle you must *also* take the sign +/- of x
and y into account to see what quadrant you are in.
e.g. if x is negative and y is positive
the angle must be greater than PI/2 and less than PI.
(There are 2PI radians in a circle, i.e. 360 degrees)
If x is positive, arctan() should give you the correct result,
but if x is negative you'll have to compute PI plus or minus the
angle given by arctan(). I'd draw a diagram but it would be
messed up by proportional fonts.

Regards,
     Rob Craig
     Rapid Deployment Software
     http://members.aol.com/FilesEu/

new topic     » goto parent     » topic index » view message » categorize

3. Re: atan2

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 message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu