https://github.com/semibran/vector
Minimal operations for multidimensional vectors
https://github.com/semibran/vector
geometry math multidimensional trigonometry vector
Last synced: about 1 year ago
JSON representation
Minimal operations for multidimensional vectors
- Host: GitHub
- URL: https://github.com/semibran/vector
- Owner: semibran
- License: mit
- Created: 2017-04-19T07:12:40.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-06-27T02:12:34.000Z (almost 9 years ago)
- Last Synced: 2025-02-28T09:43:10.360Z (about 1 year ago)
- Topics: geometry, math, multidimensional, trigonometry, vector
- Language: JavaScript
- Homepage:
- Size: 10.7 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# vctr
> Minimal operations for multidimensional vectors
This module assumes that a vector is an array of numbers, allowing these functions to be used on vectors of all dimensions.
## install
```sh
npm install vctr
```
## usage
```js
const { add, subtract, ... } = require('vctr')
```
### `add(a, b)`
Returns the sum of the two provided vectors.
### `subtract(a, b)`
Returns the difference between the two provided vectors.
### `multiply(a, b)`
Returns the product of the two provided vectors. The second argument may be a scalar quantity (a `Number`) if desired.
### `divide(a, b)`
Returns the quotient of the two provided vectors. The second argument may be a scalar quantity (a `Number`) if desired.
### `dot(a, b)`
Determines the dot product of the two provided vectors.
### `compose(vector)`
Converts `vector` from Cartesian coordinates to spherical coordinates `{ direction, magnitude }`.
### `resolve(vector)`
Converts `vector` from spherical coordinates to Cartesian coordinates.
### `direction(vector)`
Calculates the direction in which `vector` is pointing, in radians.
### `magnitude(vector)`
Calculates the distance covered by `vector`.
### `normalize(vector)`
Converts `vector` to a unit vector.
### `distance(a, b)`
Determines the distance (a scalar quantity) between the two provided vectors.
## see also
- [`semibran/radians`](https://github.com/semibran/radians) - convert between radians and degrees
## license
[MIT](https://opensource.org/licenses/MIT) © [Brandon Semilla](https://git.io/semibran)