atan2.js 2.6 KB

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