Version 6 of atan

Updated 2003-04-13 14:49:36

Purpose: Explain the math function atan.


The call,

    [expr { atan( $x ) }]

returns the arcus tangent (inverse tangent) of the number, $x. The resulting angle is measured in radians.


The most common reason for computing an arctangent is to determine the angle from the positive x-axis to a vector in the plane, but for that purpose it is much better to use atan2. Consider the point (x,y) = (-1,1). The angle to this point is 3/4*pi and the tangent for this vector is -1, but

 % expr atan(-1)
 -0.785398

i.e., the angle -1/4*pi, on account on the fact that this angle also has tangent -1. atan2 can distinguish the two:

 % expr atan2(1,-1)
 2.35619
 % expr atan2(-1,1)
 -0.785398

atan provides a handy way to ask Tcl for the value of pi:

 % expr {atan(1) * 4}
 3.1415926535897931

Actually, using acos() is (slightly) more efficient:

 % set tcl_precision 17
 17
 % expr {acos(-1)}
 3.1415926535897931

Does anyone have any data on which method is preferable from a numerical point of view?


atan is also available in Tclx.


Math function help - Arts and Crafts of Tcl-Tk Programming - Category Mathematics