Re: atan2

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

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 thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu