Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mikolalysenko/compare-slope
Checks if a pair of 2D vectors are oriented CW/CCW relatively
https://github.com/mikolalysenko/compare-slope
Last synced: about 2 months ago
JSON representation
Checks if a pair of 2D vectors are oriented CW/CCW relatively
- Host: GitHub
- URL: https://github.com/mikolalysenko/compare-slope
- Owner: mikolalysenko
- License: mit
- Created: 2013-04-01T18:53:12.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2013-05-14T00:11:26.000Z (over 11 years ago)
- Last Synced: 2024-10-10T21:42:47.580Z (3 months ago)
- Language: JavaScript
- Size: 105 KB
- Stars: 5
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
compare-slope
=============
Ranks the slope of a pair of vectors through the origin in clockwise order. This is more robust than comparing their arc tangents using atan2.Use
===
First install using npm:npm install compare-slope
Then use as follows:```javascript
var compareSlope = require("compare-slope")console.log(compareSlope([0, 1], [1, 2]))
```### `require("compare-slope")(a, b)`
Checks whether `a` comes before `b` in a counter-clockwise ordering.* `a` and `b` are both represented by arrays of at least length 2
**Returns:**
* `> 0` if `b` is clockwise from `a`
* `< 0` if `a` is clockwise from `b`
* `0` if `a` and `b` are collinear**Note:** Somewhat arbitrarily, the degenerate point at the origin is ranked before all other points.
Credits
=======
(c) 2013 Mikola Lysenko. MIT License