@stdlib/math-base-special-atan2d
v0.1.1
Published
Compute the angle in the plane (in degrees) between the positive x-axis and the ray from (0,0) to the point (x,y).
Readme
atan2d
Compute the angle in the plane (in degrees) between the positive x-axis and the ray from
(0,0)to the point(x,y).
Installation
npm install @stdlib/math-base-special-atan2dUsage
var atan2d = require( '@stdlib/math-base-special-atan2d' );atan2d( y, x )
Computes the angle in the plane (in degrees) between the positive x-axis and the ray from (0,0) to the point (x,y).
var v = atan2d( 2.0, 2.0 ); // => atand(1.0)
// returns ~45.0
v = atan2d( 6.0, 2.0 ); // => atand(3.0)
// returns ~71.565
v = atan2d( -1.0, -1.0 ); // => atand(1.0) - 180.0
// returns ~-135.0
v = atan2d( 3.0, 0.0 );
// returns 90.0
v = atan2d( -2.0, 0.0 );
// returns -90.0
v = atan2d( 0.0, 0.0 );
// returns 0.0
v = atan2d( 3.0, NaN );
// returns NaNExamples
var uniform = require( '@stdlib/random-array-uniform' );
var logEachMap = require( '@stdlib/console-log-each-map' );
var atan2d = require( '@stdlib/math-base-special-atan2d' );
var x = uniform( 100, 0.0, 100.0 );
var y = uniform( 100, 0.0, 100.0 );
logEachMap( 'y: %0.4f, x: %0.4f, atan2d(y,x): %0.4f', y, x, atan2d );C APIs
Usage
#include "stdlib/math/base/special/atan2d.h"stdlib_base_atan2d( y, x )
Computes the angle in the plane (in degrees) between the positive x-axis and the ray from (0,0) to the point (x,y).
double out = stdlib_base_atan2d( 2.0, 2.0 );
// returns ~45.0
out = stdlib_base_atan2d( 6.0, 2.0 );
// returns ~71.565The function accepts the following arguments:
- y:
[in] double-ycoordinate. - x:
[in] double-xcoordinate.
double stdlib_base_atan2d( const double y, const double x );Examples
#include "stdlib/math/base/special/atan2d.h"
#include <stdlib.h>
#include <stdio.h>
static double random_uniform( const double min, const double max ) {
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
return min + ( v*(max-min) );
}
int main( void ) {
double y;
double x;
double v;
int i;
for ( i = 0; i < 100; i++ ) {
y = random_uniform( 0.0, 100.0 );
x = random_uniform( 0.0, 100.0 );
v = stdlib_base_atan2d( y, x );
printf( "atan2d(%lf, %lf) = %lf\n", y, x, v );
}
}Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2026. The Stdlib Authors.
