|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2025 The Stdlib Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +
|
| 19 | +--> |
| 20 | + |
| 21 | +# atan2d |
| 22 | + |
| 23 | +> Compute the angle in the plane (in degrees) between the positive x-axis and the ray from `(0,0)` to the point `(x,y)`. |
| 24 | +
|
| 25 | +<section class="usage"> |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```javascript |
| 30 | +var atan2d = require( '@stdlib/math/base/special/atan2d' ); |
| 31 | +``` |
| 32 | + |
| 33 | +#### atan2d( y, x ) |
| 34 | + |
| 35 | +Computes the angle in the plane (in degrees) between the positive x-axis and the ray from `(0,0)` to the point `(x,y)`. |
| 36 | + |
| 37 | +```javascript |
| 38 | +var v = atan2d( 2.0, 2.0 ); // => atand(1.0) |
| 39 | +// returns ~45.0 |
| 40 | + |
| 41 | +v = atan2d( 6.0, 2.0 ); // => atand(3.0) |
| 42 | +// returns ~71.565 |
| 43 | + |
| 44 | +v = atan2d( -1.0, -1.0 ); // => atand(1.0) - 180.0 |
| 45 | +// returns ~-135.0 |
| 46 | + |
| 47 | +v = atan2d( 3.0, 0.0 ); |
| 48 | +// returns 90.0 |
| 49 | + |
| 50 | +v = atan2d( -2.0, 0.0 ); |
| 51 | +// returns -90.0 |
| 52 | + |
| 53 | +v = atan2d( 0.0, 0.0 ); |
| 54 | +// returns 0.0 |
| 55 | + |
| 56 | +v = atan2d( 3.0, NaN ); |
| 57 | +// returns NaN |
| 58 | +``` |
| 59 | + |
| 60 | +</section> |
| 61 | + |
| 62 | +<!-- /.usage --> |
| 63 | + |
| 64 | +<section class="examples"> |
| 65 | + |
| 66 | +## Examples |
| 67 | + |
| 68 | +<!-- eslint no-undef: "error" --> |
| 69 | + |
| 70 | +```javascript |
| 71 | +var uniform = require( '@stdlib/random/array/uniform' ); |
| 72 | +var logEachMap = require( '@stdlib/console/log-each-map' ); |
| 73 | +var atan2d = require( '@stdlib/math/base/special/atan2d' ); |
| 74 | + |
| 75 | +var x = uniform( 100, 0.0, 100.0 ); |
| 76 | +var y = uniform( 100, 0.0, 100.0 ); |
| 77 | + |
| 78 | +logEachMap( 'y: %0.4f, x: %0.4f, atan2d(y,x): %0.4f', y, x, atan2d ); |
| 79 | +``` |
| 80 | + |
| 81 | +</section> |
| 82 | + |
| 83 | +<!-- /.examples --> |
| 84 | + |
| 85 | +<!-- C interface documentation. --> |
| 86 | + |
| 87 | +* * * |
| 88 | + |
| 89 | +<section class="c"> |
| 90 | + |
| 91 | +## C APIs |
| 92 | + |
| 93 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 94 | + |
| 95 | +<section class="intro"> |
| 96 | + |
| 97 | +</section> |
| 98 | + |
| 99 | +<!-- /.intro --> |
| 100 | + |
| 101 | +<!-- C usage documentation. --> |
| 102 | + |
| 103 | +<section class="usage"> |
| 104 | + |
| 105 | +### Usage |
| 106 | + |
| 107 | +```c |
| 108 | +#include "stdlib/math/base/special/atan2d.h" |
| 109 | +``` |
| 110 | + |
| 111 | +#### stdlib_base_atan2d( y, x ) |
| 112 | + |
| 113 | +Computes the angle in the plane (in degrees) between the positive x-axis and the ray from `(0,0)` to the point `(x,y)`. |
| 114 | + |
| 115 | +```c |
| 116 | +double out = stdlib_base_atan2d( 2.0, 2.0 ); |
| 117 | +// returns ~45.0 |
| 118 | + |
| 119 | +out = stdlib_base_atan2d( 6.0, 2.0 ); |
| 120 | +// returns ~71.565 |
| 121 | +``` |
| 122 | + |
| 123 | +The function accepts the following arguments: |
| 124 | + |
| 125 | +- **y**: `[in] double` - `y` coordinate. |
| 126 | +- **x**: `[in] double` - `x` coordinate. |
| 127 | + |
| 128 | +```c |
| 129 | +double stdlib_base_atan2d( const double y, const double x ); |
| 130 | +``` |
| 131 | +
|
| 132 | +</section> |
| 133 | +
|
| 134 | +<!-- /.usage --> |
| 135 | +
|
| 136 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 137 | +
|
| 138 | +<section class="notes"> |
| 139 | +
|
| 140 | +</section> |
| 141 | +
|
| 142 | +<!-- /.notes --> |
| 143 | +
|
| 144 | +<!-- C API usage examples. --> |
| 145 | +
|
| 146 | +<section class="examples"> |
| 147 | +
|
| 148 | +### Examples |
| 149 | +
|
| 150 | +```c |
| 151 | +#include "stdlib/math/base/special/atan2d.h" |
| 152 | +#include <stdlib.h> |
| 153 | +#include <stdio.h> |
| 154 | +
|
| 155 | +static double random_uniform( const double min, const double max ) { |
| 156 | + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); |
| 157 | + return min + ( v*(max-min) ); |
| 158 | +} |
| 159 | +
|
| 160 | +int main( void ) { |
| 161 | + double y; |
| 162 | + double x; |
| 163 | + double v; |
| 164 | + int i; |
| 165 | +
|
| 166 | + for ( i = 0; i < 100; i++ ) { |
| 167 | + y = random_uniform( 0.0, 100.0 ); |
| 168 | + x = random_uniform( 0.0, 100.0 ); |
| 169 | + v = stdlib_base_atan2d( y, x ); |
| 170 | + printf( "atan2d(%lf, %lf) = %lf\n", y, x, v ); |
| 171 | + } |
| 172 | +} |
| 173 | +``` |
| 174 | + |
| 175 | +</section> |
| 176 | + |
| 177 | +<!-- /.examples --> |
| 178 | + |
| 179 | +</section> |
| 180 | + |
| 181 | +<!-- /.c --> |
| 182 | + |
| 183 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 184 | + |
| 185 | +<section class="related"> |
| 186 | + |
| 187 | +</section> |
| 188 | + |
| 189 | +<!-- /.related --> |
| 190 | + |
| 191 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 192 | + |
| 193 | +<section class="links"> |
| 194 | + |
| 195 | +<!-- <related-links> --> |
| 196 | + |
| 197 | +<!-- </related-links> --> |
| 198 | + |
| 199 | +</section> |
| 200 | + |
| 201 | +<!-- /.links --> |
0 commit comments