tcl::mathfunc atan2
Gives the angle of the point at X and Y, in radians.
tcl::mathfunc::atan2 Y X
expr {atan2(Y, X)}
Description
Gives the angle from the positive x axis to the point (X, Y), from -pi to pi. The signs of both arguments choose the quadrant, so atan2(0, -1) is pi. atan2(0, 0) is 0.0. Y comes first.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| Y | number | required | The y coordinate. |
| X | number | required | The x coordinate. |
Returns
A float from -pi to pi.
Examples
% expr {atan2(1, 1)}
0.7853981633974483
% expr {atan2(0, -1)}
3.141592653589793
% expr {atan2(-1, 0)}
-1.5707963267948966
% expr {atan2(0, 0)}
0.0
Errors
% expr {atan2(1)}
not enough arguments for math function "atan2"
-errorcode TCL WRONGARGS
# Tcl 9.1 only
% expr {atan2(1, "x")}
cannot use non-numeric string "x" as operand of "atan2"
-errorcode ARITH DOMAIN {non-numeric string}
# Tcl 8.6 only
% expr {atan2(1, "x")}
can't use non-numeric string as operand of "atan2"
-errorcode ARITH DOMAIN {non-numeric string}
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztcl 1.0.0-beta.1