compare-slope
Use https://www.npmjs.org/package/robust-orientation instead
Compares the slopes of a pair of 2D vectors
npm install compare-slope
Want to see pretty graphs? Log in now!
3 | downloads in the last week |
7 | downloads in the last month |
Last Published By | |
---|---|
Version | 0.0.0 last updated a year ago |
License | MIT |
Keywords | slope, vector, 2d, point, atan, tangent, atan2, arc, angle, polar |
Repository | git://github.com/mikolalysenko/compare-slope.git (git) |
Dependencies | None |
Dependents | mikolalysenko-hoarders, vishull2d |
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:
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
andb
are both represented by arrays of at least length 2
Returns:
> 0
ifb
is clockwise froma
< 0
ifa
is clockwise fromb
0
ifa
andb
are collinear
Note: Somewhat arbitrarily, the degenerate point at the origin is ranked before all other points.
Credits
(c) 2013 Mikola Lysenko. MIT License