@phun-ky/angle
Version:
A JavaScript function to calculate the angle between two coordinates
154 lines (109 loc) • 5.03 kB
Markdown
# @phun-ky/angle
[](http://commitizen.github.io/cz-cli/)
[](http://makeapullrequest.com)
[](http://semver.org/spec/v2.0.0.html)






[](https://codecov.io/gh/phun-ky/angle)
[](https://github.com/phun-ky/angle/actions/workflows/check.yml)
## About
A JavaScript function to calculate the angle between two coordinates.
## Table of Contents<!-- omit from toc -->
- [@phun-ky/angle](#phun-kyangle)
- [About](#about)
- [Installation](#installation)
- [Usage](#usage)
- [API](#api)
- [angle()](#angle)
- [Development](#development)
- [Contributing](#contributing)
- [License](#license)
- [Changelog](#changelog)
- [Sponsor me](#sponsor-me)
## Installation
```shell-session
npm i --save @phun-ky/angle
```
## Usage
Either import and run the required functions:
```javascript
import { angle } from '@phun-ky/angle';
const angleValue = angle(0, 0, 3, 4);
console.log(angleValue); // 53.13
```
## API
### angle()
```ts
function angle(cx, cy, ex, ey, normalize?): number;
```
Defined in:
[main.ts:24](https://github.com/phun-ky/angle/blob/main/src/main.ts#L24)
Returns the angle between two sets of coordinates.
#### Parameters
| Parameter | Type | Default value | Description |
| ------------ | --------- | ------------- | ------------------------------------------------------------------------ |
| `cx` | `number` | `undefined` | The x-coordinate of the first point. |
| `cy` | `number` | `undefined` | The y-coordinate of the first point. |
| `ex` | `number` | `undefined` | The x-coordinate of the second point. |
| `ey` | `number` | `undefined` | The y-coordinate of the second point. |
| `normalize?` | `boolean` | `true` | If the angle output should be normalized to a value between 0° and 360°. |
#### Returns
`number`
The angle between the given coordinates.
#### Throws
Missing input for `angle`.
#### Throws
Parameters for `angle` do not have the required type.
#### Example
```ts
// Calculate the angle between two points
const angleValue = angle(0, 0, 3, 4);
console.log(angleValue); // 53.13
// Normalized
const angleValue = angle(0, 0, -3, -4, true);
console.log(angleValue); // 233.13
```
---
Full API documentation is available
[here](https://github.com/phun-ky/angle/blob/main/api/README.md).
## Development
```shell-session
// Build
$ npm run build
// Run dev
$ npm run dev
// Test
$ npm test
```
## Contributing
Want to contribute? Please read the
[CONTRIBUTING.md](https://github.com/phun-ky/angle/blob/main/CONTRIBUTING.md)
and
[CODE_OF_CONDUCT.md](https://github.com/phun-ky/angle/blob/main/CODE_OF_CONDUCT.md)
## License
This project is licensed under the MIT License - see the
[LICENSE](https://github.com/phun-ky/angle/blob/main/LICENSE) file for details.
## Changelog
See the [CHANGELOG.md](https://github.com/phun-ky/angle/blob/main/CHANGELOG.md)
for details on the latest updates.
## Sponsor me
I'm an Open Source evangelist, creating stuff that does not exist yet to help
get rid of secondary activities and to enhance systems already in place, be it
documentation or web sites.
The sponsorship is an unique opportunity to alleviate more hours for me to
maintain my projects, create new ones and contribute to the large community
we're all part of :)
[Support me on GitHub Sponsors](https://github.com/sponsors/phun-ky).

p.s. **Ukraine is still under brutal Russian invasion. A lot of Ukrainian people
are hurt, without shelter and need help**. You can help in various ways, for
instance, directly helping refugees, spreading awareness, putting pressure on
your local government or companies. You can also support Ukraine by donating
e.g. to [Red Cross](https://www.icrc.org/en/donate/ukraine),
[Ukraine humanitarian organisation](https://savelife.in.ua/en/donate-en/#donate-army-card-weekly)
or
[donate Ambulances for Ukraine](https://www.gofundme.com/f/help-to-save-the-lives-of-civilians-in-a-war-zone).