UNPKG

4.72 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.createAtan2 = void 0;
7
8var _factory = require("../../utils/factory");
9
10var _algorithm = require("../../type/matrix/utils/algorithm02");
11
12var _algorithm2 = require("../../type/matrix/utils/algorithm03");
13
14var _algorithm3 = require("../../type/matrix/utils/algorithm09");
15
16var _algorithm4 = require("../../type/matrix/utils/algorithm11");
17
18var _algorithm5 = require("../../type/matrix/utils/algorithm12");
19
20var _algorithm6 = require("../../type/matrix/utils/algorithm13");
21
22var _algorithm7 = require("../../type/matrix/utils/algorithm14");
23
24var name = 'atan2';
25var dependencies = ['typed', 'matrix', 'equalScalar', 'BigNumber', 'DenseMatrix'];
26var createAtan2 = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
27 var typed = _ref.typed,
28 matrix = _ref.matrix,
29 equalScalar = _ref.equalScalar,
30 BigNumber = _ref.BigNumber,
31 DenseMatrix = _ref.DenseMatrix;
32 var algorithm02 = (0, _algorithm.createAlgorithm02)({
33 typed: typed,
34 equalScalar: equalScalar
35 });
36 var algorithm03 = (0, _algorithm2.createAlgorithm03)({
37 typed: typed
38 });
39 var algorithm09 = (0, _algorithm3.createAlgorithm09)({
40 typed: typed,
41 equalScalar: equalScalar
42 });
43 var algorithm11 = (0, _algorithm4.createAlgorithm11)({
44 typed: typed,
45 equalScalar: equalScalar
46 });
47 var algorithm12 = (0, _algorithm5.createAlgorithm12)({
48 typed: typed,
49 DenseMatrix: DenseMatrix
50 });
51 var algorithm13 = (0, _algorithm6.createAlgorithm13)({
52 typed: typed
53 });
54 var algorithm14 = (0, _algorithm7.createAlgorithm14)({
55 typed: typed
56 });
57 /**
58 * Calculate the inverse tangent function with two arguments, y/x.
59 * By providing two arguments, the right quadrant of the computed angle can be
60 * determined.
61 *
62 * For matrices, the function is evaluated element wise.
63 *
64 * Syntax:
65 *
66 * math.atan2(y, x)
67 *
68 * Examples:
69 *
70 * math.atan2(2, 2) / math.pi // returns number 0.25
71 *
72 * const angle = math.unit(60, 'deg') // returns Unit 60 deg
73 * const x = math.cos(angle)
74 * const y = math.sin(angle)
75 *
76 * math.atan(2) // returns Complex 1.5707963267948966 -1.3169578969248166 i
77 *
78 * See also:
79 *
80 * tan, atan, sin, cos
81 *
82 * @param {number | Array | Matrix} y Second dimension
83 * @param {number | Array | Matrix} x First dimension
84 * @return {number | Array | Matrix} Four-quadrant inverse tangent
85 */
86
87 var atan2 = typed(name, {
88 'number, number': Math.atan2,
89 // Complex numbers doesn't seem to have a reasonable implementation of
90 // atan2(). Even Matlab removed the support, after they only calculated
91 // the atan only on base of the real part of the numbers and ignored the imaginary.
92 'BigNumber, BigNumber': function BigNumberBigNumber(y, x) {
93 return BigNumber.atan2(y, x);
94 },
95 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
96 return algorithm09(x, y, atan2, false);
97 },
98 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
99 // mind the order of y and x!
100 return algorithm02(y, x, atan2, true);
101 },
102 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
103 return algorithm03(x, y, atan2, false);
104 },
105 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
106 return algorithm13(x, y, atan2);
107 },
108 'Array, Array': function ArrayArray(x, y) {
109 return atan2(matrix(x), matrix(y)).valueOf();
110 },
111 'Array, Matrix': function ArrayMatrix(x, y) {
112 return atan2(matrix(x), y);
113 },
114 'Matrix, Array': function MatrixArray(x, y) {
115 return atan2(x, matrix(y));
116 },
117 'SparseMatrix, number | BigNumber': function SparseMatrixNumberBigNumber(x, y) {
118 return algorithm11(x, y, atan2, false);
119 },
120 'DenseMatrix, number | BigNumber': function DenseMatrixNumberBigNumber(x, y) {
121 return algorithm14(x, y, atan2, false);
122 },
123 'number | BigNumber, SparseMatrix': function numberBigNumberSparseMatrix(x, y) {
124 // mind the order of y and x
125 return algorithm12(y, x, atan2, true);
126 },
127 'number | BigNumber, DenseMatrix': function numberBigNumberDenseMatrix(x, y) {
128 // mind the order of y and x
129 return algorithm14(y, x, atan2, true);
130 },
131 'Array, number | BigNumber': function ArrayNumberBigNumber(x, y) {
132 return algorithm14(matrix(x), y, atan2, false).valueOf();
133 },
134 'number | BigNumber, Array': function numberBigNumberArray(x, y) {
135 return algorithm14(matrix(y), x, atan2, true).valueOf();
136 }
137 });
138 return atan2;
139});
140exports.createAtan2 = createAtan2;
\No newline at end of file