Skip to content

Latest commit

 

History

History

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).

Usage

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 NaN

Examples

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.565

The function accepts the following arguments:

  • y: [in] double - y coordinate.
  • x: [in] double - x coordinate.
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 );
    }
}