December 2005
Beginner to intermediate
618 pages
20h 19m
English
atan2
Calculates the inverse tangent of a quotient
#include <math.h> doubleatan2( doubley, doublex); floatatan2f( floaty, floatx); (C99) long doubleatan2l( long doubley, long doublex); (C99)
The atan2() function
divides the first argument by the second and returns the arc tangent
of the result, or arctan(y/x).
The return value is given in radians, and is in the range -π ≤
atan2(y,x) ≤ π. The signs of
x and y
determine the quadrant of the result:
x > 0,
y > 0:0 ≤ atan2(
y,x) ≤ π/2
x < 0,
y > 0:π/2 ≤ atan2(
y,x) ≤ π
x < 0,
y < 0:-π ≤ atan2(
y,x) ≤ -π/2
x > 0,
y < 0:-π/2 ≤ atan2(
y,x) ≤ 0
If both arguments are zero, then the function may incur a domain error.
/*
* Calculate an acute angle of a right triangle, given
* the adjacent and opposite sides.
*/
#define PI 3.141593
#define DEG_PER_RAD (180.0/PI)
double adjacent = 3.0;
double opposite = 4.0;
double angle =atan2( opposite, adjacent ) * DEG_PER_RAD;
printf( "The acute angles of a 3-4-5 right triangle are %4.2f\xB0 "
"and %4.2f\xB0.\n", angle, 90.0 - angle );This code produces the following output:
The acute angles of a 3-4-5 right triangle are 53.13° and 36.87°.
The arc tangent function for a single argument: atan()
Read now
Unlock full access