Created
August 22, 2016 16:16
-
-
Save paulzi/64a87ae17ae6b28487918cfe649603fc to your computer and use it in GitHub Desktop.
Check point in triangle
This file contains hidden or 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
var inUV = function (uv, point) { | |
var x = point.x - uv[0].x; | |
var y = point.y - uv[0].y; | |
var s = (uv[1].x - uv[0].x) * y - (uv[1].y - uv[0].y) * x > 0; | |
if ((uv[2].x - uv[0].x) * y - (uv[2].y - uv[0].y) * x > 0 === s) { | |
return false; | |
} | |
return (uv[2].x - uv[1].x) * (point.y - uv[1].y) - (uv[2].y - uv[1].y) * (point.x - uv[1].x) > 0 === s; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment