We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 08d8c6b commit 36e2b16Copy full SHA for 36e2b16
Geometry/ConvexHullGraham.js
@@ -13,16 +13,10 @@ function compare(a, b) {
13
return 1
14
}
15
function orientation(a, b, c) {
16
- // Check orientation of Line(a, b) and Line(b, c)
17
- const alpha = (b.y - a.y) / (b.x - a.x)
18
- const beta = (c.y - b.y) / (c.x - b.x)
+ const crossProduct = (b.y - a.y) * (c.x - b.x) - (b.x - a.x) * (c.y - b.y);
19
20
- // Clockwise
21
- if (alpha > beta) return 1
22
- // Anticlockwise
23
- else if (beta > alpha) return -1
24
- // Colinear
25
- return 0
+ if(crossProduct === 0) return 0;
+ return (crossProduct > 0) ? 1 : -1;
26
27
28
function convexHull(points) {
0 commit comments