atan2.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { factory } from '../../utils/factory.js';
  2. import { createMatAlgo02xDS0 } from '../../type/matrix/utils/matAlgo02xDS0.js';
  3. import { createMatAlgo03xDSf } from '../../type/matrix/utils/matAlgo03xDSf.js';
  4. import { createMatAlgo09xS0Sf } from '../../type/matrix/utils/matAlgo09xS0Sf.js';
  5. import { createMatAlgo11xS0s } from '../../type/matrix/utils/matAlgo11xS0s.js';
  6. import { createMatAlgo12xSfs } from '../../type/matrix/utils/matAlgo12xSfs.js';
  7. import { createMatrixAlgorithmSuite } from '../../type/matrix/utils/matrixAlgorithmSuite.js';
  8. var name = 'atan2';
  9. var dependencies = ['typed', 'matrix', 'equalScalar', 'BigNumber', 'DenseMatrix', 'concat'];
  10. export var createAtan2 = /* #__PURE__ */factory(name, dependencies, _ref => {
  11. var {
  12. typed,
  13. matrix,
  14. equalScalar,
  15. BigNumber,
  16. DenseMatrix,
  17. concat
  18. } = _ref;
  19. var matAlgo02xDS0 = createMatAlgo02xDS0({
  20. typed,
  21. equalScalar
  22. });
  23. var matAlgo03xDSf = createMatAlgo03xDSf({
  24. typed
  25. });
  26. var matAlgo09xS0Sf = createMatAlgo09xS0Sf({
  27. typed,
  28. equalScalar
  29. });
  30. var matAlgo11xS0s = createMatAlgo11xS0s({
  31. typed,
  32. equalScalar
  33. });
  34. var matAlgo12xSfs = createMatAlgo12xSfs({
  35. typed,
  36. DenseMatrix
  37. });
  38. var matrixAlgorithmSuite = createMatrixAlgorithmSuite({
  39. typed,
  40. matrix,
  41. concat
  42. });
  43. /**
  44. * Calculate the inverse tangent function with two arguments, y/x.
  45. * By providing two arguments, the right quadrant of the computed angle can be
  46. * determined.
  47. *
  48. * For matrices, the function is evaluated element wise.
  49. *
  50. * Syntax:
  51. *
  52. * math.atan2(y, x)
  53. *
  54. * Examples:
  55. *
  56. * math.atan2(2, 2) / math.pi // returns number 0.25
  57. *
  58. * const angle = math.unit(60, 'deg') // returns Unit 60 deg
  59. * const x = math.cos(angle)
  60. * const y = math.sin(angle)
  61. *
  62. * math.atan(2) // returns number 1.1071487177940904
  63. *
  64. * See also:
  65. *
  66. * tan, atan, sin, cos
  67. *
  68. * @param {number | Array | Matrix} y Second dimension
  69. * @param {number | Array | Matrix} x First dimension
  70. * @return {number | Array | Matrix} Four-quadrant inverse tangent
  71. */
  72. return typed(name, {
  73. 'number, number': Math.atan2,
  74. // Complex numbers doesn't seem to have a reasonable implementation of
  75. // atan2(). Even Matlab removed the support, after they only calculated
  76. // the atan only on base of the real part of the numbers and ignored
  77. // the imaginary.
  78. 'BigNumber, BigNumber': (y, x) => BigNumber.atan2(y, x)
  79. }, matrixAlgorithmSuite({
  80. scalar: 'number | BigNumber',
  81. SS: matAlgo09xS0Sf,
  82. DS: matAlgo03xDSf,
  83. SD: matAlgo02xDS0,
  84. Ss: matAlgo11xS0s,
  85. sS: matAlgo12xSfs
  86. }));
  87. });