04-10-2015, 08:23 AM
04-10-2015, 11:35 AM
If you have to roll your own atan2(y,x) function have a look at
http://en.wikipedia.org/wiki/Atan2
Martin
http://en.wikipedia.org/wiki/Atan2
Martin
04-10-2015, 11:41 AM
Here is a little atan2(y,x) program especially useful as a subroutine:
Code:
EXPORT atan2(y,x)
BEGIN
// atan2 returns coordinates in correct angle for all four quadrants
CASE
if x==0 AND y==0 then return "undefined"; end; // x=0, y=0
if x>0 then return atan(y/x); end; // x>0
if x<0 AND y>=0 then return atan(y/x)+pi; end; // x<0, y>=0
if x==0 AND y>0 then return pi/2; end; // x=0, y>0
if x<0 AND y<=0 then return atan(y/x)-pi; end; // x<0, y<0
if x==0 AND y<0 then return -pi/2; end; // x=0, y<0
END;
return;
END;
04-11-2015, 03:39 AM
Don't forget there is also ARG
ARG(x+i*y)=ATAN2(y,x),
and ARG is built-in.
ARG(x+i*y)=ATAN2(y,x),
and ARG is built-in.
04-12-2015, 09:27 PM
(04-11-2015 03:39 AM)Helge Gabert Wrote: [ -> ]Don't forget there is also ARG
ARG(x+i*y)=ATAN2(y,x),
and ARG is built-in.
I've just tried ARG for a handful of values and have noticed a few minor details that might be worth keeping in mind.
- Both home ARG and CAS arg respect the angle measure setting (radians / degrees).
- Home ARG returns an error for zero while the CAS arg returns 0.0.
- The CAS arg deals with large and small magnitude arguments in a different manner than home ARG does. (With CAS epsilon as 1E-12 and degrees angle measure, CAS arg returns undef for 1E309+i and for 1E-12*i, 90.0 for 1e-12+1e-11*i, and 84.2894068625 for 1.01e-12+1.01e-11*i.)