Last active
March 10, 2022 12:44
-
-
Save AntiHero/2ba0e13e73b96f6ea24bd457892ad40c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const polygonArea = (ps) => { | |
const v = ps.reduce( | |
(acc, p, i) => (acc += p.x * ps.at(i - 1).y - ps.at(i - 1).x * p.y), | |
0 | |
); | |
return Math.abs(v) / 2; | |
}; | |
// or | |
const polygonArea = (ps) => | |
ps.reduce( | |
(acc, p, i) => (acc += Math.abs(p.x * ps.at(i - 1).y - ps.at(i - 1).x * p.y)), | |
0 | |
) / 2; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment