TAN Function
Action
Returns the tangent of the angle x, where x is in radians.
Syntax
TAN( x)
Remarks
The tangent of an angle in a right triangle is the ratio between the length
of the side opposite an angle and the length of the side adjacent to it.
TAN is calculated in single precision if x is an integer or
single-precision value. If you use any other numeric data type, TAN is
calculated in double precision.
To convert values from degrees to radians, multiply the angle (in degrees)
times -180
(or .0174532925199433). To convert a radian value to degrees, multiply it by
180-
(or 57.2957795130824). In both cases, 3.141593.
BASICA
In BASICA, if TAN overflows, the interpreter generates an error message
that reads Overflow, returns machine infinity as the result, and continues
execution.
If TAN overflows, BASIC does not display machine infinity and execution
halts (unless the program has an error-handling routine).
See Also
ATN, COS, SIN
Example
The following example computes the height of an object using the distance
from the object and the angle of elevation. The program draws the triangle
produced by the base and the computed height.
SCREEN 2' CGA screen mode.
INPUT "LENGTH OF BASE. ",Baselen
INPUT "ANGLE OF ELEVATION (DEGREES,MINUTES). ",Deg,Min
Ang = (3.141593-180) * (Deg + Min-60)' Convert to radians.
Height = Baselen * TAN(Ang)' Calculate height.
PRINT "HEIGHT =" Height
Aspect = 4 * (200 - 640) - 3' Screen 2 is 640 x 200 pixels.
H = 180 - Height
B = 15 + (Baselen - Aspect)
LINE (15,180)-(B,180)' Draw triangle.
LINE -(B,H)
LINE -(10,180)
LOCATE 24,1 . PRINT "Press any key to continue...";
DO
LOOP WHILE INKEY$=""