pixi.js
Version:
<p align="center"> <a href="https://pixijs.com" target="_blank" rel="noopener noreferrer"> <img height="150" src="https://files.pixijs.download/branding/pixijs-logo-transparent-dark.svg?v=1" alt="PixiJS logo"> </a> </p> <br/> <p align="center">
24 lines (21 loc) • 719 B
JavaScript
;
;
function pointInTriangle(px, py, x1, y1, x2, y2, x3, y3) {
const v2x = x3 - x1;
const v2y = y3 - y1;
const v1x = x2 - x1;
const v1y = y2 - y1;
const v0x = px - x1;
const v0y = py - y1;
const dot00 = v2x * v2x + v2y * v2y;
const dot01 = v2x * v1x + v2y * v1y;
const dot02 = v2x * v0x + v2y * v0y;
const dot11 = v1x * v1x + v1y * v1y;
const dot12 = v1x * v0x + v1y * v0y;
const invDenom = 1 / (dot00 * dot11 - dot01 * dot01);
const u = (dot11 * dot02 - dot01 * dot12) * invDenom;
const v = (dot00 * dot12 - dot01 * dot02) * invDenom;
return u >= 0 && v >= 0 && u + v < 1;
}
exports.pointInTriangle = pointInTriangle;
//# sourceMappingURL=pointInTriangle.js.map