Skip to content

Instantly share code, notes, and snippets.

@paulzi
Created August 22, 2016 16:16
Show Gist options
  • Save paulzi/64a87ae17ae6b28487918cfe649603fc to your computer and use it in GitHub Desktop.
Save paulzi/64a87ae17ae6b28487918cfe649603fc to your computer and use it in GitHub Desktop.
Check point in triangle
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