UNPKG

@nexys/math-ts

Version:

[![npm version](https://badge.fury.io/js/%40nexys%2Fmath-ts.svg)](https://www.npmjs.com/package/@nexys/math-ts) [![TavisCI](https://travis-ci.com/Nexysweb/tableau-wdc-react.svg?branch=master)](https://travis-ci.com/github/Nexysweb/math-ts) [![Deployment](

35 lines (34 loc) 1.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.toPolar = (x, y) => { const modulus = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)); const arg = Math.atan2(y, x); return [modulus, arg]; }; exports.toCartesian = (x, y) => [x * Math.cos(y), x * Math.sin(y)]; exports.toCylindrical = (x, y, z) => { const [modulus, arg] = exports.toPolar(x, y); return [modulus, arg, z]; }; exports.toCartesianFromCylindrical = (modulus, arg, z) => { const [x, y] = exports.toCartesian(modulus, arg); return [x, y, z]; }; exports.toSpherical = (x, y, z) => { const r = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2)); const t = Math.acos(z / r); const a = Math.atan2(y, x); return [r, a, t]; }; exports.toSphericalFromCylindrical = (modulus, arg, z) => { const [r, a] = exports.toPolar(z, modulus); return [r, arg, a]; }; exports.toCylindricalFromSpherical = (r, t, a) => { const [modulus, arg] = exports.toCartesian(r, a); return [arg, t, modulus]; }; exports.toCartesianFromSpherical = (r, t, a) => { const x = exports.toCylindricalFromSpherical(r, t, a); return exports.toCartesianFromCylindrical(x[0], x[1], x[2]); };